代码之家  ›  专栏  ›  技术社区  ›  Sirko

graphdb+lucene索引:我可以得到匹配的谓词/文本吗?

  •  1
  • Sirko  · 技术社区  · 6 年前

    跟随 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 如果存在,这可以给我匹配值旁边的实际匹配谓词。但是,我甚至不确定Lucene是否对谓词进行了索引,这对于启用这样的函数来说是必需的。

    1 回复  |  直到 6 年前
        1
  •  1
  •   vassil_momtchev    6 年前

    使用传统的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 .
    }
    

    在投影图中:

    • ?实体是属性或属性链匹配的RDF资源,即
    • ?snippetfield是与全文查询匹配的字段名
    • ?snippettext是匹配的snippet值