Capturing user input as a custom entity? #77
-
I have a use case where I'm trying to match custom entities that may include patterns like the following:
Right now I'm replacing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @timtutt The pattern const winkNLP = require( 'wink-nlp' );
const model = require( 'wink-eng-lite-web-model' );
const nlp = winkNLP( model );
const its = nlp.its;
const ANY = ' [|ADJ|ADP|ADV|ADV|AUX|CCONJ|DET|INTJ|NOUN|NUM|PART|PRON|PROPN|PUNCT|SCONJ|SYM|VERB|X]';
const patterns = [
{
name: 'multi-word-capture',
patterns: [
'[where] [state] [is] [equal] [to]' + ANY + ANY + ANY +ANY
]
}
];
// Such pattern will slow down the learning part
// but will not impact further processing i.e. the NLP Pipe so much!
nlp.learnCustomEntities( patterns, { useEntity: false } );
const text = 'Where state is equal to something very amazing. Or Where state is equal to 4 and not 6. And where State is equal to simple';
const doc = nlp.readDoc( text );
console.log( doc.customEntities().out( its.detail ) );
// —> [
// —> {value: "Where state is equal to something very amazing.", type: "multi-word-capture"},
// —> {value: "Where state is equal to 4 and not 6", type: "multi-word-capture"},
// —> {value: "where State is equal to simple", type: "multi-word-capture"}
// —> ] Note: The However if you need to capture a larger number of such tokens then you need to code, where you capture until the end of the sentence or text after the occurrence of the pattern — should be simple with winkNLP's API. Best, |
Beta Was this translation helpful? Give feedback.
Hello @timtutt
The pattern
[|ADJ|ADP|ADV|ADV|AUX|CCONJ|DET|INTJ|NOUN|NUM|PART|PRON|PROPN|PUNCT|SCONJ|SYM|VERB|X]
will detect a single token of any PoS and not multiple instances. Currently winkNLP does not support wildcard match. Therefore one way to achieve is to use the following pattern, provided you are only looking to capture only upto a few tokens — say 3 or 4: