首页 文章

在 GraphDB 的 Lucene 连接器中使用 wild-cards

提问于
浏览
0

我正在使用 GraphDB 的Lucene 连接器。我在我的三元组商店中为实体代码构建索引my_index,我想使用这样的索引进行子字符串匹配。

例.

实体代码:

FooBar
FooBaz
BazFoo

Lucene 连接器:

PREFIX :<http://www.ontotext.com/connectors/lucene#>
PREFIX inst:<http://www.ontotext.com/connectors/lucene/instance#>
INSERT DATA {
    inst:my_index :createConnector '''
{
  "fields": [
    {
      "fieldName": "code",
      "propertyChain": [
        "http://foo#identifier"
      ],
      "indexed": true,
      "stored": true,
      "analyzed": true,
      "multivalued": true,
      "facet": true
    }
  ],
  "types": [
    http://foo#MyType"
  ],
  "stripMarkup": false
}
''' .
}

SPARQL查询利用 Lucene 连接器:

PREFIX : <http://www.ontotext.com/connectors/lucene#>
PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>

SELECT ?entity {
  ?search a inst:my_index ;
      :query "code:Foo*" ;
      :entities ?entity .
}

我想让所有实体的代码都以Foo(i.e.,FooBarFooBaz)开头,但我得到一个空的结果集。

我怎么能得到它们?

编辑:

在 Vassil 的回答中尝试了这个例子后,我发现问题可能与区分大小有关。

行为:

  • :query "label:Foo*"什么都不返回

  • :query "label:foo*"返回FooBarFooBaz

1 回答

  • 2

    默认情况下,前缀搜索应该可以使用。我怀疑您的查询还有其他问题。如果使用:query "*:*"搜索所有可能的值,会发生什么?

    以下是检查并使用您的数据集重复它的测试用例。

    生成样本虚拟数据

    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    INSERT DATA
    {
        <urn:1> a <urn:type>;
            rdfs:label "FooBar".
        <urn:2> a <urn:type>;
            rdfs:label "FooBaz".
        <urn:3> a <urn:type>;
            rdfs:label "BazFoo".
    }
    

    您还需要为每个 RDF 资源定义rdf:type语句。

    创建 Lucene 连接器

    PREFIX :<http://www.ontotext.com/connectors/lucene#>
    PREFIX inst:<http://www.ontotext.com/connectors/lucene/instance#>
    INSERT DATA {
        inst:my_index :createConnector '''
    {
      "fields": [
        {
          "fieldName": "label",
          "propertyChain": [
            "http://www.w3.org/2000/01/rdf-schema#label"
          ],
          "indexed": true,
          "stored": true,
          "analyzed": true,
          "multivalued": true,
          "facet": true
        }
      ],
      "types": [
        "urn:type"
      ],
      "stripMarkup": false
    }
    ''' .
    }
    

    连接器将索引所有urn:type类的所有rdfs:label值。

    测试前缀搜索

    PREFIX : <http://www.ontotext.com/connectors/lucene#>
    PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>
    
    SELECT ?entity {
      ?search a inst:my_index ;
          :query "label:Foo*" ;
          :entities ?entity .
    }
    

    数据库返回urn:1urn:2

相关问题