首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphDB + Lucene :我能得到匹配的谓词/文字吗?

GraphDB + Lucene :我能得到匹配的谓词/文字吗?
EN

Stack Overflow用户
提问于 2018-11-18 14:44:51
回答 1查看 239关注 0票数 1

指示之后,我设置了一个包含多个(文字-)谓词的索引:

代码语言:javascript
复制
  PREFIX luc: <http://www.ontotext.com/owlim/lucene#>
  INSERT DATA {
    luc:index             luc:setParam "uris" .
    luc:include           luc:setParam "literals" .
    luc:moleculeSize      luc:setParam "1" .
    luc:includePredicates luc:setParam "http://purl.org/dc/terms/title http://www.w3.org/2000/01/rdf-schema#label http://www.w3.org/2004/02/skos/core#prefLabel http://www.w3.org/2004/02/skos/core#altLabel" .
  }

代码语言:javascript
复制
PREFIX luc: <http://www.ontotext.com/owlim/lucene#>
INSERT DATA {
  luc:${Cfg.literalIndex}   luc:createIndex   "true" .
}

这部分似乎运作得很好。我现在的问题是,是否有方法在我的SPARQL查询中获得匹配的谓词或文字?

因此,假设以下数据:

代码语言:javascript
复制
:exA rdfs:label     'label' ;
     dct:title      'title' .

我想做这样的事

代码语言:javascript
复制
SELECT *
WHERE {
  ?needle luc:labelIndex "title" ;
          luc:predicate  ?predicate ;
          ?predicate     ?label .
}

如果存在类似于此luc:predicate的内容,则可以在匹配值旁边提供实际匹配的谓词。但是,我甚至不能确定Lucene索引谓词,这是启用这样一个函数所需要的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-18 15:22:30

你不能用传统的FTS Lucene插件高效地完成这个任务。但是,Lucene连接器很容易支持您的用例。下面是一个带有一些模拟数据的示例:

样本数据

代码语言:javascript
复制
<urn:a> a <http://www.w3.org/2004/02/skos/core#Concept> ;
    <http://purl.org/dc/terms/title> "title"; 
    <http://www.w3.org/2000/01/rdf-schema#label> "label" ; 
    <http://www.w3.org/2004/02/skos/core#prefLabel> "prefer label"; 
    <http://www.w3.org/2004/02/skos/core#altLabel> "alt label" .

注意:连接器对单个rdf:type的数据进行索引。在您的例子中,我认为您应该拥有skos:Concept

创建Lucene连接器

连接器将为所选类型索引每个属性或属性链到单独的Lucene字段中。

代码语言:javascript
复制
PREFIX : <http://www.ontotext.com/connectors/lucene#>
PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>

INSERT DATA {
    inst:fts :createConnector '''
{
  "types": [
    "http://www.w3.org/2004/02/skos/core#Concept"
  ],
  "fields": [
    {
      "fieldName": "label",
      "propertyChain": [
        "http://www.w3.org/2000/01/rdf-schema#label"
      ]
    },
    {
      "fieldName": "prefLabel",
      "propertyChain": [
        "http://www.w3.org/2004/02/skos/core#prefLabel"
      ]
    },
    {
      "fieldName": "altLabel",
      "propertyChain": [
        "http://www.w3.org/2004/02/skos/core#altLabel"
      ]
    }
  ]
}
''' .
}

返回匹配字段和片段

代码语言:javascript
复制
PREFIX : <http://www.ontotext.com/connectors/lucene#>
PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>
SELECT ?entity ?snippetField ?snippetText {
    ?search a inst:fts ;
            :query "label" ;
            :entities ?entity .
    ?entity :snippets _:s .
    _:s :snippetField ?snippetField ;
        :snippetText ?snippetText .
}

在投影中:

  • ?实体是与属性或属性链匹配的RDF资源,即
  • ?代码段字段是匹配全文查询的字段名。
  • ?snippetText是匹配的片段值
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53362090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档