命令行tdbquery与文本索引

时间:2016-12-20 16:29:47

标签: sparql jena apache-jena tdb

我尝试通过命令行使用Jena运行文本搜索查询。

tdbquery  --desc textsearch.ttl  --query search.rq  

查询返回空结果并显示消息:

17:23:46 WARN  TextQueryPF          :: Failed to find the text index :    tried context and as a text-enabled dataset
17:23:46 WARN  TextQueryPF          :: No text index - no text search performed

我的汇编程序文件是:

    @prefix :        <http://localhost/jena_example/#> .
  @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#> .

  ## Example of a TDB dataset and text index
  ## Initialize TDB
  [] ja:loadClass "org.apache.jena.tdb.TDB" .
  tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
  tdb:GraphTDB    rdfs:subClassOf  ja:Model .

  ## Initialize text query
  [] ja:loadClass       "org.apache.jena.query.text.TextQuery" .
  # A TextDataset is a regular dataset with a text index.
  text:TextDataset      rdfs:subClassOf   ja:RDFDataset .
  # Lucene index
  text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .
  # Solr index
  text:TextIndexSolr    rdfs:subClassOf   text:TextIndex .

  ## ---------------------------------------------------------------
  ## This URI must be fixed - it's used to assemble the text dataset.

  :text_dataset rdf:type     text:TextDataset ;
    text:dataset   <#dataset> ;
    text:index     <#indexLucene> ;
    .

  # A TDB datset used for RDF storage
  <#dataset> rdf:type      tdb:DatasetTDB ;
    tdb:location "DB2" ;
    tdb:unionDefaultGraph true ; # Optional
    .

  # Text index description
  <#indexLucene> a text:TextIndexLucene ;
    text:directory <file:Lucene2> ;
    ##text:directory "mem" ;
    text:entityMap <#entMap> ;
    .

  # 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 ]
         ) .

我的查询是:

  PREFIX text: <http://jena.apache.org/text#>
  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

  SELECT ?s
  { ?s text:query 'London' ; 
       rdfs:label ?label 
  }

我想知道我是否错过了任何配置,或者此查询只能在fuseki内完成。

1 个答案:

答案 0 :(得分:0)

首先,您可以在Fuseki外进行文本搜索。您从代码中获取的示例演示了如何使用Java中的普通Jena数据集执行此操作。

其次,Andy Seaborne on Jena mailing list建议如下:

SELECT (count(*) AS ?C) { ?x text:query .... }

为了触摸&#34;运行真实查询之前的索引。