Ho appena iniziato a giocare con NSLinguisticTagger
basando il mio codice su questo blog: NSLinguisticTagger @ NSHipster.comObjective-C: NSLinguisticTagger "New York" vs "New York"
NSLinguisticTaggerOptions options = NSLinguisticTaggerOmitWhitespace | NSLinguisticTaggerOmitPunctuation | NSLinguisticTaggerJoinNames;
NSLinguisticTagger *tagger = [[NSLinguisticTagger alloc] initWithTagSchemes: [NSLinguisticTagger availableTagSchemesForLanguage:@"en"] options:options];
tagger.string = question;
[tagger enumerateTagsInRange:NSMakeRange(0, [question length]) scheme:NSLinguisticTagSchemeNameTypeOrLexicalClass options:options usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop) {
NSString *token = [question substringWithRange:tokenRange];
NSLog(@"%@: %@", token, tag); }];
Quando eseguo questo con question = @"Weekend in New York"
, "New York"
ottiene etichettato come PlaceName
che è fantastico. Ma quando eseguo questo con question = @"Weekend in new york"
, "new"
viene taggato come "Adjective"
e "york"
viene contrassegnato come PlaceName
. C'è un modo per aggirare questo in modo tale che "New York"
e "new york"
vengono entrambi etichettati come PlaceName
?
Sono assolutamente nuovo a questa cosa della linguistica.
"Weekend a New York" e "Weekend a New York" in realtà ha 2 significati diversi (York è anche una città). Il Tagger sceglie quello che pensa sia giusto quando usa "Weekend in new york". Probabilmente la soluzione migliore è correggere l'ortografia, se possibile. – Daniel
questo non è possibile, da un punto di vista grammaticale "new york" e "New York" sono completamente diversi – tkanzakic
C'è un modo per applicare retroattivamente il commento automatico a una stringa? Ad esempio, se digito "week end a new york" su un dispositivo, verrà automaticamente eseguita la correzione in "Weekend a New York" quando toccherò la barra spaziatrice dopo "york". –