【问题标题】:Apache Jena full-text search (with external content)Apache Jena 全文搜索(带有外部内容)
【发布时间】:2015-11-13 12:10:00
【问题描述】:

我想这样配置:

  1. 书籍元数据的 RDF 数据集;
  2. 单独放置的书籍,如 XHTML 文件、具有唯一 ID 的段落;
  3. 每本书的元数据都包含 dc:source 之类的文件链接(绝对的?像一个适当的 URI,那么缩放呢?);

我知道这可能很微不足道,但我无法正确理解。一开始我试图只索引纯 TXT 小文件,每个链接都来自元数据文件中的 dc:source。据我了解,这应该足以索引所有内容。我正在尝试像this post 中的那个人那样做。与他不同的是,我想索引 RDF 数据集以及外部文件。特别是这两个命令没有错误记录(相反,它记录了 57 个三元组):

java -cp /home/honza/.apache-jena-fuseki-2.3.0/fuseki-server.jar tdb.tdbloader --tdb=run/configuration/service2.ttl testDir/test_dataset.ttl

INFO  -- Start triples data phase
INFO  ** Load into triples table with existing data
INFO  -- Start quads data phase
INFO  ** Load empty quads table
INFO  Load: testDir/test_dataset.ttl -- 2015/11/13 12:46:22 CET
INFO  -- Finish triples data phase
INFO  ** Data: 57 triples loaded in 0,29 seconds [Rate: 193,22 per second]
INFO  -- Finish quads data phase
INFO  -- Start triples index phase
INFO  -- Finish triples index phase
INFO  -- Finish triples load
INFO  ** Completed: 57 triples loaded in 0,33 seconds [Rate: 172,21 per second]
INFO  -- Finish quads load

java -cp /home/honza/.apache-jena-fuseki-2.3.0/fuseki-server.jar jena.textindexer --desc=run/configuration/service2.ttl

WARN  Values stored but langField not set. Returned values will not have language tag or datatype.

之后,服务器正常运行,我看到了图表,但它不包含任何数据。

我对该服务的配置是(我不知道将服务和数据库配置放在一个文件中是否正确,对我来说目前效果更好,分割会引发一些错误):

@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix text:    <http://jena.apache.org/text#> .
@prefix :        <#> .

[] rdf:type fuseki:Server 
.

<#service2> rdf:type fuseki:Service ;
  rdfs:label                        "TDB/text service" ;
  fuseki:name                       "test" ;       # http://host:port/ds
  fuseki:serviceQuery               "sparql" ;   # SPARQL query service
  fuseki:serviceQuery               "query" ;    # SPARQL query service (alt name)
  fuseki:serviceUpdate              "update" ;   # SPARQL update service
  fuseki:serviceUpload              "upload" ;   # Non-SPARQL upload service
  fuseki:serviceReadWriteGraphStore "data" ;     # SPARQL Graph store protocol (read and write)
  # A separate read-only graph store endpoint:
  fuseki:serviceReadGraphStore      "get" ;      # SPARQL Graph store protocol (read only)
  fuseki:dataset                    :text_dataset 
.

[] ja:loadClass   "org.apache.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

[] ja:loadClass "org.apache.jena.query.text.TextQuery" .

text:TextIndexLucene rdfs:subClassOf  text:TextIndex .
:text_dataset rdf:type text:TextDataset ;
  text:dataset <#test> ;
  text:index <#indexLucene> .

【问题讨论】:

    标签: lucene rdf jena full-text-indexing fuseki


    【解决方案1】:

    首先,您实际上并没有明确定义 Lucene 索引,因此您得到的很可能是每次应用程序停止时都会丢弃的临时内存索引。您的配置中至少需要以下内容:

    # Text index description
    <#indexLucene> a text:TextIndexLucene ;
        text:directory <file:path/to/index/> .
    

    &lt;file:path/to/index/&gt; 指向您希望存储文本索引的目录。

    其次,您没有告诉文本搜索 Lucene 索引的结构。即使您已经从外部文件中单独创建了索引,您也需要在配置中定义 Jena 应该如何使用和访问该索引。

    documentation你需要定义一个实体映射:

    # Mapping in the index
    # URI stored in field "uri"
    # rdfs:label is mapped to field "text"
    <#entMap> a text:EntityMap ;
        text:entityField      "uri" ;
        text:defaultField     "text" ;
        text:map (
             [ text:field "text" ; text:predicate rdfs:label ]
             ) .
    

    文档中示例中的 cmets 希望能很好地描述事物。 text:entityField 属性用于指定索引中存储与索引数据关联的 URI 的字段,即这提供了将文本索引命中链接回三重存储中的 RDF 的方法。 text:defaultField 用于指定包含索引数据的字段,即文本搜索将实际搜索的字段。

    此处显示的可选text:map 可用于进一步自定义搜索哪些字段,并允许您索引不同字段中的多条内容,然后编写以不同方式搜索文本索引的查询。

    一旦您有一个适当定义的实体映射,您需要将它链接到您的索引配置,如下所示:

    # Text index description
    <#indexLucene> a text:TextIndexLucene ;
        text:directory <file:path/to/index/> ;
        text:entityMap <#entMap> .
    

    有了这个,您实际上应该能够从索引中获得结果。

    【讨论】:

    • 非常感谢,这很有意义!我会尝试报告。但是,除了元数据集之外,我对文档的索引感到困惑。用相对链接指向它们的方式可以吗?它们可以是 xhtml 还是像另一个单独的 RDF 数据集那样构建书籍更好?我想将它们按页面或段落分块。
    • 有效!我必须确保全文搜索也能正常工作。至于索引外部内容,我开始猜测它需要更多,比如 Solr 左右......
    猜你喜欢
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    相关资源
    最近更新 更多