On Jun 21, 2009, at 11:02 PM, Jerry Krinock wrote:

Given the numbers in your post, "3-5", "250" and "several", I'd say you should just split the phrase into words, write an outer loop for(words in phraseWords), an inner loop for(tag in tags), and inside it all compare using -isEqualToString, breaking when found. "Just do it."

I would suggest making an NSSet from the tags, and using - containsObject: rather than the inner loop. Not necessarily for speed, although it would probably be faster, but just because it's easier and simpler. Since the tags set isn't changing frequently, you can keep the set around persistently, updating it on the infrequent occasions that it's necessary. So, you don't need to build and tear down the set for each phrase matching operation.


Only thing that might require a little digging -- I believe that there is probably a "correct" way to split a phrase into a set or array of words which will work for non-Western languages. - [NSString componentsJoinedByString:@" "] would be a cheesy solution.

The other problem is doing the string matching in a sensible way. You probably don't want the usual test for equality which is a literal match. It's sensitive to case and to differences in precomposed/ decomposed characters, etc.

To do that with NSSet would require you to wrap your strings in a custom class which overrides -isEqual: and -hash:. That runs counter to the simplicity arguing for NSSet. It may end up, after all, that just enumerating the strings and using -compare:options: would be simpler.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to