入力:
set firstList to {'red ball','blue','yellow'}
set secondList to {'grasshopper','yellowjacket','blueberry','redball'}
出力:
{'yellowjacket','blueberry','redball'}
このようなことを達成するための最良の方法は何ですか? 基本的に、各リスト内のアイテム間の類似性を探しています。
入力:
set firstList to {'red ball','blue','yellow'}
set secondList to {'grasshopper','yellowjacket','blueberry','redball'}
出力:
{'yellowjacket','blueberry','redball'}
このようなことを達成するための最良の方法は何ですか? 基本的に、各リスト内のアイテム間の類似性を探しています。
試す:
set matchList to {}
set firstList to {"red ball ", "blue", "yellow"}
set secondList to {"grasshopper", "yellowjacket", "blueberry", "redball"}
repeat with aItem in firstList
set myTerm to do shell script "echo " & quoted form of aItem & " | sed -E 's/ */ ?/g'"
repeat with bItem in secondList
try
set end of matchList to (do shell script "echo " & quoted form of bItem & " | grep -E " & quoted form of myTerm)
end try
end repeat
end repeat
return matchList
編集
set matchList to {}
set firstList to {"jamesdoe","jackknow","henryrod"}
set secondList to {"James Doe", "Jack Know", "John Matthews"}
set {TID, text item delimiters} to {text item delimiters, {""}}
repeat with aItem in firstList
set AppleScript's text item delimiters to {""}
set myTerm to text items of aItem
set AppleScript's text item delimiters to {" ?"}
set myTerm to myTerm as text
repeat with bItem in secondList
try
set end of matchList to (do shell script "echo " & quoted form of bItem & " | grep -Ei " & quoted form of myTerm)
end try
end repeat
end repeat
set text item delimiters to TID
return matchList
編集2
set matchList to {}
set firstList to {"jamesdoe", "jackknow", "henryrod"}
set secondList to {"James Doe", "Jack Know", "John Matthews"}
set {TID, text item delimiters} to {text item delimiters, {""}}
repeat with aItem in firstList
set AppleScript's text item delimiters to {""}
set myTerm to text items of aItem
set AppleScript's text item delimiters to {" ?"}
set myTerm to myTerm as text
repeat with bItem in secondList
try
do shell script "echo " & quoted form of bItem & " | grep -Ei " & quoted form of myTerm
set end of matchList to (aItem's contents)
exit repeat
end try
end repeat
end repeat
set text item delimiters to TID
return matchList