mirror of https://github.com/apache/lucene.git
add synonym lookup utility
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bd07d7acc4
commit
79313c8f43
|
@ -0,0 +1,45 @@
|
|||
package org.apache.lucene.wordnet;
|
||||
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.Hits;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.document.Document;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SynLookup {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 2) {
|
||||
System.out.println(
|
||||
"java org.apache.lucene.wordnet.SynLookup <index path> <word>");
|
||||
}
|
||||
|
||||
FSDirectory directory = FSDirectory.getDirectory(args[0], false);
|
||||
IndexSearcher searcher = new IndexSearcher(directory);
|
||||
|
||||
String word = args[1];
|
||||
Hits hits = searcher.search(
|
||||
new TermQuery(new Term("word", word)));
|
||||
|
||||
if (hits.length() == 0) {
|
||||
System.out.println("No synonyms found for " + word);
|
||||
} else {
|
||||
System.out.println("Synonyms found for \"" + word + "\":");
|
||||
}
|
||||
|
||||
for (int i = 0; i < hits.length(); i++) {
|
||||
Document doc = hits.doc(i);
|
||||
|
||||
String[] values = doc.getValues("syn");
|
||||
|
||||
for (int j = 0; j < values.length; j++) {
|
||||
System.out.println(values[j]);
|
||||
}
|
||||
}
|
||||
|
||||
searcher.close();
|
||||
directory.close();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue