在我将同义词文件添加到索引后,模糊性停止工作。看来,不可能同时使用它们。我的查询:
"query": {
"dis_max": {
"queries": [{
"multi_match": {
"query": $('#searchterm').val(),
"fields": ["search_1"],
"fuzziness": "AUTO",
"operator": "and",
"max_expansions": 1
}},
{ "match": { "search_2": $('#searchterm').val() }}
]
}
}
Run Code Online (Sandbox Code Playgroud)
映射:
"mappings": {
"objs":{
"properties": {
"o":{
"type": "string"
},
"loc":{
"type":"geo_point"
},
"search_1":{
"type": "string",
"analyzer": "synonym"
},
"search_2":{
"type": "string",
"analyzer": "synonym"
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用波特过滤器工厂来处理包含 3 到 4 个单词的字段。
例如:“ABC BLOSSOM 公司”
我希望在搜索 ABC BLOSSOMING COMPANY 时也能获取上述文档。
当我查询这个时:
name:ABC AND name:BLOSSOMING AND name:COMPANY
Run Code Online (Sandbox Code Playgroud)
我得到我的结果
这就是解析后的查询的样子
+名称:southern +名称:flower +名称:compani (词干分析器效果很好)
但是当我像这样添加模糊语法和查询时,
name:ABC~1 AND name:BLOSSOMING~1 AND name:COMPANY~1
Run Code Online (Sandbox Code Playgroud)
搜索没有给出任何文档作为结果,解析的查询如下所示
+姓名:abc~1 +姓名:朵朵~1 +姓名:公司~2
这清楚地表明阻止没有发生。请审查并提供反馈。
我有一组 40.000 行 x 4 列,我需要将每一列与其自身进行比较,以找到最接近的结果或最小的编辑距离。这个想法是为每一行获得一个“几乎重复的”。我用“adist”计算过,但似乎太慢了。例如,对于仅一列,5.000 行与所有列数据集,40.000 行相比,需要将近 2 小时。对于 4 列,这是 8 小时,对于整个数据集,这是 32 小时。有没有更快的方法来实现相同的目标?如果可能的话,我需要它在 1 或 2 小时内完成。这是我到目前为止所做的一个例子:
#vector example
a<-as.character(c("hello","allo","hola"))
b<-as.character(c("hello","allo","hola"))
#execution time
start_time <- Sys.time()
#Matrix with distance
dist.name<-adist(a,b, partial = TRUE, ignore.case = TRUE)
#time elapsed
end_time <- Sys.time()
end_time - start_time
Output:
Time difference of 5.873202 secs
#result
dist.name
[,1] [,2] [,3]
[1,] 0 4 5
[2,] 2 0 2
[3,] 5 4 0
Run Code Online (Sandbox Code Playgroud)
[1,] 4
[2,] 2
[3,] 4
Run Code Online (Sandbox Code Playgroud) 我需要比较两个非结构化地址,并能够确定它们是否相同(或足够相似)。
我知道我们可以使用一些模糊逻辑进行这种比较,对拼写错误有一定的容忍度,但是......
我不想重新发明轮子。在不同的上下文中,这个问题似乎是一个普遍关注的问题,我认为有一种算法(可能稍作修改)可能适合这种情况。
提前致谢
我对两个单词列表的功能感兴趣,这两个单词列表将返回它们之间的顺序不可知的编辑距离.
也就是说,参数将是两个(例如空格分隔)单词列表,返回值将是列表中单词的编辑(或Levenshtein)距离的最小总和.
"cat rat bat"和之间的距离"rat bat cat"将为0. "cat rat bat"和之间的"fat had bad"距离与"rat bat cat"和之间的距离相同"had fat bad".4.如果列表中的单词数不相同,则较短的列表将填充0长度的单词.
我的直觉(没有用计算机科学课程培养)没有找到任何其他解决方案而不是使用蛮力:
|had|fat|bad| a solution
---+---+---+---+ +---+---+---+
cat| 2 | 1 | 2 | | | 1 | |
---+---+---+---+ +---+---+---+
rat| 2 | 1 | 2 | | 3 | | |
---+---+---+---+ +---+---+---+
bat| 2 | 1 | 1 | | | | 4 |
---+---+---+---+ +---+---+---+
Run Code Online (Sandbox Code Playgroud)
从第一行开始,选择一列并转到下一行,而无需重新访问已访问过的列.一遍又一遍地这样做,直到你尝试了所有的组合.
对我来说这听起来有点像旅行推销员的问题.是吗,你会如何解决我的特定问题?
我从raspi制作了一个交通信号灯原型。我的源代码给出了一个错误。埃罗说
Traceback (most recent call last):
File "/home/pi/testing.py", line 2, in <module>
import skfuzzy as fuzz
ImportError: No module named 'skfuzzy'
Run Code Online (Sandbox Code Playgroud)
我已经检查过我的raspi上已经安装了scikit-fuzzy,但是无论何时运行,源都无法识别出scikit-fuzzy工具。
这是我的一些源代码:
import numpy as np
import skfuzzy as fuzz
import RPi.GPIO as GPIO
import time
Curr_GtGB=40
Curr_GtSU=46
Curr_GtSS=26
Curr_GtK=12
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
redGB=16
yelGB=18
grenGB=22
redSU=40
yelSU=38
grenSU=36
redSS=33
yelSS=35
grenSS=37
redK=11
yelK=13
grenK=15
GPIO.setup(redGB, GPIO.OUT)
GPIO.setup(yelGB, GPIO.OUT)
GPIO.setup(grenGB, GPIO.OUT)
GPIO.setup(redSU, GPIO.OUT)
GPIO.setup(yelSU, GPIO.OUT)
GPIO.setup(grenSU, GPIO.OUT)
GPIO.setup(redSS, GPIO.OUT)
GPIO.setup(yelSS, GPIO.OUT)
GPIO.setup(grenSS, GPIO.OUT)
GPIO.setup(redK, GPIO.OUT)
GPIO.setup(yelK, GPIO.OUT)
GPIO.setup(grenK, GPIO.OUT)
Run Code Online (Sandbox Code Playgroud) 如何在Damerau-Levenshtein距离算法的实现中禁用删除计数,或者如果已经实现了其他算法,请指向我.
示例(禁用删除计数):
string1:你好吗?
string2:oyu怎么样?
距离: 1(换位,4次删除不计算)
这是算法:
public static int DamerauLevenshteinDistance(string string1, string string2, int threshold)
{
// Return trivial case - where they are equal
if (string1.Equals(string2))
return 0;
// Return trivial case - where one is empty
if (String.IsNullOrEmpty(string1) || String.IsNullOrEmpty(string2))
return (string1 ?? "").Length + (string2 ?? "").Length;
// Ensure string2 (inner cycle) is longer_transpositionRow
if (string1.Length > string2.Length)
{
var tmp = string1;
string1 = string2;
string2 = tmp;
}
// Return …Run Code Online (Sandbox Code Playgroud) 我希望解析十进制数字而不管它们的格式如何,这是未知的。原文的语言未知,可能会有所不同。此外,源字符串之前或之后可以包含一些额外的文本,例如货币或单位。
我正在使用以下内容:
# NOTE: Do not use, this algorithm is buggy. See below.
def extractnumber(value):
if (isinstance(value, int)): return value
if (isinstance(value, float)): return value
result = re.sub(r'&#\d+', '', value)
result = re.sub(r'[^0-9\,\.]', '', result)
if (len(result) == 0): return None
numPoints = result.count('.')
numCommas = result.count(',')
result = result.replace(",", ".")
if ((numPoints > 0 and numCommas > 0) or (numPoints == 1) or (numCommas == 1)):
decimalPart = result.split(".")[-1]
integerPart = "".join ( result.split(".")[0:-1] )
else:
integerPart …Run Code Online (Sandbox Code Playgroud) 极限是如何与 python 的fuzzywuzzy 模块一起工作的,它是什么意思?
matches = process.extract(query, choices, limit=2, scorer=fuzz.partial_ratio)
Run Code Online (Sandbox Code Playgroud) fuzzy ×9
fuzzy-logic ×3
algorithm ×2
python ×2
c# ×1
fuzzywuzzy ×1
matching ×1
parsing ×1
python-3.x ×1
r ×1
raspberry-pi ×1
solr ×1
stemming ×1
string ×1