Parsimmon 是一个用 Swift 编写的 iOS 语言工具包。
我们目前支持 Swift 1.2。如果您在寻找 Objective-C,请使用 0.3.4 或更早的版本。
当前可用的工具
开始使用的最简单方法是使用 CocoaPods 0.36 或更高版本。只需将以下行添加到 Podfile 中
pod 'Parsimmon', '~> 0.4.0'
要开始使用 Parsimmon
import Parsimmon
let tokenizer = Tokenizer()
let tokens = tokenizer.tokenize("The quick brown fox jumps over the lazy dog")
println(tokens)
(
The,
quick,
brown,
fox,
jumps,
over,
the,
lazy,
dog
)
let tagger = Tagger()
let taggedTokens = tagger.tagWordsInText("The quick brown fox jumps over the lazy dog")
println(taggedTokens)
(
"('The', Determiner)",
"('quick', Adjective)",
"('brown', Adjective)",
"('fox', Noun)",
"('jumps', Noun)",
"('over', Preposition)",
"('the', Determiner)",
"('lazy', Adjective)",
"('dog', Noun)"
)
let lemmatizer = Lemmatizer()
let lemmatizedTokens = lemmatizer.lemmatizeWordsInText("Diane, I'm holding in my hand a small box of chocolate bunnies.")
println(lemmatizedTokens)
(
diane,
i,
hold,
in,
my,
hand,
a,
small,
box,
of,
chocolate,
bunny
)
let classifier = NaiveBayesClassifier()
// Train the classifier with some ham examples.
classifier.trainWithText("nom nom ham", category: "ham")
classifier.trainWithText("make sure to get the ham", category: "ham")
classifier.trainWithText("please put the eggs in the fridge", category: "ham")
// Train the classifier with some spam examples.
classifier.trainWithText("spammy spam spam", category: "spam")
classifier.trainWithText("what does the fox say?", category: "spam")
classifier.trainWithText("and fish go blub", category: "spam")
// Classify some new text. Is it ham or spam?
// In practice, you'd want to train with more examples first.
let firstExample = "use the eggs in the fridge."
let secondExample = "what does the fish say?"
println("\(firstExample) => \(classifier.classify(firstExample))")
println("\(secondExample) => \(classifier.classify(secondExample))")
'use the eggs in the fridge.' => ham
'what does the fish say?' => spam
MIT
我们期待看到您对这个库改进的想法!最好的贡献方法是提交一个拉取请求。我们将尽最大努力尽快回应您的补丁。如果您发现错误或有疑问,也可以提交 新的 GitHub 问题
请确保遵循我们的通用编码风格并为新功能添加测试覆盖率!