在the instructions之后,我建立了一个涵盖多个(文字)谓词的索引:
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" .
}
和
PREFIX luc: <http://www.ontotext.com/owlim/lucene#>
INSERT DATA {
luc:${Cfg.literalIndex} luc:createIndex "true" .
}
这部分似乎工作正常。现在我的问题是,是否可以通过某种方式在我的SPARQL查询中获取匹配的谓词或文字?
因此,假设以下数据:
:exA rdfs:label 'label' ;
dct:title 'title' .
我想做这样的事情
SELECT *
WHERE {
?needle luc:labelIndex "title" ;
luc:predicate ?predicate ;
?predicate ?label .
}
如果存在类似luc:predicate
的内容,则可以在matchs值旁边给我实际匹配的谓词。但是,我什至不确定Lucene是否为谓词建立索引,而启用该功能将是必需的。
答案 0 :(得分:1)
使用传统的FTS Lucene插件无法有效地做到这一点。但是,Lucene Connectors很容易支持您的用例。这是带有一些模拟数据的示例案例:
样本数据
<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字段中。
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"
]
}
]
}
''' .
}
返回匹配的字段和代码段
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 .
}
投影中的位置: