使用 NSPredicate 时出现问题
Sql查询:
select * from test_mart 其中替换(替换(替换(替换(替换(替换(较低(名称),'+'),'_'),'该'),'该'),'a'),'a')='tariq '
如果我必须简单地使用 Sqlite,我可以非常轻松地触发以下查询...但是在当前项目中我使用的是 Core Data,所以对 NSPredicate 不太熟悉。
该功能讨论删除所有字母数字字符,这意味着删除特殊字符。
在比较中应该有效的字符将为
ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890
但我们不应该对以下字符进行比较失败
:;,~`!@#$%^&*()_-+="'/?.> ,<|\
或者对于以下单词
'the' 'an' 'a'
一些示例:
'Walmart' 将被视为与 'Wal-Mart' 相同的收款人
“The Shoe Store”将被视为与“Shoe Store”相同的收款人
“Domino's Pizza”将被视为与“Dominos Pizza”相同的收款人
- 测试收款人”;将被视为与“测试收款人”相同的收款人
任何人都可以建议适当的谓词/正则表达式
谢谢吗?
Sql query:
select * from test_mart
where replace(replace(replace(replace(replace(replace(lower(name),'+'),'_'),'the '),' the'),'a '),' a')='tariq'
I can fire following query very easy, if I have to use simply Sqlite... but In current project I am using Core Data so not familiar about NSPredicate much.
The functionality talks about removing all BUT alphanumeric characters, which means removing special characters.
The characters that should be valid in the comparison would be
ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890
But we should not fail the comparison for the following characters
:;,~`!@#$%^&*()_-+="'/?.>,<|\
Or for the following words
'the' 'an' 'a'
Some examples:
'Walmart' would be seen as the same payee as 'Wal-Mart'
'The Shoe Store' would be seen as the same payee as 'Shoe Store'
'Domino's Pizza' would be seen as the same payee as 'Dominos Pizza'
- 'Test Payee;' would be seen as the same payee as 'Test Payee'
Can any one suggest appropriate Predicates/Regular Expression ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将在数据库中有一个额外的字段,它将是原始字段的处理版本,并删除所有不相关的字符。然后用它来进行比较。
您可能想看看 soundex 算法,它可能更适合您的目的... Soundex
I would have an extra field in the data base which would be a processed version of the original with all the irrelevant characters stripped out. Then use that for comparisons.
You might want to look at the soundex algorithm which may suite your purposes better... Soundex
在我看来,您可能希望在数据被设置到核心数据存储之前对其进行标准化。因此,如果您收到“Wal-Mart”,请将其标准化为“walmart”一次,然后保存。那么您就不会多次进行所有这些昂贵的即时比较。
根据您的规则,规范化将相当简单:
It seems to me that you would want to normalize your data before it every gets set into the core data store. So if you're given "Wal-Mart", normalize it to "walmart" once, and then save it. Then you won't be doing all of this expensive on-the-fly comparison many many times.
The normalization would be fairly simple, given your rules: