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

  • ¶
    'use strict';
    const abbreviations = require('../../../data/abbreviations');
    const org_data = require('../../../data/organisations');
  • ¶

    words like ‘co’ and ltd

    let org_suffix = abbreviations.orgs.reduce(function(h, s) {
      h[s] = true;
      return h;
    }, {});
    org_data.suffixes.forEach(function(s) { //a few more
      org_suffix[s] = true;
    });
  • ¶

    named orgs like google and nestle

    let org_names = org_data.organisations.reduce(function(h, s) {
      h[s] = true;
      return h;
    }, {});
    
    const is_organisation = function(str, text) {
      text = text || '';
  • ¶

    some known organisations, like microsoft

      if (org_names[str]) {
        return true;
      }
  • ¶

    no period acronyms

      if (text.length <= 5 && text.match(/^[A-Z][A-Z]+$/) !== null) {
        return true;
      }
  • ¶

    period acronyms

      if (text.length >= 4 && text.match(/^([A-Z]\.)*$/) !== null) {
        return true;
      }
  • ¶

    eg ‘Smith & Co’

      if (str.match(/ & /)) {
        return true;
      }
  • ¶

    Girlscouts of Canada

      if (str.match(/..s of /)) {
        return true;
      }
  • ¶

    eg pets.com

      if (str.match(/[a-z]{3}\.(com|net|org|biz)/)) { //not a perfect url regex, but a "org.com"
        return true;
      }
      let words = str.split(' ');
      let last = words[words.length - 1];
      if (org_suffix[last]) {
        return true;
      }
    
      return false;
    };
    
    module.exports = is_organisation;
  • ¶

    console.log(is_organisation(‘Captain of Jamaica’));