我们正在开发一款检测剽窃的应用程序。我们使用 Apache lucene 进行文档索引。我需要使用我们创建的索引为每个文档创建一个出现 vector 。我想知道是否有办法使用 apache lucene 来做到这一点。我尝试使用 TermFreqVectors 但找不到合适的方法。非常感谢任何建议或帮助。
谢谢。
最佳答案
我认为,TermFreqVector
类可以满足您的需求。它甚至可以为您提供术语位置,以便您可以检测有序的单词序列。要生成 vector ,您需要在索引时指定它,如下所示:
String text = "text you want to index; you could also use a Reader here";
Document doc = new Document();
doc.add(new Field("text", text, Store.NO, Index.ANALYZED, TermVector.WITH_POSITIONS));
在检索时,您可以运行短语查询(例如,“a b c”~25)或 SpanQuery
(您必须以编程方式构建)。
要从索引中获取术语频率和位置信息,请执行以下操作:
TermPositionVector v = (TermPositionVector) this.reader.getTermFreqVector(docnum, this.textField);
int wordIndex = v.indexOf("want");
int[] positions = v.getTermPositions(wordIndex); // should return the position(s) of the word "want" in your text
关于java - 使用 Apache Lucene 创建出现 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6054488/