【发布时间】:2015-09-17 21:32:22
【问题描述】:
我有两个歌曲标题列表,每个列表都在一个纯文本文件中,它们是许可歌词文件的文件名 - 我想检查较短的列表标题(针)是否在较长的列表(干草堆)中。脚本/应用程序应返回不在大海捞针中的标题列表。
我更喜欢使用 Python 或 shell 脚本 (BASH),或者只使用可以处理所需模糊性的可视差异程序。
主要问题是标题需要模糊匹配以解决数据输入错误以及可能的字序问题。
Haystack 示例(注意一些重复和接近重复的行,匹配突出显示):
Yearn
Yesterday, Today And Forever
Yesterday, Today, Forever
You
You Alone
You Are Here (The Same Power)
You Are Holy
You Are Holy (Prince Of Peace)
You Are Mighty
You Are Mine
You Are My All In All
You Are My Hiding Place
You Are My King (Amazing Love)
You Are Righteous (Hope)
You Are So Faithful
You Are So Good to Me
You Are Worthy Of My Praise
You Have Been Good
You Led Me To The Cross
You Reign
You Rescued Me
You Said
You Sent Your Own
You Set Me Apart (Dwell In Your House)
You alone are worthy (Glory in the highest)
You are God in heaven (let my words be few)
You are always fighting for us (Hallelujah you have overcome)
You are beautiful (I stand in awe)
You are beautiful beyond description
You are mighty
You are my all in all
You are my hiding place
You are my passion
You are still Holy
You are the Holy One (We exalt Your name)
You are the mighty King
You are the mighty warrior
You are the vine
**You chose the cross (Lost in wonder)**
You have shown me favour unending
You hold the broken hearted
You laid aside Your majesty
You said
You're Worthy Of My Praise
You're calling me (Unashamed love)
You're the God of this city
You're the Lion of Judah
You're the word of God the Father (Across the lands)
You've put a new song in my heart
Your Beloved
Your Grace is Enough
Your Great Name We Praise
Your Great Name We Praise-2
Your Light (You Have Turned)
Your Light Is Over Me (His Love)
**Your Love**
**Your Love Is Amazing**
Your Love Is Deep
Your Love Is Deeper - Jesus, Lord of Heaven (Phil Wickham)
Your Love Oh Lord
Your Love Oh Lord (Psalm 36)
Your Love is Extravagant
Your Power (Send Me)
Your blood speaks a better word
Your everlasting love
**Your grace is enough**
**Your grace is enough (Great is Your faithfulness)**
Your mercy is falling
Your mercy taught us how to dance (Dancing generation)
Your voice stills the oceans (nothing is impossible)
Yours Is The Kingdom
针样:
You Are Good (I Want To Scream It Out)
You Are My Strength (In The Fullness)
You Are My Vision O King Of My Heart
You Are The King Of Glory (Hosanna To The Son)
**You Chose The Cross (Lost In Wonder)**
**Your Grace Is Enough (This Is Our God)**
**Your Love Is Amazing Steady And Unchanging**
**Your Love Shining Like The Sun**
请注意,针标题“Your Love Shining Like The Sun”只是“Your Love”的可能匹配项。最好不要匹配失败,因此任何不确定的标题匹配都应该出现在输出中。
comm -1 -3 <(sort haystack.txt) <(sort needle.txt)
没有找到任何匹配项。 diff 或 grep 似乎他们也有同样的问题,不够模糊。 Kdiff3 和 diffnow.com 与手动比较一样快,因为我仍然必须扫描几乎所有匹配项,它们只能处理空格和字母大小写的差异。
来自 prestosoft.com 的ExamDiffPro 看起来很有可能,但它仅适用于 MS Windows,在我使用 WINE 或 VirtualBox 之前,我更喜欢原生 Linux 解决方案。
针实际上是一个 CSV,所以我考虑过使用 LibreOffice 并将其视为数据库并执行 SQL 查询或使用带有 hlookup 或其他东西的电子表格...Another 问题引导我到OpenRefine (formerly google-refine)
似乎这是一个常见的问题类别(它基本上是经常使用 [Levenshtein] 编辑距离计算的“记录链接”),我应该如何处理它?请给点建议?
【问题讨论】:
-
可能听起来很愚蠢...但是我们可以将两个文件都加载到表中并通过简单的连接来完成
标签: database list comparison recordset fuzzy-comparison