本文整理汇总了Java中net.semanticmetadata.lire.filter.RerankFilter类的典型用法代码示例。如果您正苦于以下问题:Java RerankFilter类的具体用法?Java RerankFilter怎么用?Java RerankFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RerankFilter类属于net.semanticmetadata.lire.filter包,在下文中一共展示了RerankFilter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRerankFilters
import net.semanticmetadata.lire.filter.RerankFilter; //导入依赖的package包/类
public void testRerankFilters() throws IOException {
int queryDocID = (int) (Math.random() * 10000);
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File("index-large")));
// select one feature for the large index:
int featureIndex = 4;
int count = 0;
long ms = System.currentTimeMillis();
ImageSearchHits hits = searchers[featureIndex].search(reader.document(queryDocID), reader);
RerankFilter rerank = new RerankFilter(featureClasses[0], DocumentBuilder.FIELD_NAME_CEDD);
LsaFilter lsa = new LsaFilter(featureClasses[0], DocumentBuilder.FIELD_NAME_CEDD);
FileUtils.saveImageResultsToPng("GeneralTest_rerank_0_old", hits, reader.document(queryDocID).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]);
hits = rerank.filter(hits, reader.document(queryDocID));
FileUtils.saveImageResultsToPng("GeneralTest_rerank_1_new", hits, reader.document(queryDocID).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]);
hits = lsa.filter(hits, reader.document(queryDocID));
FileUtils.saveImageResultsToPng("GeneralTest_rerank_2_lsa", hits, reader.document(queryDocID).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]);
}
示例2: testSearch
import net.semanticmetadata.lire.filter.RerankFilter; //导入依赖的package包/类
public void testSearch() throws IOException, ParseException {
// create a Lucene IndexReader and the according IndexSearcher:
IndexReader reader = DirectoryReader.open(FSDirectory.open(testIndex));
IndexSearcher searcher = new IndexSearcher(reader);
// The QueryParser takes a String and creates a query out of it. Make sure you use the same field
// as for indexing, in this case "tags"
QueryParser q = new QueryParser(Version.LUCENE_42, "tags", new SimpleAnalyzer(Version.LUCENE_42));
// let's just take the tags of the first document in the index:
Query query = q.parse(reader.document(1).getValues("tags")[0]);
// now that's the actual search:
// NOTE: The number of results here is critical. The less documents are returned here, the
// less the image re-ranking can mess up. However, the recall (the absolute number of relevant
// documents returned) is also influenced by this. Best to try several values like 10, 100, 200, 500, ...
TopDocs results = searcher.search(query, 10);
// here we print the results of the text search, just for the win.
System.out.println("-----------> SEARCH RESULTS ...");
for (int i = 0; i < results.scoreDocs.length; i++) {
ScoreDoc scoreDoc = results.scoreDocs[i];
System.out.print(scoreDoc.score + "\t: ");
// reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] gets you the actual image file path.
// LIRE manages all needed filed names as static Strings in DocumentBuilder ...
System.out.print(reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + " -> ");
System.out.println(reader.document(scoreDoc.doc).getValues("tags")[0]);
}
// just for a visual example ... this will pop up a browser window
FileUtils.browseUri(FileUtils.saveImageResultsToHtml("text", results, reader, reader.document(1).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]));
// and now for the re-ranking:
// make sure to use a low level feature that has been indexed -- check the DocumentBuilder in above method.
RerankFilter rerank = new RerankFilter(FCTH.class, DocumentBuilder.FIELD_NAME_FCTH);
// note that you need the document here, it contains the low level feature ...
// if you don't have it but just the image you need to create a new one with the
// appropriate DocumentBuilder -- check the DocumentBuilder in above method.
ImageSearchHits hitsReranked = rerank.filter(results, reader, reader.document(1));
// and here we print the re-ranked hits:
System.out.println("-----------> RERANKED ...");
for (int i = 0; i < hitsReranked.length(); i++) {
System.out.print(hitsReranked.score(i) + "\t: ");
System.out.print(hitsReranked.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0] + " -> ");
System.out.println(hitsReranked.doc(i).getValues("tags")[0]);
}
// just for a visual example ... this will pop up a browser window.
FileUtils.browseUri(FileUtils.saveImageResultsToHtml("reranked", hitsReranked, reader.document(1).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]));
}