以下是代码:
public int docLength(String filename) throws IOException {
int length = 0;
TermFreqVector t = indexReader.getTermFreqVector(0, "contents");
for (int i = 0; i < t.getTermFrequencies().length; i++) {
length += t.getTermFrequencies()[i];
}
return length;
}
public int docLength(int id) throws IOException {
int length = 0;
TermFreqVector t = indexReader.getTermFreqVector(id, "contents");
for (int i = 0; i < t.getTermFrequencies().length; i++) {
length += t.getTermFrequencies()[i];
}
return length;
}
错误是:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
TermFreqVector cannot be resolved to a type
The method getTermFreqVector(int, String) is undefined for the type IndexReader
at BM25.docLength(BM25.java:96)
at BM25.avgDocLength(BM25.java:130)
答案 0 :(得分:1)
访问和遍历术语向量在4.0中发生了显着变化。 Migration Guide是一个非常有用的资源,其中包括从3.6到4.0的其他变化。
在这种情况下,您需要通过致电Terms
来访问IndexReader.getTermVector
个实例:
int length = 0;
TermEnum terms = indexReader.getTermVector(id, "contents").iterator();
while (terms.next())
length += terms.totalTermFreq(null);
return length;