fin-urls
Version:
detecting URLs emails and IPs for Fin NLP
42 lines (41 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const anchorme_1 = require("anchorme");
const Fin = require("finnlp");
let links = [];
Fin.preProcessors.push(function (string) {
anchorme_1.default(string, { list: true })
.forEach((match, index) => {
links[index] = match.raw;
string = string.split(match.raw).join("DetectedLINK" + index);
});
return string;
});
Fin.postProcessors.push(function (processingResult) {
processingResult.sentences.forEach((sentence, sentenceIndex) => {
sentence.tokens.forEach((token, tokenIndex) => {
if (/^(DetectedLINK)(\d)+$/.test(token)) {
let linkIndex = parseInt(token.replace(/^DetectedLINK/, ""));
processingResult.sentences[sentenceIndex].tokens[tokenIndex] = links[linkIndex];
}
});
});
return processingResult;
});
Fin.Run.prototype.links = function () {
const result = [];
this.sentences.forEach((sentence, sentenceIndex) => {
result[sentenceIndex] = sentence.tokens
.map((token) => {
const result = anchorme_1.default(token, { list: true });
if (!result.length)
return false;
else
return {
type: result[0].reason,
token: result[0].raw
};
});
});
return result;
};