lucene - 在 GraphDB 的 Lucene 连接器中使用通配符
问题描述
我正在使用 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
(ie, FooBar
, FooBaz
) 开头的所有实体,但我得到的是一个空的结果集。
我怎样才能得到它们?
编辑:
在尝试了 Vassil答案中的示例后,我发现问题可能与区分大小写有关。
行为:
:query "label:Foo*"
什么都不返回:query "label:foo*"
返回FooBar
和FooBaz
解决方案
默认情况下,前缀搜索应该可以开箱即用。我怀疑您的查询还有另一个问题。如果你用 搜索所有可能的值会发生什么: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:type
为每个 RDF 资源定义语句。
创建 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
}
''' .
}
连接器将索引所有类的所有rdfs:label
值urn:type
。
测试前缀搜索
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:1
和urn:2
推荐阅读
- javascript - 平滑的进度条
- c++ - 在C ++中递归搜索char数组子字符串中第一次出现的char数组子字符串
- firebase - Firebase OTP 或 Twilio OTP 在交付方面是否更可靠?
- laravel - Laravel Cors 推荐人政策
- python - 有没有更优雅的解决方案来修改这些文件名?
- sql - 同一命令中的 DISTINCT 和 ORDER BY 不使用 order by 变量
- php - 未定义变量:returnValue
- python - 我在 Pygame 中遇到了精灵的问题。我希望他们改变它们,让它看起来像一个动画,我真的不知道该怎么做
- javascript - $gte & $lte 在 Mongoose/MongoDB 中没有按预期工作
- powershell - SharePoint 并提取网站上的所有 URL