• 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
  • text.js

  • ¶
    'use strict';
    const sentence_parser = require('./sentence_parser.js');
    const Sentence = require('../sentence/sentence.js');
    const Question = require('../sentence/question/question.js');
    const Statement = require('../sentence/statement/statement.js');
    const fns = require('../fns.js');
  • ¶

    a text object is a series of sentences, along with the generic methods for transforming them

    class Text {
      constructor(str) {
        const the = this;
        this.raw_text = str || '';
  • ¶

    build-up sentence/statement methods

        this.sentences = sentence_parser(str).map(function(s) {
          let last_char = s.slice(-1);
          if (last_char === '?') {
            return new Question(s);
          } else if (last_char === '.' || last_char === '!') {
            return new Statement(s);
          }
          return new Sentence(s);
        });
    
        this.contractions = {
  • ¶

    he’d -> he would

          expand: function() {
            return the.sentences.map(function(s) {
              return s.contractions.expand();
            });
          },
  • ¶

    he would -> he’d

          contract: function() {
            return the.sentences.map(function(s) {
              return s.contractions.contract();
            });
          }
        };
      }
  • ¶

    map over sentence methods

      text() {
        const arr = this.sentences.map(function(s) {
          return s.text();
        });
        return fns.flatten(arr).join(' ');
      }
      normalized() {
        const arr = this.sentences.map(function(s) {
          return s.normalized();
        });
        return fns.flatten(arr).join(' ');
      }
      terms() {
        const arr = this.sentences.map(function(s) {
          return s.terms;
        });
        return fns.flatten(arr);
      }
      normalised() {
        const arr = this.sentences.map(function(s) {
          return s.normalized();
        });
        return fns.flatten(arr).join(' ');
      }
      tags() {
        return this.sentences.map(function(s) {
          return s.tags();
        });
      }
      to_past() {
        return this.sentences.map(function(s) {
          return s.to_past();
        });
      }
      to_present() {
        return this.sentences.map(function(s) {
          return s.to_present();
        });
      }
      to_future() {
        return this.sentences.map(function(s) {
          return s.to_future();
        });
      }
      negate() {
        return this.sentences.map(function(s) {
          return s.negate();
        });
      }
  • ¶

    mining

      people() {
        let arr = [];
        for(let i = 0; i < this.sentences.length; i++) {
          arr = arr.concat(this.sentences[i].people());
        }
        return arr;
      }
      places() {
        let arr = [];
        for(let i = 0; i < this.sentences.length; i++) {
          arr = arr.concat(this.sentences[i].places());
        }
        return arr;
      }
      organisations() {
        let arr = [];
        for(let i = 0; i < this.sentences.length; i++) {
          arr = arr.concat(this.sentences[i].organisations());
        }
        return arr;
      }
      dates() {
        let arr = [];
        for(let i = 0; i < this.sentences.length; i++) {
          arr = arr.concat(this.sentences[i].dates());
        }
        return arr;
      }
      values() {
        let arr = [];
        for(let i = 0; i < this.sentences.length; i++) {
          arr = arr.concat(this.sentences[i].values());
        }
        return arr;
      }
    }
    Text.fn = Text.prototype;
    
    module.exports = Text;