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

  • ¶
    'use strict';
    const Noun = require('../noun.js');
    const to_number = require('./to_number.js');
    const units = require('./units.js');
    const nums = require('./numbers.js');
    
    class Value extends Noun {
      constructor(str, tag) {
        super(str);
        this.tag = tag;
        this.pos['Value'] = true;
        this.number = null;
        this.unit = null;
        this.unit_name = null;
        this.measurement = null;
        this.parse();
      }
    
      is_unit(s) {
        if (units[s]) {
          return true;
        }
        s = s.toLowerCase();
        if (nums.prefixes[s]) {
          return true;
        }
  • ¶

    try singular version

        s = s.replace(/s$/); //ew
        if (units[s]) {
          return true;
        }
    
        return false;
      }
    
      parse() {
        let words = this.text.toLowerCase().split(' ');
        let number_words = {
          minus: true,
          point: true
        };
        let numbers = '';
        for(let i = 0; i < words.length; i++) {
          let w = words[i];
          if (nums.ones[w] || nums.teens[w] || nums.tens[w] || nums.multiples[w] || number_words[w] || w.match(/[0-9]/)) {
            numbers += ' ' + w;
          } else if (this.is_unit(w)) { //optional units come after the number
            this.unit = w;
            if (units[w]) {
              this.measurement = units[w].category;
              this.unit_name = units[w].name;
            }
          }
        }
        this.number = to_number(numbers);
      }
    
    }
    Value.fn = Value.prototype;
    
    module.exports = Value;