【问题标题】:How to create a custom AnalyzerFactory in GraphDB full text search?如何在 GraphDB 全文搜索中创建自定义 AnalyzerFactory?
【发布时间】:2017-04-20 10:33:32
【问题描述】:

(免费使用 GraphDB 8.1)。 http://graphdb.ontotext.com/documentation/free/full-text-search.html 说我可以通过实现接口com.ontotext.trree.plugin.lucene.AnalyzerFactory 使用luc:analyzer 参数为GraphDB 全文搜索启用自定义AnalyzerFactory。但是我在任何地方都找不到这个接口。它不在 jar graphdb-free-runtime-8.1.0.jar 中。

我检查了http://ontotext.com/products/graphdb/editions/#feature-comparison-table 的功能矩阵,似乎此功能“Connectors Lucene”可用于 GraphDB 的免费版。

com.ontotext.trree.plugin.lucene.AnalyzerFactory 接口位于哪个 jar 中?我需要在我的项目中导入什么来实现这个接口?

GraphDB 中是否包含预先存在的 AnalyzerFactories 以使用 Lucene 其他分析器? (我有兴趣使用 FrenchAnalyzer)。

谢谢!

【问题讨论】:

标签: java lucene sparql graphdb


【解决方案1】:

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/ 路径中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    相关资源
    最近更新 更多