뭔가를 작동하는 것을 볼 수 있도록 당신에게 대안을 제공하는 것입니다 배열에 이름을 변환 :
irb> names.map!{|n|n.scan(/[^\s.]+\.?/)}
["J.", "R.", "Smith"]
["John", "R.", "Smith"]
["John", "Smith"]
["John", "Roy", "Smith"]
["Johnny", "Smith"]
2 : 정체성의 일부 기능 : 동일한 이름의 부분이 .permutation
+ .zip
+ .max
결정 일부 사용자 지정 기능을 적용하는 데 사용할 수있는
for a,b in names.combination(2)
p [(a&b).size,a,b]
end
[2, ["J.", "R.", "Smith"], ["John", "R.", "Smith"]]
[1, ["J.", "R.", "Smith"], ["John", "Smith"]]
[1, ["J.", "R.", "Smith"], ["John", "Roy", "Smith"]]
[1, ["J.", "R.", "Smith"], ["Johnny", "Smith"]]
[2, ["John", "R.", "Smith"], ["John", "Smith"]]
[2, ["John", "R.", "Smith"], ["John", "Roy", "Smith"]]
[1, ["John", "R.", "Smith"], ["Johnny", "Smith"]]
[2, ["John", "Smith"], ["John", "Roy", "Smith"]]
[1, ["John", "Smith"], ["Johnny", "Smith"]]
[1, ["John", "Roy", "Smith"], ["Johnny", "Smith"]]
또는 대신 &
의이다.
UPD :
aim = 'Rob Bobbie Johnson'
candidates = [
"Bob Robbie John",
"Bobbie J. Roberto",
"R.J.B.",
]
$synonyms = Hash[ [
["bob",["bobbie"]],
["rob",["robbie","roberto"]],
] ]
def prepare name
name.scan(/[^\s.]+\.?/).map &:downcase
end
def mf a,b # magick function
a.zip(b).map do |i,j|
next 1 if i == j
next 0.9 if $synonyms[i].to_a.include?(j) || $synonyms[j].to_a.include?(i)
next 0.5 if i[/\.$/] && j.start_with?(i.chomp '.')
next 0.5 if j[/\.$/] && i.start_with?(j.chomp '.')
-10 # if some part of name appears to be different -
# it's bad even if another two parts were good
end.inject :+
end
for c in candidates
results = prepare(c).permutation.map do |per|
[mf(prepare(aim),per),per]
end
p [results.transpose.first.max,c]
end
[-8.2, "Bob Robbie John"] # 0.9 + 0.9 - 10 # Johnson != John # I think ..)
[2.4, "Bobbie J. Roberto"] # 1 + 0.9 + 0.5 # Rob == Roberto, Bobbie == Bobbie, Johnson ~~ J.
[1.5, "R.J.B."] # 0.5 + 0.5 + 0.5
어떻게 이런이 같은 사람임을 알 수 있습니까? –
신원을 밝히기를 원하는 인간은 이름의 일관된 철자법을 사용합니다. 신원을 밝히지 않으려는 사람은 크게 다르며 알고리즘은 이름 문자열 만 사용하여이를 포착하지 않습니다. 주소, 전화 번호, 우편 번호, 신용 카드 번호, 이메일 주소 또는 고유하게 식별 할 수있는 다른 주소도 일치시켜야합니다. 또한, "J." "John", "James", "Jerry"또는 "Jon"과 같은 다른 철자가 될 수 있습니다. –
나는 그것들이 동일하지만 100 % 회사 경영진의 맥락에서 이것을하고있는 것을 모른다. 그래서 대부분 나는 그들이 상대적으로 똑같을 수 있다고 생각한다. 일반적으로 볼 수있는 이름에는 한 가지 변형 만 존재하며 다른 방법으로 삭제할 수 있습니다. 이름이 일치하는 경우 인간의 관점에서 알 필요가 있습니다. – hadees