• R/O
  • SSH
  • HTTPS

nls: 提交


Commit MetaInfo

修订版7 (tree)
时间2011-03-30 18:10:30
作者linuxchecker

Log Message

introducing JUnit

更改概述

差异

--- test/searcherTest.java (nonexistent)
+++ test/searcherTest.java (revision 7)
@@ -0,0 +1,13 @@
1+import org.mathsci.distance.NldSearcher;
2+
3+import org.junit.Test;
4+
5+class NldSearcherTest
6+{
7+
8+ @Test public void test1()
9+ {
10+ NldSearcher s = new NldSearcher();
11+ }
12+
13+}
\ No newline at end of file
--- test/Makefile (nonexistent)
+++ test/Makefile (revision 7)
@@ -0,0 +1,4 @@
1+SRCDIR = test
2+OPTIONS = -Xlint:deprecation -cp $(DEST):$(LIBS):$(CONF):../dest/nld.jar:../lib/junit-4.9b2.jar -encoding UTF-8
3+all: searcherTest.java
4+ javac $(OPTIONS) searcherTest.java
Added: svn:mergeinfo
## -0,0 +0,0 ##
--- src/org/mathsci/distance/NldSearcher.java (revision 6)
+++ src/org/mathsci/distance/NldSearcher.java (revision 7)
@@ -8,6 +8,7 @@
88 import java.io.IOException;
99 import java.util.Date;
1010 import java.util.List;
11+import java.util.Properties;
1112
1213 import java.io.FileReader;
1314 import java.io.StringReader;
@@ -35,10 +36,54 @@
3536 import org.apache.lucene.search.TopScoreDocCollector;
3637
3738 public class NldSearcher {
39+
40+ static final Properties properties = new Properties();
41+ static File INDEX_DIR;
3842
39- public NldSearcher() {}
43+ public NldSearcher()
44+ {
45+ try
46+ {
47+ InputStreamReader inFile = new InputStreamReader(NldSearcher.class.getClassLoader().getResourceAsStream("nld.properties"));
48+ properties.load(inFile);
49+ INDEX_DIR = new File(properties.getProperty("lucene.index.path"));
50+ }catch(IOException e)
51+ {
52+ e.printStackTrace();
53+ }
54+System.out.println("index="+properties.getProperty("lucene.index.path"));
55+ }
56+ public void searcher(String arg) throws Exception {
57+ NldSearcher search = new NldSearcher();
4058
41- static final File INDEX_DIR = new File("index");
59+ String index = "index";
60+ String field = "contents";
61+ String queries = arg;
62+ boolean paging = true;
63+
64+System.out.println("くえりーqueries="+queries);
65+ IndexReader reader = IndexReader.open(FSDirectory.open(new File(index)), true);
66+System.out.println("reader="+reader);
67+ Searcher searcher = new IndexSearcher(reader);
68+System.out.println("searcher="+searcher);
69+// Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
70+ Analyzer analyzer = new IpadicAnalyzer(new Tagger("/home/tetsato/ipadic"));
71+System.out.println("analyzer="+analyzer);
72+ BufferedReader in = null;
73+ if (queries != null) {
74+ in = new BufferedReader(new StringReader(queries));
75+ }
76+System.out.println("in="+in);
77+ QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
78+ String line = in.readLine();
79+ line = line.trim();
80+System.out.println("line="+line);
81+ Query query = parser.parse(line);
82+ System.out.println("Searching for: " + query.toString(field));
83+ doStreamingSearch(searcher, query);
84+ reader.close();
85+ }
86+
4287
4388 static void searcher(String[] args) throws Exception {
4489 String usage =
--- src/Makefile (revision 6)
+++ src/Makefile (revision 7)
@@ -1,9 +1,9 @@
11 SRCDIR = org/mathsci/distance
2-OPTIONS = -Xlint:deprecation -cp $(DEST):$(LIBS) -encoding UTF-8
2+OPTIONS = -Xlint:deprecation -cp $(DEST):$(LIBS):$(CONF) -encoding UTF-8
33 all: $(SRCDIR)/NldIndexer.java $(SRCDIR)/NldSearcher.java $(SRCDIR)/NldCommand.java
44 javac $(OPTIONS) org/mathsci/distance/NldIndexer.java
55 javac $(OPTIONS) org/mathsci/distance/NldSearcher.java
66 javac $(OPTIONS) org/mathsci/distance/NldCommand.java
7- mkdir $(DEST)
7+ test -e $(DEST) || mkdir $(DEST)
88 jar cvf $(DEST)/nld.jar $(SRCDIR)/*.class
99
--- bin/wikipedia_parse.rb (revision 6)
+++ bin/wikipedia_parse.rb (revision 7)
@@ -29,7 +29,7 @@
2929 text_node = xml_object.xpath('//car:text', 'car' => MEDIAWIKI);
3030 text_contents = text_node.children[0];
3131 fp = File.open("#{MEDIA_DIR}/#{id}.txt","w");
32- fp.puts(text_contents.to_xml(:encoding => 'UTF-8'));
32+ fp.puts(text_contents.to_xml(:encoding => 'UTF-8')) if text_contents;
3333 fp.close();
3434 return(true);
3535 end;
@@ -36,4 +36,4 @@
3636 end;
3737
3838 a = Wikipedia_parse.new(ARGV[0]);
39-a.indexer(10000);
39+a.indexer(1000000);
--- README.txt (revision 6)
+++ README.txt (revision 7)
@@ -61,3 +61,7 @@
6161 うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ,,
6262 EOS
6363
64+ * OPTIONAL
65+ + jUnit
66+ $ wget --no-check-certificate https://github.com/downloads/KentBeck/junit/junit-4.9b2.jar
67+ $ mv -v junit-4.9b2.jar nls/lib/
--- Makefile (revision 6)
+++ Makefile (revision 7)
@@ -3,13 +3,16 @@
33 DEST = dest
44 LUCENE_HOME =../lib/lucene-core-3.0.3.jar
55 IGO = ../lib/igo-analyzer-0.0.1.jar:../lib/igo-0.4.2.jar
6-DEFINES = DEST=../$(DEST) LIBS=.:$(LUCENE_HOME):$(IGO)
6+DEFINES = DEST=../$(DEST) LIBS=.:$(LUCENE_HOME):$(IGO) CONF=conf
77 all:
88 cd src && env $(DEFINES) $(MAKE)
99
1010 install:
11- cp -v $(DEST)/*.jar bin/
11+ cp -v $(DEST)/*.jar bin/
1212
13+test::
14+ cd test && env $(DEFINES) $(MAKE)
15+
1316 clean:
1417 rm -fR $(DEST) bin/*.jar # bin/index
1518
Show on old repository browser