@nlpjs/ner
Advanced tools
Comparing version 4.22.9 to 4.23.0
{ | ||
"name": "@nlpjs/ner", | ||
"version": "4.22.9", | ||
"version": "4.23.0", | ||
"description": "Named Entity Recognition", | ||
@@ -32,3 +32,3 @@ "author": { | ||
}, | ||
"gitHead": "d47263a3bc8fe5019f95c6d314b926102ed7da9a" | ||
"gitHead": "48292d4484037e39d70fa1fa541ddf3cbbb5461e" | ||
} |
@@ -60,11 +60,24 @@ /* | ||
if (match) { | ||
let matchIndex; | ||
let startIndex; | ||
let endIndex; | ||
if (condition && condition.options && condition.options.closest) { | ||
matchIndex = 1; | ||
const leftWordIndex = match[0].indexOf(match[matchIndex]); | ||
startIndex = match.index - 1 + leftWordIndex; | ||
endIndex = startIndex + match[matchIndex].length - 1; | ||
} else { | ||
matchIndex = 0; | ||
startIndex = match.index - 1; | ||
endIndex = condition.regex.lastIndex - 2; | ||
} | ||
result.push({ | ||
type: 'trim', | ||
subtype: TrimType.Between, | ||
start: match.index - 1, | ||
end: condition.regex.lastIndex - 2, | ||
len: match[0].length, | ||
start: startIndex, | ||
end: endIndex, | ||
len: match[matchIndex].length, | ||
accuracy: 1, | ||
sourceText: match[0], | ||
utteranceText: match[0], | ||
sourceText: match[matchIndex], | ||
utteranceText: match[matchIndex], | ||
entity: name, | ||
@@ -71,0 +84,0 @@ }); |
@@ -249,2 +249,10 @@ /* | ||
addBetweenLastCondition(locale, name, srcLeftWords, srcRightWords, srcOptions = {}) { | ||
const options = { | ||
...srcOptions, | ||
closest: true, | ||
}; | ||
this.addBetweenCondition(locale, name, srcLeftWords, srcRightWords, options); | ||
} | ||
addBetweenCondition(locale, name, srcLeftWords, srcRightWords, srcOptions) { | ||
@@ -265,3 +273,9 @@ const options = srcOptions || {}; | ||
options.noSpaces === true ? rightWords[j] : ` ${rightWords[j]} `; | ||
conditions.push(`(?<=${leftWord})(.*)(?=${rightWord})`); | ||
let regex; | ||
if (options.closest === true) { | ||
regex = `${leftWord}(?!.*${leftWord}.*)(.*)${rightWord}`; | ||
} else { | ||
regex = `(?<=${leftWord})(.*)(?=${rightWord})`; | ||
} | ||
conditions.push(regex); | ||
} | ||
@@ -268,0 +282,0 @@ } |
64693
1426