Objective C 中的智能句子比较
我需要在 Objective C 中进行智能句子比较。
详细信息如下所述。
我有一根主弦。我将其命名为“OriginalString”
NSString *OriginalString = @""HOW DID STUDENT EMILY DO TODAY";
然后我有很多字符串,我需要与原始字符串进行比较。它们
NSString *CompareString1 = @"HOW DID EMILY DO "
NSString *CompareSting = @"HOW DID YOUR FATHER"
NSString *CompareString2 = @"WHAT IS YOUR EMILY"
NSString *CompareString3 = @"THIS IS THE FAST DO ONE"
NSString *CompareString4 = @"THIS SEARCH EMILY EXAMPLE DO"
来自这5个CompareStrings,我需要获取相对于原始字符串最高的字符串“HOW DID EMILY DO” (艾米丽学生今天表现如何)。
让我告诉你一件事。
如果我在 CompareStrings 组中有一个附加字符串作为“HOW DID STUDENT DO TODAY”,
那么现在我的 CompareStrings 是
NSString *CompareString1 = @"HOW DID EMILY DO "
NSString *CompareSting = @"HOW DID YOUR FATHER"
NSString *CompareString2 = @"WHAT IS YOUR EMILY"
NSString *CompareString3 = @"THIS IS THE FAST DO ONE"
NSString *CompareString4 = @"THIS SEARCH EMILY EXAMPLE DO"
NSString *CompareString4 = @"HOW DID STUDENT DO TODAY"
来自这 6 个 CompareStrings,我需要获取字符串“HOW DID STUDENT DO TODAY”,该字符串相对于原始字符串(学生艾米丽今天做了什么)
我查看了 NSPredicate“比较和类似”方法。然而,我没有找到任何方法来完成这个过程,
感谢任何关于弄清楚这个概念的帮助。
谢谢。
I need to do the intelligence Sentence comparison in Objective C.
The Detail's are explained below.
I have one main string. I named it as "OriginalString"
NSString *OriginalString = @""HOW DID STUDENT EMILY DO TODAY";
Then I have many strings, that i need to compare with the Original String.They are
NSString *CompareString1 = @"HOW DID EMILY DO "
NSString *CompareSting = @"HOW DID YOUR FATHER"
NSString *CompareString2 = @"WHAT IS YOUR EMILY"
NSString *CompareString3 = @"THIS IS THE FAST DO ONE"
NSString *CompareString4 = @"THIS SEARCH EMILY EXAMPLE DO"
From these 5 CompareStrings ,i need to get the string "HOW DID EMILY DO" which is highest relative to the Original string(HOW DID STUDENT EMILY DO TODAY) .
Let me tell you one thing.
If i have an additional string in the group of CompareStrings As "HOW DID STUDENT DO TODAY"
So now i have the CompareStrings are
NSString *CompareString1 = @"HOW DID EMILY DO "
NSString *CompareSting = @"HOW DID YOUR FATHER"
NSString *CompareString2 = @"WHAT IS YOUR EMILY"
NSString *CompareString3 = @"THIS IS THE FAST DO ONE"
NSString *CompareString4 = @"THIS SEARCH EMILY EXAMPLE DO"
NSString *CompareString4 = @"HOW DID STUDENT DO TODAY"
From these 6 CompareStrings ,i need to get the string "HOW DID STUDENT DO TODAY" which is highest relative to the Original string (HOW DID STUDENT EMILY DO TODAY)
I have looked the NSPredicate "comparison and like" methods. However i didn't found any way to do the process
Any help on figuring out this concept is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自然语言解析是一个困难的话题,通过简单的字符串比较方法不太可能获得好的结果。我建议寻找一个在更高级别上运行的工具包。 Lion 和 iOS 5 通过 NSLinguisticTagger 类。
Natural language parsing is a difficult topic, and it's unlikely you'll get good results with a simple string comparison approach. I would suggest looking for a toolkit that operates at a higher level. Lion and iOS 5 include a small level of support for this with the NSLinguisticTagger class.
听起来像是计算机科学作业。虽然它非常草率和低效,但它会起作用。我确信这里有人有更好的想法来提高性能。
将要搜索的短语分解为单个单词的数组:
现在 myWords 是每个单词的数组(没有空格)。然后,构建一个查找每个单词的谓词:
完成后,您将得到一个
found
,您可以对每个不同的短语进行比较。最大的那个与最多的单词匹配。在这种情况下,您最终会像这样进行计数:
HOW DID STUDENT EMILY DO TODAY
Sounds like comp-sci homework. It's sloppy and inefficient as hell, but it will work. I'm sure somebody on here has a better idea to improve performance.
Break down your phrases that you want to search for into arrays of individual words:
Now myWords is an array of each word (no spaces). Then, build a predicate looking for each of the words:
When you are done, you'll end up with a
found
you can compare for each of the different phrases. The one that is greatest matched the most words.In this case, you'd end up counting like this:
HOW DID STUDENT EMILY DO TODAY