Compromise: custom lexicon key with multiple words only partially matching

Created on 13 Sep 2016  Â·  7Comments  Â·  Source: spencermountain/compromise

Is this normal behavior? I was hoping any custom lexicon key of mine would override anything else. Any suggestions around it if it's normal behavior?

let nlp = require('nlp_compromise');
let newLex = nlp.lexicon();
newLex['ser waymar royce'] = 'TARGETED_GUY';
console.log(nlp.sentence('Ser Waymar Royce asked cooly.', {lexicon: newLex}).terms);

is giving output

Noun {
    whitespace: { preceding: '', trailing: ' ' },
    text: 'Ser Waymar',
    normal: 'ser waymar',
    expansion: null,
    reasoning: [ 'fallback', 'capital_signal', 'chunked two-nouns' ],
    pos: { Noun: true },
    tag: 'Noun' },
  Person {
    whitespace: { preceding: '', trailing: ' ' },
    text: 'Royce',
    normal: 'royce',
    expansion: null,
    reasoning: [ 'capital_signal', 'lexicon_pass' ],
    pos: { Noun: true, Person: true, MalePerson: true },
    tag: 'MalePerson',
    honourific: null,
    firstName: 'Royce',
    middleName: '',
    lastName: null },
  Verb {
    whitespace: { preceding: '', trailing: ' ' },
    text: 'asked',
    normal: 'asked',
    expansion: null,
    reasoning: [ 'lexicon_pass' ],
    pos: { Verb: true, PastTense: true },
    tag: 'PastTense' },

etc...

bug

All 7 comments

hey brian, yuck. this seems like a bug for sure.
it looks like the term 'Royce' is tripping it up because it's already recognized as a first-name.
There may be some lumping/splitting rule it's colliding with, because of the first-name.
Definitely not what it's supposed to do..
I can look at doing a hotfix this week.
thanks

I'm not sure if this is classified as different or along the same lines as the one above, but it looks like the name 'will' is being classified as a PerfectTense conjugation.

Am I right in hoping that it should override 'will' in the verb sense with my custom lex definition?

let nlp = require('nlp_compromise');
let newLex = nlp.lexicon();
newLex['will'] = 'PERSON_CONFIRMED';
let res = nlp.text('Will went in front of the wagon.', {lexicon: newLex})
console.log(JSON.stringify(res, null, 4));

produces

{
    "raw_text": "Will went in front of the wagon.",
    "sentences": [
        {
            "str": "Will went in front of the wagon.",
            "terms": [
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "Will went",
                    "normal": "will went",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass",
                        "lexicon_pass",
                        "chunked will-verb"
                    ],
                    "pos": {
                        "Verb": true,
                        "PerfectTense": true
                    },
                    "tag": "PerfectTense"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "in front",
                    "normal": "in front",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass",
                        "multiples_pass_lexicon"
                    ],
                    "pos": {
                        "Adjective": true
                    },
                    "tag": "Adjective"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "of",
                    "normal": "of",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass"
                    ],
                    "pos": {
                        "Preposition": true
                    },
                    "tag": "Preposition"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "the",
                    "normal": "the",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass"
                    ],
                    "pos": {
                        "Determiner": true
                    },
                    "tag": "Determiner"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": ""
                    },
                    "text": "wagon.",
                    "normal": "wagon",
                    "expansion": null,
                    "reasoning": [
                        "fallback"
                    ],
                    "pos": {
                        "Noun": true
                    },
                    "tag": "Noun"
                }
            ],
            "contractions": {}
        }
    ],
    "contractions": {}
}

agh, this is a great, tough bug.
looks like 'will went' got lumped like 'will walk' would.
rats. I'll add this to the list.

Hey Spencer,

I'm not sure if I'm putting these in the right place, but I've also noticed that a custom key wont get a hit whether it is with the possessive or without on a custom key.

with this

let nlp = require('nlp_compromise');
let newLex = nlp.lexicon();
newLex['jory’s'] = 'PERSON_CONFIRMED_POSSESSIVE';
newLex['jory'] = 'PERSON_CONFIRMED';
let res = nlp.text('Jory’s sword was already out.', {lexicon: newLex})
console.log(JSON.stringify(res, null, 4));
{
    "raw_text": "Jory’s sword was already out.",
    "sentences": [
        {
            "str": "Jory’s sword was already out.",
            "terms": [
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "Jory’s",
                    "normal": "jory's",
                    "expansion": null,
                    "reasoning": [
                        "regex #75 Possessive",
                        "possessive_pass"
                    ],
                    "pos": {
                        "Noun": true,
                        "Plural": true,
                        "Possessive": true
                    },
                    "tag": "Noun"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "sword",
                    "normal": "sword",
                    "expansion": null,
                    "reasoning": [
                        "fallback"
                    ],
                    "pos": {
                        "Noun": true
                    },
                    "tag": "Noun"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "was",
                    "normal": "was",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass"
                    ],
                    "pos": {
                        "Verb": true,
                        "Copula": true
                    },
                    "tag": "Copula"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": " "
                    },
                    "text": "already",
                    "normal": "already",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass"
                    ],
                    "pos": {
                        "Adverb": true
                    },
                    "tag": "Adverb"
                },
                {
                    "whitespace": {
                        "preceding": "",
                        "trailing": ""
                    },
                    "text": "out.",
                    "normal": "out",
                    "expansion": null,
                    "reasoning": [
                        "lexicon_pass"
                    ],
                    "pos": {
                        "Preposition": true
                    },
                    "tag": "Preposition"
                }
            ],
            "contractions": {}
        }
    ],
    "contractions": {}
}

Also if I try to use 'jon' as a custom lexicon key, it doesn't override 'MalePerson' as the tag type, which personally I'd like it to do.

yeah, this is a mess. The custom lexicon is obviously a good idea, and something that should've been there from the beginning. Unfortunately I bolted it on the side as a second-class feature, and it gets washed-around through the tagging/lumping steps.

this works a lot better in v7, but it's still immature and unstable.
worst-case, if you need a gross hotfix, you could always loop around each term, and tag them 'in post':

nlp.text(gameofthrones).sentences.terms.forEach((t)=>{
  if(t.normal==='jory'){
    t.pos={Person:true}
  }
})

¯_(ツ)_/¯

Was this page helpful?
0 / 5 - 0 ratings