Skip to content
spencer kelly edited this page Jan 14, 2017 · 28 revisions

CodacyBadge npm version downloads

compromise aims to make interpreting and manipulating written text as easy and straightforward as possible.

It also works under the constraint of being a single-file, immediate-use web-library, for cases appropriate for the accuracy and trade-offs of standard rule-based NLP.

As a javascript framework, it provides a set of natural language analysis and manipulation tools. It classify the words of a sentence into their parts of speech - whether they are names of companies, people, places, etc., normalize dates, times, and numeric quantities, and mark up the structure of sentences in terms of phrases and word dependencies.

Unlike most NLP programs that run on the server, compromise is small-enough to run in a website.

Significant Characteristics

  • Minimized library size is approximately the size of jQuery (~200KB)
  • 86% alignment with Penn Treebank Project

Development

We try to make development with NLP Compromise as simple as possible. The information below should help to get you started developing with the library and/or contributing to the project.

Technologies Used

  • Javascript
  • NodeJS
  • Babelify
  • Browserify
  • Tape
  • Tap-Spec

####Installing NodeJS We also use a number of node.js tools to initialize, test and build NLP-Compromise. You must have node.js and its package manager (npm) installed. You can get these tools from nodejs.org.

####Building NLP-Compromise Once you have set up your environment, just run:

npm run build

####Install with npm

$ npm install compromise

####Javascript Import

let nlp = require('nlp_compromise');

####See it in Action Once you have the project installed and referenced in a Javascript file, you can use the following code to see the project in action:

let nlp = require('compromise'); // or nlp = window.nlp

nlp('speak').verbs().conjugate();
// [{ past: 'spoke',
//   infinitive: 'speak',
//   gerund: 'speaking',
//   actor: 'speaker',
//   present: 'speaks',
//   future: 'will speak',
//   perfect: 'have spoken',
//   pluperfect: 'had spoken',
//   future_perfect: 'will have spoken'
// }]

nlp('She sells seashells').sentences().toNegative().out('text')
// 'She doesn't sell seashells'

nlp('I fed the dog').replace('the #Noun', 'the cat').out('text')
// 'I fed the cat'

nlp('Tony Hawk did a kickflip').people().data();
// [ Person { text: 'Tony Hawk' ..} ]

nlp('vacuum').nouns().article();
// 'a'

nlp('Tony Hawk').people().pronoun();
// ['he']

nlp('five hundred and sixty').values().toNumber();
// 560

var transcript = require('nlp-corpus').friends().random()
nlp(transcript).topics().out('freq')//11 seasons of friends
// [ { count: 2523, text: 'ross' },
//   { count: 1922, text: 'joey' },
//   { count: 1876, text: 'god' },
//   { count: 1411, text: 'rachel' },
//   ....

####Running tests To execute all unit tests, use:

npm run test

To execute client-side tests, use:

npm run testbrowser

####Deployment To deploy compromise, simply link to the project's CDN library

<script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>

####Continuous Integration

Travis CI

Travis CI is a continuous integration service, which can monitor GitHub for new commits to your repository and execute scripts such as building the app or running tests. The project contains a Travis configuration file, .travis.yml, which will cause Travis to run your tests when you push to GitHub.

You will need to enable the integration between Travis and GitHub. See the Travis website for more instruction on how to do this.

####Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

###Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

##Authors

See also the list of contributors who participated in this project.

##How you can help

Filing issues is helpful but pull requests that improve the code and the docs are even better! Not only do we welcome all contributions, but we will gladly work with you to incorporate commits and suggestions.

As for this wiki, feel free to edit it liberally as you wish. Join the slack group to bubble some ideas.

You can also email the benevolent dictator, spencer.

##License

Code licensed under an MIT License.

Documentation licensed under Creative Commons BY 4.0.