diff --git a/Parsimmon/DecisionTree.swift b/Parsimmon/DecisionTree.swift index 89e639f..8cb9513 100644 --- a/Parsimmon/DecisionTree.swift +++ b/Parsimmon/DecisionTree.swift @@ -61,11 +61,19 @@ public class DecisionTree { self.featureNames = featureNames self.classificationNames = classificationNames } - + + /** + Adds a data point to the decision tree. + + @param datum A data point + */ public func addSample(datum: Datum) { self.data.append(datum) } - + + /** + Builds the decision tree based on the data it has. + */ public func build() { let features = [ Bit.Zero, Bit.One ] self.root = self.decisionTree(self.data, remainingFeatures: features, maxDepth: self.maxDepth) diff --git a/Parsimmon/Lemmatizer.swift b/Parsimmon/Lemmatizer.swift index b33f488..592f271 100644 --- a/Parsimmon/Lemmatizer.swift +++ b/Parsimmon/Lemmatizer.swift @@ -33,6 +33,13 @@ public struct Lemmatizer: Analyzer { self.seed = seed } + /** + Returns the lemmatized tokens for the input text using the specified linguistic tagger options. + + @param text Text to lemmatized + @param options Linguistic tagger options + @return The lemmatized tokens + */ public func lemmatizeWordsInText(text: String, options: NSLinguisticTaggerOptions? = nil) -> [String] { return analyze(self, text, options).map { (token, lemma) in lemma } } diff --git a/Parsimmon/NaiveBayesClassifier.swift b/Parsimmon/NaiveBayesClassifier.swift index 8bd9b11..8f0a8a1 100644 --- a/Parsimmon/NaiveBayesClassifier.swift +++ b/Parsimmon/NaiveBayesClassifier.swift @@ -73,9 +73,10 @@ public class NaiveBayesClassifier { // MARK: - Training /** - Trains the classifier with text and its category. - @param text The text - @param category The category of the text + Trains the classifier with text and its category. + + @param text The text + @param category The category of the text */ public func trainWithText(text: String, category: Category) { let tokens = tokenizer.tokenize(text) @@ -83,10 +84,11 @@ public class NaiveBayesClassifier { } /** - Trains the classifier with tokenized text and its category. - This is useful if you wish to use your own tokenization method. - @param tokens The tokenized text - @param category The category of the text + Trains the classifier with tokenized text and its category. + This is useful if you wish to use your own tokenization method. + + @param tokens The tokenized text + @param category The category of the text */ public func trainWithTokens(tokens: [Word], category: Category) { let words = Set(tokens) @@ -100,9 +102,10 @@ public class NaiveBayesClassifier { // MARK: - Classifying /** - Classifies the given text based on its training data. - @param text The text to classify - @return The category classification + Classifies the given text based on its training data. + + @param text The text to classify + @return The category classification */ public func classify(text: String) -> Category? { let tokens = tokenizer.tokenize(text) @@ -110,9 +113,10 @@ public class NaiveBayesClassifier { } /** - Classifies the given tokenized text based on its training data. - @param text The tokenized text to classify - @return The category classification if one was found, or nil if one wasn’t + Classifies the given tokenized text based on its training data. + + @param text The tokenized text to classify + @return The category classification if one was found, or nil if one wasn’t */ public func classifyTokens(tokens: [Word]) -> Category? { // Compute argmax_cat [log(P(C=cat)) + sum_token(log(P(W=token|C=cat)))] diff --git a/Parsimmon/Tagger.swift b/Parsimmon/Tagger.swift index 6be2a06..b841788 100644 --- a/Parsimmon/Tagger.swift +++ b/Parsimmon/Tagger.swift @@ -33,6 +33,13 @@ public struct Tagger: Analyzer { self.seed = seed } + /** + Returns the tagged tokens for the input text using the specified linguistic tagger options. + + @param text Text to tag + @param options Linguistic tagger options + @return The tagged tokens + */ public func tagWordsInText(text: String, options: NSLinguisticTaggerOptions? = nil) -> [TaggedToken] { return analyze(self, text, options).map { (token, tag) in TaggedToken(token: token, tag: tag) diff --git a/Parsimmon/Tokenizer.swift b/Parsimmon/Tokenizer.swift index 0868d0e..58ff12d 100644 --- a/Parsimmon/Tokenizer.swift +++ b/Parsimmon/Tokenizer.swift @@ -33,6 +33,13 @@ public struct Tokenizer: Analyzer { self.seed = seed } + /** + Returns the tokens for the input text using the specified linguistic tagger options. + @param text Text to tokenize + @param options Linguistic tagger options + + @return The tokens + */ public func tokenize(text: String, options: NSLinguisticTaggerOptions? = nil) -> [String] { return analyze(self, text, options).map { (token, tag) in token } }