gpt4 book ai didi

multidimensional-array - 在 Salesforce 中优化 Levenshtein 距离算法

转载 作者:行者123 更新时间:2023-12-04 14:38:48 25 4
gpt4 key购买 nike

我有一个名为 customer 的自定义对象,其中包含 Customer_Name、Address_Line_1、Post_Code 等字段。

我想遍历所有记录并比较 Customer_Name 的相似性(基于模糊搜索或编辑距离)。如果相似度高于或低于某个阈值,自定义字段 (Possible_Duplicate_Customer_ID__c) 将被更新以识别可能的重复项。

我已经设法实现了这一点,但我遇到了 2 个问题:

1).超过 Salesforce 管理器限制(太多脚本语句:200001)可能是由 Levenshtein 距离算法所需的大量循环引起的。2).我提交的列表 (newList) 也包含重复的 ID。

    private static List<Customer__c> newList = new List<Customer__c>();

webService static Integer findDupes() {

Integer returnCount = 0;
Double cost = 0;
Integer COST_THRESHOLD = 5;

Map<id,Customer__c> cMap = new Map<id,Customer__c>([
select ID, Name, Customer_Name__c, Possible_Duplicate_Customer_ID__c
from Customer__c
]);

List<Customer__c> custList1 = cMap.values();
List<Customer__c> custList2 = custList1.clone();

for (Customer__c cust1 :custList1) {
for (Customer__c cust2 :custList2) {
cost = LevenshteinDistance.computeLevenshteinDistance(
cust1.Customer_Name__c, cust2.Customer_Name__c);
if(cost<COST_THRESHOLD && cost != 0) {
Customer__c c = new Customer__c(
id = cust2.Id,
Possible_Duplicate_Customer_ID__c = cust1.Name
);
newList.add(c);
}
System.debug(cost+' edits to transform '
+cust1.Customer_Name__c+' to '+cust2.Customer_Name__c);
}
}

returnCount = newList.size();

update newList;
return returnCount;
}

最佳答案

您是否尝试过新的getLevenshteinDistance method 字符串

另请参阅我的问题/方法 here .我坚持只返回同一国家/地区具有相同邮政编码或城市的匹配项,从而减少初始匹配项的数量。

关于multidimensional-array - 在 Salesforce 中优化 Levenshtein 距离算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10210980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com