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

  • ¶
    'use strict';
  • ¶

    this method is used to predict which current conjugation a verb is

  • ¶

    this method is the slowest in the whole library,

    const fns = require('../../../fns.js');
    const suffix_rules = require('./suffix_rules');
    const irregular_verbs = require('../../../data/irregular_verbs');
    let known_verbs = Object.keys(irregular_verbs).reduce(function(h, k) {
      Object.keys(irregular_verbs[k]).forEach(function(k2) {
        h[irregular_verbs[k][k2]] = k2;
      });
      return h;
    }, {});
    
    const predict = function(w) {
  • ¶

    check if known infinitive

      if (irregular_verbs[w]) {
        return 'infinitive';
      }
  • ¶

    check if known infinitive

      if (known_verbs[w]) {
        return known_verbs[w];
      }
    
      if (w.match(/will ha(ve|d) [a-z]{2}/)) {
        return 'future_perfect';
      }
      if (w.match(/will [a-z]{2}/)) {
        return 'future';
      }
      if (w.match(/had [a-z]{2}/)) {
        return 'pluperfect';
      }
      if (w.match(/have [a-z]{2}/)) {
        return 'perfect';
      }
      if (w.match(/..erer$/)) {
        return 'actor';
      }
      if (w.match(/[^aeiou]ing$/)) {
        return 'gerund';
      }
    
      const arr = Object.keys(suffix_rules);
      for (let i = 0; i < arr.length; i++) {
        if (fns.endsWith(w, arr[i]) && arr[i].length < w.length) {
          return suffix_rules[arr[i]];
        }
      }
      return 'infinitive';
    };
    
    module.exports = predict;