Giter Club home page Giter Club logo

parsimmon's Introduction

Parsimmon

Build Status

Parsimmon is a wee linguistics toolkit for iOS written in Swift.

We currently support Swift 2.0. If you are looking for Objective-C, please use version 0.3.4 or earlier.

Toolkit

Currently available tools:

  • Tokenizer
  • Tagger
  • Lemmatizer
  • Naive Bayes Classifier
  • Decision Tree (alpha)

Installation

The easiest way to get started is to use CocoaPods version 0.36 or higher. Just add the following line to your Podfile:

pod 'Parsimmon', '~> 0.5.0'

Examples

To start using Parsimmon:

import Parsimmon

Tokenizer

let tokenizer = Tokenizer()
let tokens = tokenizer.tokenize("The quick brown fox jumps over the lazy dog")
print(tokens)
(
The,
quick,
brown,
fox,
jumps,
over,
the,
lazy,
dog
)

Tagger

let tagger = Tagger()
let taggedTokens = tagger.tagWordsInText("The quick brown fox jumps over the lazy dog")
print(taggedTokens)
(
"('The', Determiner)",
"('quick', Adjective)",
"('brown', Adjective)",
"('fox', Noun)",
"('jumps', Noun)",
"('over', Preposition)",
"('the', Determiner)",
"('lazy', Adjective)",
"('dog', Noun)"
)

Lemmatizer

let lemmatizer = Lemmatizer()
let lemmatizedTokens = lemmatizer.lemmatizeWordsInText("Diane, I'm holding in my hand a small box of chocolate bunnies.")
print(lemmatizedTokens)
(
diane,
i,
hold,
in,
my,
hand,
a,
small,
box,
of,
chocolate,
bunny
)

Naive Bayes Classifier

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?"

print("\(firstExample) => \(classifier.classify(firstExample))")
print("\(secondExample) => \(classifier.classify(secondExample))")
'use the eggs in the fridge.' => ham
'what does the fish say?' => spam

License

MIT

Contributing

We’d love to see your ideas for improving this library! The best way to contribute is by submitting a pull request. We’ll do our best to respond to your patch as soon as possible. You can also submit a new GitHub issue if you find bugs or have questions. :octocat:

Please make sure to follow our general coding style and add test coverage for new features!

parsimmon's People

Contributors

ayanonagon avatar ben-g avatar cananito avatar chocochipset avatar eneko avatar kylef avatar morganchen12 avatar rinatkhanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parsimmon's Issues

Parsimmon doesn't work

i'm using Parsimmon to develop my application, but Parsimmon doesn't work when i build my app in device - iphone 5s, iOS 9.3.1

Swift 3.0

Parsimmon doesn't work with Swift 3.0

Classifier is not working as expected

Even though I write the exat same sentence, classifier can't identify string's category.

let prepared = ["file is packed",
            "Data Prepared",
            "information Arranged",
            "Record Created",
            "Data received"]
        let inhouse = ["Data is waiting",
            "Received at some location",
            "Received by somebody",
            "Package arrived"]
        trainCategory(prepared, category: "prepared")
        trainCategory(inhouse, category: "inhouse")

 let category = classifier.classify("Data is waiting")
        println(category) // it prints prepared

  private func trainCategory(items:[String], category:String) {
        for item in items {
            classifier.trainWithText(item, category:category)
        }
    }

PS: In Swift, documentation uses different syntax. For example following comment

    /**
        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
    */

should be converted to

    /**
        Returns the tokens for the input text using the specified linguistic tagger options.

        :param: text Text to tokenize
        :param: options Linguistic tagger options
        :returns: The tokens
    */

For more information you may check http://nshipster.com/swift-documentation/

Saving the state of Naive Bayes Classifier

Let's say I have huge amount of sentences to train Naive Bayes Classifier. Instead of doing this training every time in the program, is it possible to do it once save and reuse/add more training data later on?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.