我的情况是,在卢塞内使用标准Analyzer,将案文拼写成以下索引:
public void indexText(String suffix, boolean includeStopWords) {
StandardAnalyzer analyzer = null;
if (includeStopWords) {
analyzer = new StandardAnalyzer(Version.LUCENE_30);
}
else {
// Get Stop_Words to exclude them.
Set<String> stopWords = (Set<String>) Stop_Word_Listener.getStopWords();
analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWords);
}
try {
// Index text.
Directory index = new RAMDirectory();
IndexWriter w = new IndexWriter(index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
this.addTextToIndex(w, this.getTextToIndex());
w.close();
// Read index.
IndexReader ir = IndexReader.open(index);
Text_TermVectorMapper ttvm = new Text_TermVectorMapper();
int docId = 0;
ir.getTermFreqVector(docId, PropertiesFile.getProperty(text), ttvm);
// Set output.
this.setWordFrequencies(ttvm.getWordFrequencies());
w.close();
}
catch(Exception ex) {
logger.error("Error message
", ex);
}
}
private void addTextToIndex(IndexWriter w, String value) throws IOException {
Document doc = new Document();
doc.add(new Field(text), value, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
w.addDocument(doc);
}
这些工作做得很好,但我要把这项工作与利用斯沃加纳利泽来遏制。
这一类别还包含以下构造中所示两种变量:
public Text_Indexer(String textToIndex) {
this.textToIndex = textToIndex;
this.wordFrequencies = new HashMap<String, Integer>();
}
谁能告诉我,如何以上述法典实现这一目标?
增 编
Morgan先生