【问题标题】:Using wild-cards in Lucene connector of GraphDB在 GraphDB 的 Lucene 连接器中使用通配符
【发布时间】:2018-06-25 12:00:51
【问题描述】:

我正在使用 GraphDB 的 Lucene connectors。我为我的三重存储中的实体代码构建索引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 开头的所有实体(即FooBarFooBaz),但我得到的是一个空结果集。

我怎样才能得到它们?

编辑:

在尝试了 Vassil 的answer 中的示例后,我发现问题可能与区分大小写有关。

行为:

  • :query "label:Foo*" 不返回任何内容

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

【问题讨论】:

  • 我建议swrlb:startsWith("Foo")
  • 它是否使用某种索引?
  • 不,但比正则表达式更适合字符串匹配。
  • 我明白了。我正在尝试使用 Lucene 进行此类文本搜索。

标签: lucene wildcard graphdb


【解决方案1】:

默认情况下,前缀搜索应该是开箱即用的。我怀疑您的查询还有另一个问题。如果你用: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

【讨论】:

  • 如果我搜索所有可能的值 (:query "*:*") 我得到了所有值。
  • 我刚刚用我的连接器更新了这个问题。好像没问题。我不明白问题出在哪里:/
  • 跟进。刚刚尝试了您的示例,但我发现了同样的问题::query "label:*" 返回所有 3 个项目,:query "label:Foo*" 不返回任何内容。
  • 跟进#2。奇怪的是,:query "label:foo*" 返回urn:1urn:2(分别标记为FooBarFooBaz)。发生了什么事……
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多