Compromise: Guessing part of speech?

Created on 14 Jun 2016  路  3Comments  路  Source: spencermountain/compromise

I know context is required to accurately determine a word's part of speech, but does this library provide a way to guess (or pick the word's most common part of speech)?

Something like...

nlp.term('cheese').pos()
// => probably a noun

Most helpful comment

This library is basically "guessing" each word's part of speech based on it's spelling, and then makes minor adjustments depending on the context.

So,

nlp.sentence('cheese')

is an object that contains the following:

Sentence {
  str: 'cheese',
  terms: 
   [ Noun {
       whitespace: [Object],
       text: 'cheese',
       normal: 'cheese',
       expansion: null,
       reason: 'lexicon_pass',
       pos: [Object],
       tag: 'Noun' } ],
  contractions: { expand: [Function], contract: [Function] } }

As you see, tag: 'Noun'.

To extract part of speech for a single word, use:

nlp.sentence('cheese').terms[0].tag
// => 'Noun'

All 3 comments

This library is basically "guessing" each word's part of speech based on it's spelling, and then makes minor adjustments depending on the context.

So,

nlp.sentence('cheese')

is an object that contains the following:

Sentence {
  str: 'cheese',
  terms: 
   [ Noun {
       whitespace: [Object],
       text: 'cheese',
       normal: 'cheese',
       expansion: null,
       reason: 'lexicon_pass',
       pos: [Object],
       tag: 'Noun' } ],
  contractions: { expand: [Function], contract: [Function] } }

As you see, tag: 'Noun'.

To extract part of speech for a single word, use:

nlp.sentence('cheese').terms[0].tag
// => 'Noun'

exactly. The perfect tagger also should know the user's cultural setting too, like 'smashed' means drunk in america, but tired in britain...
so often the sentence/text is not even enough.

This library just tries to 80-20 rule the most-common pos, in an opinionated-but-fair way. If you know the context in advance, you can coerce certain words like this.
but like Ilya says,

nlp.sentence("the cheese").tags()
// Noun
nlp.sentence("he would cheese the bagel").tags()
// Verb

cheers

Good stuff. Thanks @ilyankou and @spencermountain

Was this page helpful?
0 / 5 - 0 ratings