字符串匹配算法中的引用错误

我为两个字符串列之间的字符串匹配百分比 (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]

我错过了什么吗?


慕娘9325324
浏览 69回答 1
1回答

四季花海

它给我以下错误查询错误:ReferenceError: in_a is not defined at UDF$1(STRING, STRING) line 9, columns 8-9 at [52:1]我错过了什么吗?您至少应该修复第一个函数的签名,如下所示CREATE&nbsp;OR&nbsp;REPLACE&nbsp;FUNCTION&nbsp;`rep-ds-us.nboorla.similarity`(in_a&nbsp;STRING,&nbsp;in_b&nbsp;STRING)&nbsp;RETURNS&nbsp;INT64&nbsp;LANGUAGE&nbsp;js&nbsp;AS&nbsp;"""笔记;&nbsp;以上回答了您当前的具体问题,可能无法解决与您使用的代码相关的任何未来问题。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript