Re: Approaches for this Matching Problem?
Re: Approaches for this Matching Problem?
- Subject: Re: Approaches for this Matching Problem?
- From: Ken Thomases <email@hidden>
- Date: Sun, 21 Jun 2009 23:35:17 -0500
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 (email@hidden)
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:
This email sent to email@hidden