java - 在哪里可以找到要导入和使用的类 "org.terrier.realtime.memory.MemoryIndex"?

标签 java search information-retrieval

我正在关注Quickstart Guide: Integrating Search into your Application available梗类信息检索平台网站:Terrier IR platform homepage ,使用以下代码,可在其网页上找到。代码使用org.terrier.realtime.memory.MemoryIndex但它在 terrier jar files 中不可用,我已使用 maven 将其包含在我的项目中。

我已经检查了 Terrier 5.15.0但无法找到MemoryIndex class及其构造函数。

import java.io.File;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;

import org.terrier.indexing.Document;
import org.terrier.indexing.TaggedDocument;
import org.terrier.indexing.tokenisation.Tokeniser;
import org.terrier.querying.LocalManager;
import org.terrier.querying.Manager;
import org.terrier.querying.ManagerFactory;
import org.terrier.querying.ScoredDoc;
import org.terrier.querying.ScoredDocList;
import org.terrier.querying.SearchRequest;
import org.terrier.realtime.memory.MemoryIndex;
import org.terrier.utility.ApplicationSetup;
import org.terrier.utility.Files;


public class IndexingAndRetrievalExample {

public static void main(String[] args) throws Exception {

    // Directory containing files to index
        String aDirectoryToIndex = "/my/directory/containing/files/";

    // Configure Terrier
            ApplicationSetup.setProperty("indexer.meta.forward.keys", "docno");
    ApplicationSetup.setProperty("indexer.meta.forward.keylens", "30");

    // Create a new Index
            MemoryIndex memIndex = new MemoryIndex();

    // For each file
            for (String filename : new File(aDirectoryToIndex).list() ) {

                    String fullPath = aDirectoryToIndex+filename;

        // Convert it to a Terrier Document
                    Document document = new TaggedDocument(Files.openFileReader(fullPath), new HashMap(), Tokeniser.getTokeniser());

        // Add a meaningful identifier
                    document.getAllProperties().put("docno", filename);

                    // index it
                    memIndex.indexDocument(document);
            }

            // Set up the querying process
            ApplicationSetup.setProperty("querying.processes", "terrierql:TerrierQLParser,"
            + "parsecontrols:TerrierQLToControls,"
            + "parseql:TerrierQLToMatchingQueryTerms,"
            + "matchopql:MatchingOpQLParser,"
            + "applypipeline:ApplyTermPipeline,"
            + "localmatching:LocalManager$ApplyLocalMatching,"
            + "filters:LocalManager$PostFilterProcess");

            // Enable the decorate enhancement
            ApplicationSetup.setProperty("querying.postfilters", "org.terrier.querying.SimpleDecorate");

            // Create a new manager run queries
            Manager queryingManager = ManagerFactory.from(memIndex.getIndexRef());

            // Create a search request
            SearchRequest srq = queryingManager.newSearchRequestFromQuery("search for document");

            // Specify the model to use when searching
            srq.setControl(SearchRequest.CONTROL_WMODEL, "BM25");

            // Enable querying processes
            srq.setControl("terrierql", "on");
            srq.setControl("parsecontrols", "on");
            srq.setControl("parseql", "on");
            srq.setControl("applypipeline", "on");
            srq.setControl("localmatching", "on");
            srq.setControl("filters", "on");

            // Enable post filters
            srq.setControl("decorate", "on");

            // Run the search
            queryingManager.runSearchRequest(srq);

            // Get the result set
            ScoredDocList results = srq.getResults();

            // Print the results
            System.out.println("The top "+results.size()+" of documents were returned");
            System.out.println("Document Ranking");
            for(ScoredDoc doc : results) {
                int docid = doc.getDocid();
                double score = doc.getScore();
                String docno = doc.getMetadata("docno")
                System.out.println("   Rank "+i+": "+docid+" "+docno+" "+score);
            }
    }
}

最佳答案

我发现了问题。问题在于设置 Maven 依赖项。这里是如何通过在构建maven项目时添加以下依赖项来解决该问题:

<dependencies>
<dependency>
    <groupId>org.terrier</groupId>
    <artifactId>terrier-core</artifactId>
    <version>5.1</version>
</dependency>
<dependency>
    <groupId>org.terrier</groupId>
    <artifactId>terrier-realtime</artifactId>
    <version>5.1</version>
</dependency>
</dependencies>

关于java - 在哪里可以找到要导入和使用的类 "org.terrier.realtime.memory.MemoryIndex"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55900829/

相关文章:

java - WebLogic:URL 映射不起作用

java - 测试中未找到 gradle、activiti 和类

java - 如何为两个类创建共享 ID 空间?

java - 是否可以挂起子线程然后回调父线程,然后再次恢复子线程

search - Indexwriter 类中的 Forcemerge 函数

android - 搜索小部件在发布 apk 中不起作用

php - 如何向 PHP/SQL 搜索脚本添加拼写建议

java - 比较文档 - 文档相似度

java - 使用记录器在lucene中计算精度和召回率

string - Trie 插入或读取操作中的逻辑问题