Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于javascript的文本匹配器_Javascript_Node.js - Fatal编程技术网

基于javascript的文本匹配器

基于javascript的文本匹配器,javascript,node.js,Javascript,Node.js,我需要一些JS库,它可以通过长文本请求匹配类别 例如,我有苹果,红苹果,绿苹果,橙子,并请求西班牙的1公斤红多汁苹果。在这种情况下,类别应为红苹果。因此,简单的循环和contains()是不够的 我搜索了一些LIB,例如,但分类不合适,因为在我的情况下,我不知道所有可能的请求,也无法训练它 也许我需要阻止请求,计算请求到类别的单词距离并对其进行排序 请帮助我进行这种反全文搜索。这是一种非常基本的方法,但它符合您提供的单个示例: var categories = [ "Apples", "Red

我需要一些JS库,它可以通过长文本请求匹配类别

例如,我有
苹果
红苹果
绿苹果
橙子
,并请求
西班牙的1公斤红多汁苹果
。在这种情况下,类别应为
红苹果
。因此,简单的循环和
contains()
是不够的

我搜索了一些LIB,例如,但分类不合适,因为在我的情况下,我不知道所有可能的请求,也无法训练它

也许我需要阻止请求,计算请求到类别的单词距离并对其进行排序


请帮助我进行这种反全文搜索。

这是一种非常基本的方法,但它符合您提供的单个示例:

var categories = [ "Apples", "Red Apples", "Green Apples", "Oranges" ];
var intputString = "Red Juicy Apple 1 Kilo from Spain";

var words = inputString.split(' ');

for (int wordIndex = 0; wordIndex < words.length; wordIndex++) {
  for (int categoryIndex = 0; categoryIndex < categories.length; categoryIndex++) {
    if (categories[categoryIndex].indexOf(words[wordIndex]) > -1) {
      // The word words[wordIndex] is in the string categories[categoryIndex]
    }
  }
}
var类别=[“苹果”、“红苹果”、“绿苹果”、“橙子”];
var intputString=“来自西班牙的1公斤红多汁苹果”;
var words=inputString.split(“”);
for(int-wordIndex=0;wordIndex-1){
//单词[wordIndex]位于字符串类别[categoryIndex]中
}
}
}
我已经找到了,而且似乎有效

>>f = FuzzySet(['Apples', 'Red Apples', 'Green Apples', 'Oranges'])
>>f.get("Red Juicy Apple 1 Kilo from Spain")

[Array[2]0: 0.3030303030303031: "Red Apples"length: 2__proto__: Array[0]]

希望它不仅是英文的……

请看是,它仍然是包含的循环。我刚刚找到了lib,希望能对我有所帮助。谢谢你的回答@是的,你的答案比我的好得多!这比我的答案好!