- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 agrep 找出两个字符串名称之间模糊字符串匹配的最佳精度。
但是,由于字符串数量巨大,我需要选择一个精度“max.distance”以将其应用于我尝试匹配的所有字符串。不可能为我尝试匹配的每个字符串选择最佳精度值“max.distance”。
例如,假设我对每个“BANK OF AMERICA CORP”和“1st Capital Bank”使用精度“max.distance”作为“0.2”、“0.1”和“0.05”。
首先,以下是“BANK OF AMERICA CORP”的“max.distance”为“0.2”、“0.1”和“0.05”的情况:
> agrep("BANK OF AMERICA CORP",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.2)
[1] "BANK OF AMERICA/PRIVATE BANK WEST" "BANK OF AMERICA SECURITIES"
[3] "BANK OF AMERICA SEC LLC" "BANK OF AMERICA SECURITIES LLC"
[5] "BANK OF AMERICA NT & SA" "BANK OF AMERICA CORP"
[7] "ALLIANZ OF AMERICA CORP" "Bank of America Securities/Vice Pre"
[9] "Bank of America Securities/Investme" "Bank of America/President"
[11] "Bank of America Securities LLC/Prin" "Bank of America Securities LLC/Mana"
[13] "Bank of America Securities LLC/Inve" "Bank of America Securities/Principa"
[15] "Bank of America Securities LLC/Bank" "Bank of America Sec/Investment Bank"
[17] "Bank Of America Securities/Managing" "Bank of America/Chairman--Midwest A"
[19] "Bank of America Securities LLC/Vice" "Bank of America Corporation/Sales C"
[21] "Bank of America Securities/Broker" "Bank of America Corporation/Banker"
[23] "Bank of America Corporation/Senior" "Bank of America Securities/Equity R"
[25] "Bank of America Corporation/Vice Ch" "BANK OF AMERICA CORPORATION"
[27] "BANK OF AMERICA HEADQUARTERS" "BANK OF AMERICA ADMINISTRATION"
[29] "BANK OF AMERICA N A" "Bank of America/Commercial Banking"
[31] "Bank of America Sec./Investment Ban"
>
> agrep("BANK OF AMERICA CORP",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.1)
[1] "BANK OF AMERICA CORP" "ALLIANZ OF AMERICA CORP"
[3] "Bank of America Corporation/Sales C" "Bank of America Corporation/Banker"
[5] "Bank of America Corporation/Senior" "Bank of America Corporation/Vice Ch"
[7] "BANK OF AMERICA CORPORATION"
>
> agrep("BANK OF AMERICA CORP",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.05)
[1] "BANK OF AMERICA CORP" "Bank of America Corporation/Sales C"
[3] "Bank of America Corporation/Banker" "Bank of America Corporation/Senior"
[5] "Bank of America Corporation/Vice Ch" "BANK OF AMERICA CORPORATION"
下面是“最大距离”为“0.2”、“0.1”和“0.05”的“第一资本银行”:
> agrep("1st Capital Bank",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.2)
[1] "HURST CAPITAL PARTNERS"
[2] "SOY CAPITAL BANK"
[3] "FIRST CAPITOL BANK OF VICTOR"
[4] "OSTERWEIS CAPITAL MANAGEMENT"
[5] "1ST NATIONAL BANK"
[6] "FIRST CAPITAL BANK"
[7] "SEATTLE 1ST NAT'L BANK"
[8] "FIELD POINT CAPITAL MANAGEMENT"
[9] "SUMMERSET CAPITAL MANAGEMENT"
[10] "AMERIQUEST CAPITAL ASSOC"
[11] "BB&T CAPITAL MARKETS"
[12] "HUGHES CAPITAL MANAGEMENT"
[13] "WELLS CAPITAL MANAGEMENT"
[14] "SUPERIOR ST CAPITAL ADVISORS"
[15] "ORMES CAPITAL MARKETS INC"
[16] "1ST NAT'L BANK OF IL"
[17] "ADVENT CAPITAL MANAGEMENT"
[18] "1ST CAPITOL BANK"
[19] "BIONDI REISS CAPITAL MANAGEMENT"
[20] "CCYBYS CAPITAL MARKETS"
[21] "SEACOAST CAPITAL PARTNERS"
[22] "DOUGLAS CAPITAL MANAGEMENT"
[23] "HIGHFIELDS CAPITAL MANAGEMENT"
[24] "PRECEPT CAPITAL MANAGEMENT LP"
[25] "AUGUST CAPITAL MANAGEMENT"
[26] "SAKSA CAPITAL MANAGEMENT"
[27] "IMS CAPITAL MANAGEMENT"
[28] "TRENT CAPITAL MANAGEMENT"
[29] "Ormes Capital Management"
[30] "GARNET CAPITAL MANAGEMENT LLC"
[31] "INTERFASE CAPITAL MANAGERS"
[32] "RJS CAPITAL MANAGEMENT INC"
[33] "1ST NATIONAL BANK OF DE KALB"
[34] "1ST NAT'L BANK OF PHILLIPS CO"
[35] "1ST NAT'L BANK OF OKLAHOMA"
[36] "PROGRESS CAPITAL MANAGEMENT INC"
[37] "CAPITAL BANK & TRUST"
[38] "1ST NATL BANK"
[39] "ASB Capital Management/Real Estate"
[40] "Sears Capital Management"
[41] "Osterweis Capital Management/Invest"
[42] "Cerberus Capital Management LP/Asse"
[43] "LVS Capital Management/President"
[44] "1st Central Bank/Banker"
[45] "Summit Capital Management"
[46] "Orwes Capital Markets/Stockbroker"
[47] "Ormes Capital Management/Investment"
[48] "Nevis Capital Management/Investment"
[49] "Duncan Hurst Capital Management"
[50] "Progress Capital Management/Preside"
[51] "Cerberus Capital Management LP"
[52] "Wit Capital/Banker"
[53] "Ormes Capital Markets Inc."
[54] "Ormes Capital Markets/President & C"
[55] "Berents & Hess Capital Management"
[56] "Progress Capital Management/Venture"
[57] "First Capital Bank of KY"
[58] "Foothill Capital/Banker"
[59] "Pequot Capital Management/Equity Re"
[60] "First Dominion Capital/Banking"
[61] "Greenwhich Capital/Banker"
[62] "Veritas Capital Management/Banker"
[63] "Veritas Capital Management/Investme"
[64] "Lesese Capital Management/Investmen"
[65] "Douglas Capital Management/Investme"
[66] "FIRST NATINAL BANK OF AMARILLO"
[67] "NEVIS CAPITAL MANAGEMENT"
[68] "VERITAS CAPITAL MANAGEMENT"
[69] "SIEBERT CAPITAL MARKETS"
[70] "HOURGLASS CAPITAL MANAGEMENT"
[71] "1ST NATIONAL BANK DALHART"
[72] "TEXAS CAPITAL BANK"
[73] "NICHOLAS CAPITAL MANAGEMENT"
[74] "CERBUS CAPITAL MANAGEMENT"
[75] "CROESUS CAPITAL MANAGEMENT"
[76] "EAST WEST CAPITAL ASSOCIATES INC"
[77] "PRENDERGAST CAPITAL MANAGEMENT"
[78] "NANTUCKET CAPITAL MANAGEMENT"
[79] "1ST NATIONAL BANK TEMPLE"
[80] "ENTRUST CAPITAL INC"
[81] "1ST NATIONAL BANK OF IL"
[82] "SIMMS CAPITAL MANAGEMENT"
[83] "FIRST CAPITAL ADVISORS"
[84] "FIRST CAPITAL MANAGEMENT LTD"
[85] "1ST NATIONAL BANK & TRUST"
[86] "PENTECOST CAPITAL MANAGEMENT INC"
[87] "EAST-WEST CAPITAL ASSOCIATES"
[88] "1ST NAT'L BANK OF JOLIET"
[89] "FIRST CAPITOL BANK OF VICTO"
[90] "FIRST CAPITAL FINANCIAL"
[91] "PACIFIC COAST CAPITAL PARTNERS"
[92] "FIRST CAPITOL BANK"
[93] "FIRST CAPITAL ENGINEERING"
[94] "MIDWEST CAPITOL MANAGEMENT"
[95] "PEQUOT CAPITAL MANAGEMENT"
[96] "AGGOTT CAPITAL MANAGEMENT"
[97] "SIMMS CAPITAL MANAGEMENT INC"
[98] "PHILLIPS CAPITAL MANAGEMENT LLC"
[99] "1ST NATIONAL BANK OF COLD SP"
[100] "SOY CAPITOL BANK"
>
> agrep("1st Capital Bank",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.1)
[1] "FIRST CAPITOL BANK OF VICTOR" "FIRST CAPITAL BANK"
[3] "1ST CAPITOL BANK" "First Capital Bank of KY"
[5] "TEXAS CAPITAL BANK" "FIRST CAPITOL BANK OF VICTO"
[7] "FIRST CAPITOL BANK"
>
> agrep("1st Capital Bank",C1999_0[,2],ignore.case = TRUE, value = TRUE,fixed = TRUE,max.distance =0.05)
[1] "FIRST CAPITAL BANK" "1ST CAPITOL BANK"
[3] "First Capital Bank of KY"
正如您所看到的,找到适用于每个字符串(例如“BANK OF AMERICA CORP”和“1st Capital Bank”)的“max.distance”的通用精度值确实很困难。此外,除了这两个之外,我还有更多的公司名称,这就是为什么我很难找到模糊字符串匹配的通用精度值和命令的原因。
C1999_0 的原始数据文件太大,无法附加,因此我认为仅使用如上所示的输出值就足以复制。
我知道有几个子类别需要操作,例如成本、替换、插入等,但它们与仅更改“max.distance”值本身没有太大区别。
如果我能获得这方面的帮助,我将不胜感激!
最佳答案
agrep
存在问题就是它就像 grep
如 help("grep")
中所述
Since someone who read the description carelessly even filed a bug report on it, do note that this matches substrings of each element of
x
(just asgrep
does) and not whole elements. See alsoadist
in package utils, which optionally returns the offsets of the matched substrings.
这似乎是您后一个示例中的问题,因为您有许多名称包含“资本”或“银行”或两者都包含。我要做的就是用来计算 Levenshtein distance (这就是 agrep
的作用,或者是通用版本,仅适用于子字符串)并取距离最短的。例如,
C1999 <- c("HURST CAPITAL PARTNERS", "SOY CAPITAL BANK", "FIRST CAPITOL BANK OF VICTOR", "OSTERWEIS CAPITAL MANAGEMENT", "1ST NATIONAL BANK", "FIRST CAPITAL BANK", "SEATTLE 1ST NAT'L BANK", "FIELD POINT CAPITAL MANAGEMENT", "SUMMERSET CAPITAL MANAGEMENT", "AMERIQUEST CAPITAL ASSOC", "BB&T CAPITAL MARKETS", "HUGHES CAPITAL MANAGEMENT", "WELLS CAPITAL MANAGEMENT", "SUPERIOR ST CAPITAL ADVISORS", "ORMES CAPITAL MARKETS INC", "1ST NAT'L BANK OF IL", "ADVENT CAPITAL MANAGEMENT", "1ST CAPITOL BANK", "BIONDI REISS CAPITAL MANAGEMENT", "CCYBYS CAPITAL MARKETS", "SEACOAST CAPITAL PARTNERS", "DOUGLAS CAPITAL MANAGEMENT", "HIGHFIELDS CAPITAL MANAGEMENT", "PRECEPT CAPITAL MANAGEMENT LP", "AUGUST CAPITAL MANAGEMENT", "SAKSA CAPITAL MANAGEMENT", "IMS CAPITAL MANAGEMENT", "TRENT CAPITAL MANAGEMENT", "Ormes Capital Management", "GARNET CAPITAL MANAGEMENT LLC", "INTERFASE CAPITAL MANAGERS", "RJS CAPITAL MANAGEMENT INC", "1ST NATIONAL BANK OF DE KALB", "1ST NAT'L BANK OF PHILLIPS CO", "1ST NAT'L BANK OF OKLAHOMA", "PROGRESS CAPITAL MANAGEMENT INC", "CAPITAL BANK & TRUST", "1ST NATL BANK", "ASB Capital Management/Real Estate", "Sears Capital Management", "Osterweis Capital Management/Invest", "Cerberus Capital Management LP/Asse", "LVS Capital Management/President", "1st Central Bank/Banker", "Summit Capital Management", "Orwes Capital Markets/Stockbroker", "Ormes Capital Management/Investment", "Nevis Capital Management/Investment", "Duncan Hurst Capital Management", "Progress Capital Management/Preside", "Cerberus Capital Management LP", "Wit Capital/Banker", "Ormes Capital Markets Inc.", "Ormes Capital Markets/President & C", "Berents & Hess Capital Management", "Progress Capital Management/Venture", "First Capital Bank of KY", "Foothill Capital/Banker", "Pequot Capital Management/Equity Re", "First Dominion Capital/Banking", "Greenwhich Capital/Banker", "Veritas Capital Management/Banker", "Veritas Capital Management/Investme", "Lesese Capital Management/Investmen", "Douglas Capital Management/Investme", "FIRST NATINAL BANK OF AMARILLO", "NEVIS CAPITAL MANAGEMENT", "VERITAS CAPITAL MANAGEMENT", "SIEBERT CAPITAL MARKETS", "HOURGLASS CAPITAL MANAGEMENT", "1ST NATIONAL BANK DALHART", "TEXAS CAPITAL BANK", "NICHOLAS CAPITAL MANAGEMENT", "CERBUS CAPITAL MANAGEMENT", "CROESUS CAPITAL MANAGEMENT", "EAST WEST CAPITAL ASSOCIATES INC", "PRENDERGAST CAPITAL MANAGEMENT", "NANTUCKET CAPITAL MANAGEMENT", "1ST NATIONAL BANK TEMPLE", "ENTRUST CAPITAL INC", "1ST NATIONAL BANK OF IL", "SIMMS CAPITAL MANAGEMENT", "FIRST CAPITAL ADVISORS", "FIRST CAPITAL MANAGEMENT LTD", "1ST NATIONAL BANK & TRUST", "PENTECOST CAPITAL MANAGEMENT INC", "EAST-WEST CAPITAL ASSOCIATES", "1ST NAT'L BANK OF JOLIET", "FIRST CAPITOL BANK OF VICTO", "FIRST CAPITAL FINANCIAL", "PACIFIC COAST CAPITAL PARTNERS", "FIRST CAPITOL BANK", "FIRST CAPITAL ENGINEERING", "MIDWEST CAPITOL MANAGEMENT", "PEQUOT CAPITAL MANAGEMENT", "AGGOTT CAPITAL MANAGEMENT", "SIMMS CAPITAL MANAGEMENT INC", "PHILLIPS CAPITAL MANAGEMENT LLC", "1ST NATIONAL BANK OF COLD SP", "SOY CAPITOL BANK")
func <- function(x, y, tol = 0L){
require(stringdist)
dista <- stringdist::stringdist(x, y, method = "lv")
min_dista <- min(dista)
y[dista <= min_dista + tol]
}
func("1st Capital Bank", C1999)
#R [1] "Wit Capital/Banker"
func("1st Capital Bank", C1999, 4L)
#R [1] "Wit Capital/Banker" "First Capital Bank of KY"
func("1st Capital Bank", C1999, 10L)
#R [1] "SOY CAPITAL BANK" "1ST NATIONAL BANK"
#R [3] "FIRST CAPITAL BANK" "1ST CAPITOL BANK"
#R [5] "Ormes Capital Management" "1ST NATL BANK"
#R [7] "Sears Capital Management" "1st Central Bank/Banker"
#R [9] "Summit Capital Management" "Wit Capital/Banker"
#R [11] "Ormes Capital Markets Inc." "First Capital Bank of KY"
#R [13] "Foothill Capital/Banker" "Greenwhich Capital/Banker"
#R [15] "TEXAS CAPITAL BANK" "FIRST CAPITOL BANK"
#R [17] "SOY CAPITOL BANK"
# ignoring cases
func <- function(x, y, tol = 0L){
require(stringdist)
dista <- stringdist::stringdist(tolower(x), tolower(y), method = "lv")
min_dista <- min(dista)
y[dista <= min_dista + tol]
}
func("1st Capital Bank", C1999, 0L)
#R [1] "1ST CAPITOL BANK"
tol
func
中的参数控制是否要包含 tol
的示例远离最小编辑距离。我发现我没有准确回答您的要求(如何使用 agrep
获得模糊字符串匹配的精确通用“max.distance”值?),但我认为我的答案可能是您正在寻找什么。
我使用stringdist::stringdist
而不是adist
因为前者似乎更快。它仍然可能有点慢,我希望有一个 R 包可以设置最大距离,但我还没有遇到过这样的包。这可以使(当时有上限的)Levenshtein 距离的计算变得更快。
关于r - 如何使用 agrep 获得模糊字符串匹配的精确公共(public) "max.distance"值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52273813/
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: When should [assembly: InternalsVisibleTo()] be used?
问题与微服务有关,当我有多个微服务提供将被订购和计费的功能/服务时。 我正在确定采用哪种方法, a) 每个可计费微服务有一个订单和一个计费服务,有各自的数据库。b) 跨所有微服务的通用订单管理和计费服
我正在尝试使用 gcloud图书馆。 (ns firengine.state (:import [com.google.cloud AuthCredentials] [com.goog
Java 允许定义以下一对类。 class Class1 { ... } public Class2 { public Class2(Class1 c1) { ... } } 如果因为 Class1
我正在尝试查找文件 1 和文件 2 中的共同行。如果公共(public)行存在,我想写入文件 2 中的行,否则打印文件 1 中的非公共(public)行。fin1 和 fin2 是这里的文件句柄。它读
好吧,这是一个满口的标题。不过,这让我明白了。这是我的代码的要点,在 jar 里: public class NetworkShared { public static class Login
我在使用 ltree 时遇到 PHP 问题来自 PostgreSQL .我在 SQL 中这样做: SELECT * FROM tabla t WHERE t.parent_path " for "OP
我知道如何为类/接口(interface)/包的子集生成 Javadoc。但是有没有办法只为公共(public)方法的一个子集生成 Javadoc? 我更喜欢能够将方法(Javadoc 标记或注释)标
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: c#: why have empty get set properties instead of usin
在我们的每个项目中,都有一个文件用于存储该项目中使用的各种SQL 语句。类的声明方式和字符串的声明方式有一些变化。 示例类声明: internal sealed class ClassName int
我根据 http://docs.jquery.com/Plugins/Authoring 定义了我的插件 (function( $ ){ var methods = { init : fu
我正在使用 Inno Setup 来构建我的安装程序,我有 C:\Users\Public文件夹硬编码在我的 [Files] 中放置一些文件的部分(Inno Setup 没有此文件夹的常量) 我的目标
我有一个 dataframe1 包含像 'ID', 'A', 'B', 'C', 'D', 'E', 'F', 'G' 这样的列. 现在,我创建了两个数据框, dataframe2 包含 'ID',
我有一个抽象类,不幸的是我无法更改它的定义,它基本上提供了一个抽象方法,有点像。 public abstract void do(Data someData, BaseInterface interf
我刚刚在重构时偶然发现了一段奇怪的代码。它看起来像是分解出两个 readString() 方法的共同部分的候选者,只是它似乎是不可能的(这对我来说是一个令人毛骨悚然的脑筋急转弯): private f
是否有解析为公用文件夹的属性?显然,我不想在目录结构中对“c:\users\public”进行硬编码,但我找不到预定义的 Property解决这个问题。是否有一种可接受的方式来指定要在此处安装和/或在
我试图将值从一个类传递到另一个类。 subPanel1 类读取全局变量,但当我通过调整监听器更新这些变量时,它不会更改值。我试图将 rc、gc 和 bc 变量从 subPanel2 类传递到 subP
我想使用具有自动属性的干净且编码较少的类。所有属性(property)都是公共(public)的。在同一类的方法中我也使用了该属性。因此,我认为这种方法是可混搭的,因为我将公共(public)属性用于
不久前,我在 Android 应用程序中创建了一个 SQLiteHelper 类。我不是 100% 确定原因,但表名和列名是嵌套公共(public)静态抽象类中的公共(public)静态最终字段。我记
这个问题已经有答案了: Cannot make a static reference to the non-static method (8 个回答) 已关闭 3 年前。 我正在为类(class)做一
我是一名优秀的程序员,十分优秀!