GraphDB 提供了两种不同的基于 Lucene 的插件。
我鼓励您使用 Lucene 连接器,除非您没有 RDF 分子的特殊情况。这是一个简单的示例,如何使用法语分析器配置连接器并索引rdfs:label
类型资源的谓词的所有值urn:MyClass
。选择一个存储库并从 SPARQL 查询视图执行:
PREFIX :<http://www.ontotext.com/connectors/lucene#>
PREFIX inst:<http://www.ontotext.com/connectors/lucene/instance#>
INSERT DATA {
inst:labelFR-copy :createConnector '''
{
"fields": [
{
"indexed": true,
"stored": true,
"analyzed": true,
"multivalued": true,
"fieldName": "label",
"propertyChain": [
"http://www.w3.org/2000/01/rdf-schema#label"
],
"facet": true
}
],
"types": [
"urn:MyClass"
],
"stripMarkup": false,
"analyzer": "org.apache.lucene.analysis.fr.FrenchAnalyzer"
}
''' .
}
然后从 Import > Text 区域手动添加一些示例测试数据:
<urn:instance:test> <http://www.w3.org/2000/01/rdf-schema#label> "C'est une example".
<urn:instance:test> a <urn:MyClass>.
提交事务后,连接器将更新 Lucene 索引。现在您可以运行搜索查询,例如:
PREFIX : <http://www.ontotext.com/connectors/lucene#>
PREFIX inst: <http://www.ontotext.com/connectors/lucene/instance#>
SELECT ?entity ?snippetField ?snippetText {
?search a inst:labelFR ;
:query "label:*" ;
:entities ?entity .
?entity :snippets _:s .
_:s :snippetField ?snippetField ;
:snippetText ?snippetText .
}
要创建自定义分析器,请遵循文档中的说明并扩展org.apache.lucene.analysis.Analyzer
类。将自定义分析器 JAR 放在lib/plugins/lucene-connector/
路径中。