Permalink
Browse files

first import

  • Loading branch information...
0 parents commit c78722622933ba6f3257cf6e8ca8a49c296450a5 @mkristian mkristian committed Aug 16, 2011
Showing with 20,473 additions and 0 deletions.
  1. +84 −0 browse/pom.xml
  2. +305 −0 browse/src/main/java/org/tipitaka/search/DirectoryStructure.java
  3. +159 −0 browse/src/main/java/org/tipitaka/search/HtmlBuilder.java
  4. +21 −0 browse/src/main/java/org/tipitaka/search/HtmlBuilderFactory.java
  5. +35 −0 browse/src/main/java/org/tipitaka/search/ResourceLocator.java
  6. +19 −0 browse/src/main/java/org/tipitaka/search/RomanScriptHelper.java
  7. +37 −0 browse/src/main/java/org/tipitaka/search/Script.java
  8. +50 −0 browse/src/main/java/org/tipitaka/search/ScriptFactory.java
  9. +110 −0 browse/src/main/java/org/tipitaka/search/TipitakaOrgTocVisitor.java
  10. +109 −0 browse/src/main/java/org/tipitaka/search/TipitakaOrgVisitor.java
  11. +47 −0 browse/src/main/java/org/tipitaka/search/TipitakaOrgVisitorHtml.java
  12. +45 −0 browse/src/main/java/org/tipitaka/search/TipitakaPath.java
  13. +17 −0 browse/src/main/java/org/tipitaka/search/TipitakaUrlFactory.java
  14. +131 −0 browse/src/main/java/org/tipitaka/search/servlet/TipitakaServlet.java
  15. +61 −0 browse/src/main/java/org/tipitaka/search/solr/TextXmlDoc.java
  16. +54 −0 browse/src/main/java/org/tipitaka/search/solr/TextXmlDocFactory.java
  17. +33 −0 browse/src/main/java/org/tipitaka/search/solr/TipitakaQueryParser.java
  18. +72 −0 browse/src/main/java/org/tipitaka/search/solr/TipitakaSolrIndexer.java
  19. +32 −0 browse/src/main/webapp/WEB-INF/web-overlay.xml
  20. +172 −0 browse/src/main/webapp/WEB-INF/web.xml
  21. +5 −0 browse/src/main/webapp/index.jsp
  22. +28 −0 browse/src/main/webapp/main.css
  23. +54 −0 solr/README.txt
  24. +31 −0 solr/conf/admin-extra.html
  25. +36 −0 solr/conf/elevate.xml
  26. +3,813 −0 solr/conf/mapping-FoldToASCII.txt
  27. +246 −0 solr/conf/mapping-ISOLatin1Accent.txt
  28. +21 −0 solr/conf/protwords.txt
  29. +628 −0 solr/conf/schema.xml
  30. +24 −0 solr/conf/scripts.conf
  31. +1,550 −0 solr/conf/solrconfig-OLD.xml
  32. +1,550 −0 solr/conf/solrconfig.xml
  33. +2 −0 solr/conf/spellings.txt
  34. +58 −0 solr/conf/stopwords.txt
  35. +29 −0 solr/conf/synonyms.txt
  36. +273 −0 solr/conf/velocity-OLD/VM_global_library.vm
  37. +57 −0 solr/conf/velocity-OLD/VM_tipitaka_library.vm
  38. +47 −0 solr/conf/velocity-OLD/browse.vm
  39. +26 −0 solr/conf/velocity-OLD/cluster.vm
  40. +29 −0 solr/conf/velocity-OLD/clusterResults.vm
  41. +47 −0 solr/conf/velocity-OLD/desktop.vm
  42. +43 −0 solr/conf/velocity-OLD/doc.vm
  43. +43 −0 solr/conf/velocity-OLD/doc_desktop.vm
  44. 0 solr/conf/velocity-OLD/facet_dates.vm
  45. +20 −0 solr/conf/velocity-OLD/facet_fields.vm
  46. +12 −0 solr/conf/velocity-OLD/facet_fields.vm.oirg
  47. +3 −0 solr/conf/velocity-OLD/facet_queries.vm
  48. +30 −0 solr/conf/velocity-OLD/facet_ranges.vm
  49. +7 −0 solr/conf/velocity-OLD/facets.vm
  50. +5 −0 solr/conf/velocity-OLD/hit.vm
  51. +5 −0 solr/conf/velocity-OLD/hit_desktop.vm
  52. +48 −0 solr/conf/velocity-OLD/jquery.autocomplete.css
  53. +762 −0 solr/conf/velocity-OLD/jquery.autocomplete.js
  54. +77 −0 solr/conf/velocity-OLD/layout-desktop.vm
  55. +81 −0 solr/conf/velocity-OLD/layout.vm
  56. +196 −0 solr/conf/velocity-OLD/main.css
  57. +197 −0 solr/conf/velocity-OLD/main_desktop.css
  58. +73 −0 solr/conf/velocity-OLD/query-desktop.vm
  59. +66 −0 solr/conf/velocity-OLD/query.vm
  60. +40 −0 solr/conf/velocity-OLD/querySpatial.vm
  61. +3 −0 solr/conf/velocity-OLD/suggest.vm
  62. +22 −0 solr/conf/velocity-OLD/tabs.vm
  63. +9 −0 solr/conf/velocity-OLD/tipitaka-desktop.vm
  64. +9 −0 solr/conf/velocity-OLD/tipitaka.vm
  65. +141 −0 solr/conf/velocity/VM_global_library.vm
  66. +43 −0 solr/conf/velocity/doc-ios.vm
  67. +43 −0 solr/conf/velocity/doc-web.vm
  68. +5 −0 solr/conf/velocity/hit-ios.vm
  69. +5 −0 solr/conf/velocity/hit-web.vm
  70. +5 −0 solr/conf/velocity/hit_desktop.vm
  71. +48 −0 solr/conf/velocity/jquery.autocomplete.css
  72. +762 −0 solr/conf/velocity/jquery.autocomplete.js
  73. +81 −0 solr/conf/velocity/layout-ios.vm
  74. +77 −0 solr/conf/velocity/layout-web.vm
  75. +196 −0 solr/conf/velocity/main-ios.css
  76. +197 −0 solr/conf/velocity/main-web.css
  77. +66 −0 solr/conf/velocity/query-ios.vm
  78. +73 −0 solr/conf/velocity/query-web.vm
  79. +47 −0 solr/conf/velocity/template-ios.vm
  80. +47 −0 solr/conf/velocity/template-web.vm
  81. +9 −0 solr/conf/velocity/tipitaka-ios.vm
  82. +9 −0 solr/conf/velocity/tipitaka-web.vm
  83. +132 −0 solr/conf/xslt/example.xsl
  84. +67 −0 solr/conf/xslt/example_atom.xsl
  85. +66 −0 solr/conf/xslt/example_rss.xsl
  86. +337 −0 solr/conf/xslt/luke.xsl
  87. +34 −0 solr/solr.xml
  88. +1,770 −0 solr/tipitaka/devanagari.script
  89. +1,770 −0 solr/tipitaka/roman.script
  90. +2,545 −0 solr/tipitaka/romn.map
@@ -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>
@@ -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.

0 comments on commit c787226

Please sign in to comment.