2

I believe this is an Apple bug, but wanted to run it by you all and see if anyone else had run into the same/similar issues.

Simply, Apple's UITextChecker finds all words 25 letters or more as valid, spelled correctly words. Go ahead and open up Notes on your iOS device (or TextEdit on OS X) and type in a random 24 letter word. Hit enter, underlined red, right? Now add one more letter to that line so it is a 25 letter word. Hit enter again, underline red, right ... nope!

I don't know if this is related, but I have a similar unanswered question out there (UITextChecker is what dictionary?) questioning what dictionary is used for UITextChecker. In /usr/share/dict/words the longest word is 24 letters. Seems rather coincidental that 25 letters would be the first length of word that is not in the dictionary and it is always accepted as a valid word. But I don't know if that word list is the dictionary for UITextChecker.

This is important to note for anyone that might be confirming the spelling of a given word for something like a game. You really don't want players to able to use a random 25 letters to spell a word and most likely score massive points.

Here's my code to check for valid words:

- (BOOL) isValidWord:(NSString*)word {
    // word is all lowercase
    UITextChecker *checker = [[UITextChecker alloc] init];
    NSRange searchRange = NSMakeRange(0, [word length]);

    NSRange misspelledRange = [checker rangeOfMisspelledWordInString:word range:searchRange startingAt:0 wrap:NO language:@"en" ];
    [checker release];
    BOOL validWord = (misspelledRange.location == NSNotFound);
    BOOL passOneCharTest = ([word length] > 1 || [word isEqualToString:@"a"] || [word isEqualToString:@"i"]);
    BOOL passLengthTest = ([word length] > 0 && [word length] < 25);    // I don't know any words more than 24 letters long

    return validWord && passOneCharTest && passLengthTest;
}

So my question to the community, is this a documented 'feature' that I just haven't been able to locate?

Community
  • 1
  • 1
Jason Pawlak
  • 792
  • 1
  • 6
  • 20

1 Answers1

3

This is likely to be caused by the algorithm used for spell-checking itself although I admit it sounds like a bit of a hole.

Even spell-checkers that use a dictionary often tend to use an algorithm to get rid of false negatives. The classic is to ignore:

  • (a) single-character words followed by certain punctuation (like that (a) back there); and
  • (b) words consisting of all uppercase like NATO or CHOGM, assuming that they're quite valid acronyms.

If the algorithm for UITextChecker also considers 25+-letter words to be okay, that's just one of the things you need to watch out for.

It may well be related to the expected use case. It may be expected to be used as not so much for a perfect checker, but more as a best-guess solution.

If you really want a perfect filter, you're probably better off doing your own, using a copy of the dictionary from somewhere. That way, you can exclude things that aren't valid in your game (acronyms in Scrabble®, for example).

You can also ensure you're not subject to the vagaries of algorithms that assume longer words are valid as appears to be the case here. Instead you could just assume any word not in your dictionary is invalid (but, of course, give the user the chance to add it if your dictionary is wrong).

Other than that, and filing a query/bug with Apple, there's probably not much else you can do.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • I know UITextChecker considers ALL CAPS words as valid. That seems like a good false negative to check for. The 25+ letters does not. But that's ok, just as long as people are aware of it. Thanks for your thoughts. – Jason Pawlak Nov 08 '11 at 18:42