使用 NSPredicate 时出现问题

发布于 2024-10-13 19:27:45 字数 723 浏览 5 评论 0原文

Sql查询:

select * from test_mart 其中替换(替换(替换(替换(替换(替换(较低(名称),'+'),'_'),'该'),'该'),'a'),'a')='tariq '

如果我必须简单地使用 Sqlite,我可以非常轻松地触发以下查询...但是在当前项目中我使用的是 Core Data,所以对 NSPredicate 不太熟悉。

该功能讨论删除所有字母数字字符,这意味着删除特殊字符。

在比较中应该有效的字符将为

ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890

但我们不应该对以下字符进行比较失败

:;,~`!@#$%^&*()_-+="'/?.> ,<|\

或者对于以下单词

'the' 'an' 'a'

一些示例:

  1. 'Walmart' 将被视为与 'Wal-Mart' 相同的收款人

  2. “The Shoe Store”将被视为与“Shoe Store”相同的收款人

  3. “Domino's Pizza”将被视为与“Dominos Pizza”相同的收款人

  4. 测试收款人”;将被视为与“测试收款人”相同的收款人

任何人都可以建议适当的谓词/正则表达式

谢谢吗?

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:

  1. 'Walmart' would be seen as the same payee as 'Wal-Mart'

  2. 'The Shoe Store' would be seen as the same payee as 'Shoe Store'

  3. 'Domino's Pizza' would be seen as the same payee as 'Dominos Pizza'

  4. 'Test Payee;' would be seen as the same payee as 'Test Payee'

Can any one suggest appropriate Predicates/Regular Expression ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反差帅 2024-10-20 19:27:45

我将在数据库中有一个额外的字段,它将是原始字段的处理版本,并删除所有不相关的字符。然后用它来进行比较。

您可能想看看 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

你的他你的她 2024-10-20 19:27:45

在我看来,您可能希望在数据被设置到核心数据存储之前对其进行标准化。因此,如果您收到“Wal-Mart”,请将其标准化为“walmart”一次,然后保存。那么您就不会多次进行所有这些昂贵的即时比较。

根据您的规则,规范化将相当简单:

  • 删除单词“a”、“an”和“the”
  • 删除标点符号

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:

  • Strip the words "a", "an", and "the"
  • Remove punctuation
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文