Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanonagon committed Apr 8, 2015
1 parent ea73191 commit e75dcb1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
12 changes: 10 additions & 2 deletions Parsimmon/DecisionTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Parsimmon/Lemmatizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
30 changes: 17 additions & 13 deletions Parsimmon/NaiveBayesClassifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,22 @@ 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)
trainWithTokens(tokens, category: category)
}

/**
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)
Expand All @@ -100,19 +102,21 @@ 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)
return classifyTokens(tokens)
}

/**
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)))]
Expand Down
7 changes: 7 additions & 0 deletions Parsimmon/Tagger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Parsimmon/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down

0 comments on commit e75dcb1

Please sign in to comment.