• Jump To … +
    abbreviations.js adjectives.js convertables.js dates.js demonyms.js firstnames.js honourifics.js irregular_nouns.js irregular_verbs.js misc.js multiples.js numbers.js organisations.js phrasal_verbs.js places.js uncountables.js verbs.js fns.js index.js lexicon.js negate.js passive_voice.js contractions.js fancy_lumping.js grammar_rules.js parts_of_speech.js phrasal_verbs.js tagger.js word_rules.js question.js sentence.js statement.js tense.js adjective.js to_adverb.js to_comparative.js to_noun.js to_superlative.js adverb.js to_adjective.js is_acronym.js article.js date.js date_rules.js is_date.js parse_date.js is_plural.js is_uncountable.js noun.js is_organisation.js organisation.js gender.js is_person.js parse_name.js person.js is_place.js place.js pluralize.js pronoun.js singularize.js is_value.js numbers.js to_number.js units.js value.js term.js conjugate.js from_infinitive.js predict_form.js suffix_rules.js to_actor.js to_infinitive.js negate.js verb.js sentence_parser.js text.js
  • index.js

  • ¶
    'use strict';
    const fns = require('./fns.js');
    
    let models = {
      Term : require('./term/term.js'),
      Text : require('./text/text.js'),
      Sentence : require('./sentence/sentence.js'),
      Statement : require('./sentence/statement/statement.js'),
      Question : require('./sentence/question/question.js'),
      Verb : require('./term/verb/verb.js'),
      Adjective : require('./term/adjective/adjective.js'),
      Adverb : require('./term/adverb/adverb.js'),
      Noun : require('./term/noun/noun.js'),
      Value : require('./term/noun/value/value.js'),
      Person : require('./term/noun/person/person.js'),
      Place : require('./term/noun/place/place.js'),
      Date : require('./term/noun/date/date.js'),
      Organisation : require('./term/noun/organisation/organisation.js'),
      Lexicon : require('./lexicon.js')
    };
    
    
    function NLP() {
    
      this.plugin = function(obj) {
    
        obj = obj || {};
  • ¶

    Check if obj is a function If so, pass it an instance of the library, run it in current context and use the returned interface

        if (fns.isFunction(obj)) {
          obj = obj.call(this, this);
        }
    
        Object.keys(obj).forEach(function(k) {
          Object.keys(obj[k]).forEach(function(method) {
            models[k].fn[method] = obj[k][method];
          });
        });
      };
    
      this.term = function(s) {
        return new models.Term(s);
      };
      this.noun = function(s) {
        return new models.Noun(s);
      };
      this.verb = function(s) {
        return new models.Verb(s);
      };
      this.adjective = function(s) {
        return new models.Adjective(s);
      };
      this.adverb = function(s) {
        return new models.Adverb(s);
      };
    
      this.value = function(s) {
        return new models.Value(s);
      };
      this.person = function(s) {
        return new models.Person(s);
      };
      this.place = function(s) {
        return new models.Place(s);
      };
      this.date = function(s) {
        return new models.Date(s);
      };
      this.organisation = function(s) {
        return new models.Organisation(s);
      };
    
      this.text = function(s) {
        return new models.Text(s);
      };
      this.sentence = function(s) {
        return new models.Sentence(s);
      };
      this.statement = function(s) {
        return new models.Statement(s);
      };
      this.question = function(s) {
        return new models.Question(s);
      };
    }
    
    let nlp = new NLP();
  • ¶

    export to window or webworker

    if (typeof window === 'object' || typeof DedicatedWorkerGlobalScope === 'function') {
      self.nlp_compromise = nlp;
    }
  • ¶

    export to commonjs

    if (typeof module !== 'undefined' && module.exports) {
      module.exports = nlp;
    }
  • ¶

    export to amd

    if (typeof define === 'function' && define.amd) {
      define(nlp);
    }
  • ¶

    let text = nlp.sentence(‘He does not care’); console.log(text.tags()); console.log(text.to_present().text()); console.log(nlp.verb(‘watch’).conjugate());