mortenjust/cleartext-mac

Find base form of word before looking up in simple list

Open

#56 opened on 2016年4月11日

GitHub で見る
 (0 comments) (1 reaction) (0 assignees)Swift (114 forks)github user discovery
help wanted

Repository metrics

Stars
 (3,254 stars)
PR merge metrics
 (PR metrics pending)

説明

The English list is currently more than 1,000 words to cover conjugations. But if we use NSLinguisticTagSchemeLemma, we can find the root word before we look it up in the word list.

I propose modifying the isSimple function in in the SimpleWords class, and adding a lemmaForWord(word:Stirng) function.

Here's an example to get you started

var question = "We were lovers"
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .JoinNames]
let schemes = NSLinguisticTagger.availableTagSchemesForLanguage("en")
let tagger = NSLinguisticTagger(tagSchemes: schemes, options: Int(options.rawValue))
tagger.string = question
tagger.enumerateTagsInRange(NSMakeRange(0, (question as NSString).length), scheme: NSLinguisticTagSchemeLemma, options: options) { (tag, tokenRange, _, _) in
    let token = (question as NSString).substringWithRange(tokenRange)
    print("\(token): \(tag)")
}

It returns

We: we
were: be
lovers: lover

Once this is in place, we can look into making the lists longer, and providing the user with the option of writing with the 1,000....10,000 most common words.

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSLinguisticTagger_Class/#//apple_ref/c/data/NSLinguisticTagSchemeLemma

コントリビューターガイド