javascript - 字符串匹配算法中的引用错误
问题描述
我已经为两个字符串列之间的字符串匹配百分比(0-1)创建了 UDF,并且在执行以下查询时遇到此错误。我想执行此代码以获取名称匹配算法以显示从 0- 开始的概率算法1 值。我创建了两个函数并在该函数中定义了两个字符串列。
CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.similarity`(name STRING, to_name STRING) RETURNS INT64 LANGUAGE js AS """
/*
* Data Quality Function - Fuzzy Matching
* dq_fm_LevenshteinDistance
* Based off of https://gist.github.com/andrei-m/982927
* input: Two strings to compare the edit distance of.
* returns: Integer of the edit distance.
*/
var a = in_a.toLowerCase();
var b = in_b.toLowerCase();
if(a.length == 0) return b.length;
if(b.length == 0) return a.length;
var matrix = [];
// increment along the first column of each row
var i;
for(i = 0; i <= b.length; i++){
matrix[i] = [i];
}
// increment each column in the first row
var j;
for(j = 0; j <= a.length; j++){
matrix[0][j] = j;
}
// Fill in the rest of the matrix
for(i = 1; i <= b.length; i++){
for(j = 1; j <= a.length; j++){
if(b.charAt(i-1) == a.charAt(j-1)){
matrix[i][j] = matrix[i-1][j-1];
} else {
matrix[i][j] =
Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
}
}
return matrix[b.length][a.length];
""";
CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.conf`(name STRING, to_name STRING) AS (
/*
* Data Quality Function - Fuzzy Matching
* dq_fm_ldist_ratio
* input: Two strings to compare.
* returns: The Levenshtein similarity ratio.
*/
(LENGTH(name) + LENGTH(to_name) - `rep-ds-us.nboorla.similarity`(name, to_name))
/ (LENGTH(name) + LENGTH(to_name))
);
select t1.name,t2.to_name,`rep-ds-us.nboorla.conf`(t1.name,t2.to_name)
from `rep-ds-us.r4e_mongo.ratings` t1
JOIN `rep-ds-us.r4e_mongo.mongo_repbiz_request_reviews` t2 on t2.id=t1.id
limit 10
但它给了我以下错误
Query error: ReferenceError: in_a is not defined at UDF$1(STRING, STRING) line 9, columns 8-9 at [52:1]
我错过了什么吗?
解决方案
它给了我以下错误
查询错误:ReferenceError: in_a is not defined at UDF$1(STRING, STRING) line 9, columns 8-9 at [52:1]
我错过了什么吗?
您至少应该为您的第一个函数修复签名,如下所示
CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.similarity`(in_a STRING, in_b STRING) RETURNS INT64 LANGUAGE js AS """
笔记; 以上回答了您当前的具体问题,可能无法解决与您使用的代码相关的任何未来问题。
推荐阅读
- c++ - 按值或按引用返回 unique_ptr?
- android - 如何在 Android 上获取 Seekbar 当前背景和进度条颜色
- flutter - 未处理的异常:SqliteException(1):没有这样的表:main.checkLists,SQL 逻辑错误(代码 1)[在 Moor]
- python - DCGAN如何去RGB而不是灰度
- python - 将多个具有相同列命名的 csv 组合起来
- python - 使用 scipy 拟合微分方程,得到“对象对于所需数组来说太深”
- wordpress - 在我的 wordpress 网站上设置广告 (Google Adsense)
- reactjs - 如何在 ThemeProvider 的子项中访问 Material-UI 自定义主题
- c++ - 想不出这个多步骤的益智书问题(C++)?
- jmeter - 如何让我在 Jmeter 中的下一个采样器等到我的文件被下载?