Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c787226
Showing
90 changed files
with
20,473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.tipitaka</groupId> | ||
<artifactId>search</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Tipitaka Search Webapp</name> | ||
<url>http://tipitaka.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>xpp3</groupId> | ||
<artifactId>xpp3</artifactId> | ||
<version>1.1.4c</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.solr</groupId> | ||
<artifactId>solr</artifactId> | ||
<version>3.3.0</version> | ||
<type>war</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.solr</groupId> | ||
<artifactId>solr-core</artifactId> | ||
<version>3.3.0</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<jetty.version>7.4.2.v20110526</jetty.version> | ||
</properties> | ||
<build> | ||
<finalName>tipitaka-search</finalName> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>package</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>jetty-util</artifactId> | ||
<version>6.1H.22</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
<profile> | ||
<id>jetty-run</id> | ||
<activation> | ||
<property> | ||
<name>solr.solr.home</name> | ||
</property> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlets</artifactId> | ||
<version>${jetty.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<jetty.version>7.4.2.v20110526</jetty.version> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.mortbay.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
<version>${jetty.version}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
305 changes: 305 additions & 0 deletions
305
browse/src/main/java/org/tipitaka/search/DirectoryStructure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,305 @@ | ||
/** | ||
* | ||
*/ | ||
package org.tipitaka.search; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.xmlpull.v1.XmlPullParserException; | ||
|
||
public class DirectoryStructure { | ||
|
||
private static final Set<String> EMPTY = Collections.emptySet(); | ||
|
||
public static void main(String... args) throws Exception { | ||
long start = System.currentTimeMillis(); | ||
DirectoryStructure dir = new DirectoryStructure(); | ||
// dir.reload(); | ||
// dir.save(new FileWriter("/home/kristian/romn.map")); | ||
dir.load(new FileReader("/home/kristian/romn.map")); | ||
|
||
for(String s: dir.subdirs("/anya/sihala-gantha-sangaho/samantakutavannana/samantakutavannana")){ | ||
System.err.println(s); | ||
} | ||
System.err.println(dir.fileOf("/anya/sihala-gantha-sangaho/samantakutavannana/samantakutavannana")); | ||
for(String s: dir.subdirs("/anya/sihala-gantha-sangaho/samantakutavannana/")){ | ||
System.err.println(s); | ||
} | ||
|
||
Script roman = new Script("roman", "romn"); | ||
roman = dir.transcribe("romn"); | ||
roman.save(new FileWriter("/home/kristian/roman.script")); | ||
roman.load(new FileReader("/home/kristian/roman.script")); | ||
|
||
Script deva = new Script("devanagari", "deva"); | ||
deva = dir.transcribe("deva"); | ||
deva.save(new FileWriter("/home/kristian/devanagari.script")); | ||
deva.load(new FileReader("/home/kristian/devanagari.script")); | ||
|
||
Script script = deva; | ||
|
||
System.err.println("---------------------------------"); | ||
for(String word : "anya/sihala-gantha-sangaho/samantakutavannana/samantakutavannana".split("/")){ | ||
System.err.println(script.get(word)); | ||
} | ||
System.err.println("---------------------------------"); | ||
Map<String, String> crumbs = dir.breadCrumbs(script, "/anya/sihala-gantha-sangaho/samantakutavannana/samantakutavannana"); | ||
for(Map.Entry<String, String> c: crumbs.entrySet()){ | ||
System.err.println(c.getKey() + " -> " + c.getValue()); | ||
} | ||
System.err.println("---------------------------------"); | ||
Map<String, String> dirs = dir.listDirs(script, "/anya/sihala-gantha-sangaho"); | ||
for(Map.Entry<String, String> c: dirs.entrySet()){ | ||
System.err.println(c.getKey() + " -> " + c.getValue()); | ||
} | ||
System.err.println("---------------------------------"); | ||
Map<String, String> files = dir.listFiles(script, "/anya/sihala-gantha-sangaho/dhatuvamsa/dhatuparamparakatha"); | ||
for(Map.Entry<String, String> c: files.entrySet()){ | ||
System.err.println(c.getKey() + " -> " + c.getValue()); | ||
} | ||
System.err.println("---------------------------------"); | ||
long start2 = System.currentTimeMillis(); | ||
HtmlBuilderFactory factory = new HtmlBuilderFactory(new ScriptFactory(), dir); | ||
|
||
String path = "/" + script.name + "/anya/sihala-gantha-sangaho/dhatuvamsa/dhatuparamparakatha"; | ||
HtmlBuilder builder = factory.newHtmlBuilder(new FileWriter("/home/kristian/deva-test.html"), new TipitakaPath("", path)); | ||
builder.buildHeader(); | ||
builder.buildScriptNavigation(); | ||
builder.buildBreadCrumbs(); | ||
builder.buildViewLink(); | ||
builder.buildSubmenu(); | ||
builder.buildPage(); | ||
builder.buildFooter(); | ||
System.err.println("---------------------------------"); | ||
System.err.println(System.currentTimeMillis() - start); | ||
System.err.println(System.currentTimeMillis() - start2); | ||
factory.newHtmlBuilder(new FileWriter("/home/kristian/deva-test-mini.html"), new TipitakaPath("", path)).buildMinimal(); | ||
} | ||
|
||
public Map<String, String> list(Script words, String path) { | ||
if(map.containsKey(path)){ | ||
return listFiles(words, path); | ||
} | ||
else{ | ||
return listDirs(words, path); | ||
} | ||
} | ||
|
||
public Map<String, String> listDirs(Script words, String path) { | ||
Map<String, String> result = new LinkedHashMap<String, String>(); | ||
if(fileOf(path) == null){ | ||
if(path == null){ | ||
path = "/"; | ||
} | ||
else if(!path.endsWith("/")){ | ||
path = path + "/"; | ||
} | ||
for(String dir: subdirs(path)){ | ||
result.put(path + dir, words.get(dir)); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public Map<String, String> listFiles(Script words, String path) { | ||
Map<String, String> result = new LinkedHashMap<String, String>(); | ||
if(fileOf(path) != null){ | ||
path = path.substring(0, path.lastIndexOf("/") + 1); | ||
for(String dir: subdirs(path)){ | ||
result.put(path + dir, words.get(dir)); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public Map<String, String> breadCrumbs(Script trans, String path) { | ||
Map<String, String> result = new LinkedHashMap<String, String>(); | ||
if(path != null && !"/".equals(path)){ | ||
if (path.endsWith("/")) { | ||
path = path.substring(0, path.length() - 1); | ||
} | ||
int from = 1; | ||
int next = path.indexOf("/", from); | ||
while (next > -1) { | ||
result.put(path.substring(0, next), trans.get(path.substring( | ||
from, next))); | ||
from = next + 1; | ||
next = path.indexOf("/", from); | ||
} | ||
result.put(path, trans.get(path.substring(from))); | ||
} | ||
return result; | ||
} | ||
|
||
private final Node root = new Node(""); | ||
|
||
private final Map<String, String> map = new LinkedHashMap<String, String>(); | ||
private final Map<String, String> rmap = new HashMap<String, String>(); | ||
|
||
void reload() throws XmlPullParserException, IOException{ | ||
TipitakaOrgTocVisitor visitor = new TipitakaOrgTocVisitor(); | ||
visitor.accept("romn"); | ||
|
||
List<String> parts = new ArrayList<String>(6); | ||
for(Map.Entry<String, String[]> entry: visitor.map().entrySet()){ | ||
parts.clear(); | ||
for(String part: entry.getValue()){ | ||
if(part != null){ | ||
parts.add(RomanScriptHelper.removeDiacritcals(part.replaceFirst("[(][0-9]+[)]", "").replaceFirst("[0-9]+\\.\\ ", "") | ||
.replaceFirst("(bhikkhunīvibhaṅgo)", "- bhikkhunīvibhaṅgo")//.replaceFirst("\\ [(].*[)]", "") | ||
.replaceAll("[()]","").replace("’", " ")) | ||
.toLowerCase().trim().replaceAll(" ", "_")); | ||
} | ||
} | ||
String path = root.addLeaf(entry.getKey(), parts); | ||
map.put(path, entry.getKey()); | ||
rmap.put(entry.getKey(), path); | ||
} | ||
|
||
} | ||
|
||
Script transcribe(String script) throws XmlPullParserException, IOException{ | ||
TipitakaOrgTocVisitor visitor = new TipitakaOrgTocVisitor(); | ||
visitor.accept(script); | ||
ScriptFactory factory = new ScriptFactory(); | ||
Script words = factory.newScript(script); | ||
|
||
List<String> parts = new ArrayList<String>(6); | ||
for(Map.Entry<String, String[]> entry: visitor.map().entrySet()){ | ||
parts.clear(); | ||
for(String part: entry.getValue()){ | ||
if(part != null){ | ||
parts.add(part); | ||
} | ||
} | ||
if(rmap.containsKey(entry.getKey())){ | ||
String[] paths = rmap.get(entry.getKey()).substring(1).split("/"); | ||
for(int i = 0; i < paths.length; i++){ | ||
words.put(paths[i], parts.get(i)); | ||
} | ||
} | ||
else { | ||
System.err.println("---" + entry.getKey()); | ||
} | ||
} | ||
return words; | ||
} | ||
|
||
void save(Writer writer) throws IOException{ | ||
for(Map.Entry<String, String> entry: map.entrySet()){ | ||
writer.append(entry.getKey()).append("=").append(entry.getValue()).append("\n"); | ||
} | ||
writer.close(); | ||
} | ||
|
||
public void load(Reader reader) throws IOException{ | ||
map.clear(); | ||
rmap.clear(); | ||
BufferedReader in = null; | ||
try{ | ||
in = new BufferedReader(reader); | ||
String line = in.readLine(); | ||
while(line != null){ | ||
String[] pp = line.split("="); | ||
map.put(pp[0], pp[1]); | ||
rmap.put(pp[1], pp[0]); | ||
root.addLeaf(pp[1], pp[0].substring(1).split("/")); | ||
line = in.readLine(); | ||
} | ||
} | ||
finally { | ||
if( in != null) { | ||
in.close(); | ||
} | ||
} | ||
} | ||
|
||
public String fileOf(String path){ | ||
return map.get(path); | ||
} | ||
|
||
Set<String> subdirs(String path){ | ||
if(path == null || "/".equals(path)){ | ||
return root.children.keySet(); | ||
} | ||
if(map.containsKey(path)){ | ||
return EMPTY; | ||
} | ||
path = path.replaceAll("^/|/$", ""); | ||
System.err.println("--- " + path); | ||
return root.getNode(path.split("/")).children.keySet(); | ||
} | ||
|
||
static class Node { | ||
|
||
Map<String, Node> children; | ||
|
||
String name; | ||
|
||
Node(String name, boolean leaf){ | ||
this.name = name; | ||
this.children = leaf ? null : new LinkedHashMap<String, Node>(); | ||
} | ||
|
||
public void addLeaf(String key, String[] parts) { | ||
addLeaf(key, Arrays.asList(parts)); | ||
} | ||
|
||
public String addLeaf(String key, List<String> parts) { | ||
StringBuilder result = new StringBuilder(); | ||
Node n = this; | ||
for(String part: parts){ | ||
result.append("/").append(part); | ||
Node node = n.get(part); | ||
if( node == null){ | ||
node = n.addNode(part); | ||
} | ||
n = node; | ||
} | ||
n.children = null; | ||
n.name = key; | ||
return result.toString(); | ||
} | ||
|
||
Node(String name){ | ||
this(name, false); | ||
} | ||
|
||
Node addNode(String name){ | ||
Node n = new Node(name); | ||
children.put(name, n); | ||
return n; | ||
} | ||
|
||
Node addLeaf(String leaf, String value){ | ||
Node n = new Node(value); | ||
children.put(leaf, n); | ||
return n; | ||
} | ||
|
||
Node get(String name){ | ||
return children.get(name); | ||
} | ||
|
||
Node getNode(String... parts){ | ||
Node n = this; | ||
for(String part: parts){ | ||
n = n.get(part); | ||
} | ||
return n; | ||
} | ||
} | ||
} |
Oops, something went wrong.