连字词拆分器词元过滤器
hyphenation_decompounder
词元过滤器用于将复合词拆分为其组成部分。此过滤器对于德语、荷兰语和瑞典语等复合词常见的语言特别有用。该过滤器使用连字符模式(通常在 .xml 文件中定义)来识别复合词中可以拆分为组件的可能位置。然后,将这些组件与提供的字典进行对照检查。如果存在匹配项,则这些组件将被视为有效的词元。有关连字符模式文件的更多信息,请参阅 FOP XML Hyphenation Patterns。
参数
hyphenation_decompounder
词元过滤器可以通过以下参数进行配置。
参数 | 必需/可选 | 数据类型 | 描述 |
---|---|---|---|
hyphenation_patterns_path | 必需 | 字符串 | 连字符模式文件的路径(相对于 config 目录或绝对路径),该文件包含特定于语言的单词拆分规则。该文件通常为 XML 格式。示例文件可以从 OFFO SourceForge 项目下载。 |
word_list | 如果未设置 word_list_path ,则为必填项 | 字符串数组 | 用于验证连字符模式生成的组件的词汇列表。 |
word_list_path | 如果未设置 word_list ,则为必填项 | 字符串 | 包含子词列表的路径(相对于 config 目录或绝对路径)。 |
max_subword_size | 可选 | 整数 | 最大子词长度。如果生成的子词超过此长度,则不会添加到生成的词元中。默认值为 15 。 |
min_subword_size | 可选 | 整数 | 最小子词长度。如果生成的子词短于指定长度,则不会添加到生成的词元中。默认值为 2 。 |
min_word_size | 可选 | 整数 | 最小词字符长度。短于此长度的词元将不参与拆分为子词。默认值为 5 。 |
only_longest_match | 可选 | 布尔型 | 仅在生成的词元中包含最长的子词。默认值为 false 。 |
示例
以下示例请求创建一个名为 test_index
的新索引,并使用 hyphenation_decompounder
过滤器配置一个分析器。
PUT /test_index
{
"settings": {
"analysis": {
"filter": {
"my_hyphenation_decompounder": {
"type": "hyphenation_decompounder",
"hyphenation_patterns_path": "analysis/hyphenation_patterns.xml",
"word_list": ["notebook", "note", "book"],
"min_subword_size": 3,
"min_word_size": 5,
"only_longest_match": false
}
},
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"my_hyphenation_decompounder"
]
}
}
}
}
}
生成的词元
使用以下请求检查使用该分析器生成的词元
POST /test_index/_analyze
{
"analyzer": "my_analyzer",
"text": "notebook"
}
响应包含生成的词元
{
"tokens": [
{
"token": "notebook",
"start_offset": 0,
"end_offset": 8,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "note",
"start_offset": 0,
"end_offset": 8,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "book",
"start_offset": 0,
"end_offset": 8,
"type": "<ALPHANUM>",
"position": 0
}
]
}