信息检索 - 我如何处理将单个单词分解为多个标记的搜索查询
Information Retrieval - How can i process search query with single word break'ed into multiple tokens
我只是信息检索的初学者
我正在寻求解决用户在键入单词或将两个单词合并为一个时错误地在字符之间添加 space 的问题,由于简单的倒排索引查找,该问题目前无法处理.
假设我对以下文档进行了倒排索引:
- 杰克和吉尔是好朋友。
- 杰克去了阿拉斯加。
- 吉尔住在纽约。
现在拥有倒排索引意味着将 new 和 york 索引为单独的标记(假设仅作为示例并且没有 NLP用于将纽约标记为位置)
token count location
jack 2 1,2
jill 2 1,2
new 1 3
york 1 3
alaska 1 4
现在查询 jack,我会得到位置 1,2,这很好。
但是对于查询 newyork(假设查询没有 space)我怎样才能从 new york位置为 3(合并)的索引。
还有一个查询 ala ska(使用 space)我如何检索令牌 alaska(没有 space in index) 分别.
我遗漏的任何建议或任何特定算法。
我只是信息检索的初学者
感谢您的帮助。
我正在考虑将每个查询标记分解为字符-语法组合,最后合并它们以找出最常见的标记。
例如查询newyork
Find all the tokens of till limit n, starting with n... then ne....then new.... then newy.... etc, similarly like ne.. ew...wy..yo..or..rk...,
which will finally after merging the array will get new and york somewhere..
与查询 ala ska 类似(用 space(s) 打破了这个词)
也许类似的东西对你有用:
使用自定义分析器创建索引(ngram 分词器)
Read about NGram Tokenizer
PUT /index
{
"mappings": {
"doc": {
"properties": {
"token": {
"type": "text",
"analyzer": "myanalyzer"
},
"location":{
"type": "text"
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"myanalyzer": {
"tokenizer": "my_tokenizer",
"filter": []
}
},
"tokenizer": {
"my_tokenizer": {
"token_chars": [
"letter",
"digit",
"symbol",
"punctuation"
],
"min_gram": "3",
"type": "ngram",
"max_gram": "4"
}
}
}
}
}
让我们POST新建文档
POST index/doc
{
"token": "alaska",
"location":[4]
}
POST index/doc
{
"token": "york",
"location":[3]
}
POST index/doc
{
"token": "new",
"location":[3]
}
POST index/doc
{
"token": "jack",
"location":[1,2]
}
POST index/doc
{
"token": "jill",
"location":[1,2]
}
搜索:
GET index/_search
{
"query": {
"match": {
"token": "ala ska"
}
}
}
结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.9346048,
"hits": [
{
"_index": "index",
"_type": "doc",
"_id": "z7hBMG4BXy8wPzqAcq-C",
"_score": 1.9346048,
"_source": {
"token": "alaska",
"location": [
4
]
}
}
]
}
}
我只是信息检索的初学者
我正在寻求解决用户在键入单词或将两个单词合并为一个时错误地在字符之间添加 space 的问题,由于简单的倒排索引查找,该问题目前无法处理.
假设我对以下文档进行了倒排索引:
- 杰克和吉尔是好朋友。
- 杰克去了阿拉斯加。
- 吉尔住在纽约。
现在拥有倒排索引意味着将 new 和 york 索引为单独的标记(假设仅作为示例并且没有 NLP用于将纽约标记为位置)
token count location
jack 2 1,2
jill 2 1,2
new 1 3
york 1 3
alaska 1 4
现在查询 jack,我会得到位置 1,2,这很好。
但是对于查询 newyork(假设查询没有 space)我怎样才能从 new york位置为 3(合并)的索引。
还有一个查询 ala ska(使用 space)我如何检索令牌 alaska(没有 space in index) 分别.
我遗漏的任何建议或任何特定算法。
我只是信息检索的初学者
感谢您的帮助。
我正在考虑将每个查询标记分解为字符-语法组合,最后合并它们以找出最常见的标记。
例如查询newyork
Find all the tokens of till limit n, starting with n... then ne....then new.... then newy.... etc, similarly like ne.. ew...wy..yo..or..rk...,
which will finally after merging the array will get new and york somewhere..
与查询 ala ska 类似(用 space(s) 打破了这个词)
也许类似的东西对你有用:
使用自定义分析器创建索引(ngram 分词器) Read about NGram Tokenizer
PUT /index
{
"mappings": {
"doc": {
"properties": {
"token": {
"type": "text",
"analyzer": "myanalyzer"
},
"location":{
"type": "text"
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"myanalyzer": {
"tokenizer": "my_tokenizer",
"filter": []
}
},
"tokenizer": {
"my_tokenizer": {
"token_chars": [
"letter",
"digit",
"symbol",
"punctuation"
],
"min_gram": "3",
"type": "ngram",
"max_gram": "4"
}
}
}
}
}
让我们POST新建文档
POST index/doc
{
"token": "alaska",
"location":[4]
}
POST index/doc
{
"token": "york",
"location":[3]
}
POST index/doc
{
"token": "new",
"location":[3]
}
POST index/doc
{
"token": "jack",
"location":[1,2]
}
POST index/doc
{
"token": "jill",
"location":[1,2]
}
搜索:
GET index/_search
{
"query": {
"match": {
"token": "ala ska"
}
}
}
结果:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.9346048,
"hits": [
{
"_index": "index",
"_type": "doc",
"_id": "z7hBMG4BXy8wPzqAcq-C",
"_score": 1.9346048,
"_source": {
"token": "alaska",
"location": [
4
]
}
}
]
}
}