Comparing version 1.1.1 to 1.1.2
@@ -352,3 +352,3 @@ "use strict"; | ||
delay: 0, | ||
direction: "->", | ||
direction: "<-", | ||
label: "DET" | ||
@@ -355,0 +355,0 @@ }, |
@@ -1,12 +0,8 @@ | ||
export interface NonUniqueInterface { | ||
0: string; | ||
1: Array<string>; | ||
2?: Function; | ||
export declare const single: { | ||
[key: string]: string; | ||
}; | ||
export interface MultipleRule { | ||
type: string; | ||
regex: RegExp; | ||
} | ||
export interface UniqueInterface { | ||
0: string; | ||
1: string; | ||
} | ||
export declare const preUnique: Array<NonUniqueInterface>; | ||
export declare const unique: Array<UniqueInterface>; | ||
export declare const postUnique: Array<NonUniqueInterface>; | ||
export declare const multiple: MultipleRule[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.preUnique = [ | ||
["NP", ['DT', 'PRP$', 'JJ', 'JJS', "JJR", '$', '$', 'NN', 'NNS']], | ||
["NP", ['DT', 'PRP$', 'JJ', 'JJS', "JJR", '$', '$', 'NNP', 'NNPS']], | ||
["NP", ['PDT', 'PRP$', 'JJ', 'JJS', "JJR", '$', '$', 'NN', 'NNS']], | ||
["NP", ['PDT', 'PRP$', 'JJ', 'JJS', "JJR", '$', '$', 'NNP', 'NNPS']], | ||
["NP", ['NNP', 'NNPS']], | ||
["ADV", ['RB', 'RB']], | ||
["ADJP", ['RB', 'JJ'], (L, R, i, n) => R.tags.length === 1], | ||
["UH", ["DT", ","], (L, R, i, n) => L.index[0] === 0 && R.index[1] === 1], | ||
["PP", ["DT", "IN"]], | ||
["UH", ["PDT", ","], (L, R, i, n) => L.index[0] === 0 && R.index[1] === 1], | ||
["PP", ["PDT", "IN"]], | ||
["UH", ["UH", ","]], | ||
["NP", ["NP", "POS", "NN"]], | ||
["PP", ["PP", "IN"]], | ||
["PP", ["IN", "IN"]], | ||
["CD", ["CD", "CC", "CD"]], | ||
exports.single = { | ||
".": "PUNCT", | ||
",": "PUNCT", | ||
":": "PUNCT", | ||
'"': "PUNCT", | ||
")": "PUNCT", | ||
"(": "PUNCT", | ||
"#": "PUNCT", | ||
"PRP": "NP", | ||
"PRP$": "NP", | ||
"NNP": "NP", | ||
"NNPS": "NP", | ||
"NN": "NP", | ||
"NNS": "NP", | ||
"$": "NP", | ||
"SYM": "NP", | ||
"FW": "NP", | ||
"PDT": "DT", | ||
"VBZ": "VP", | ||
"VBP": "VP", | ||
"VBD": "VP", | ||
"VBG": "VP", | ||
"JJ": "ADJ", | ||
"JJR": "ADJ", | ||
"JJS": "ADJ", | ||
"WRB": "ADV", | ||
"RB": "ADV", | ||
"RBR": "ADV", | ||
"RBS": "ADV", | ||
"IN": "PP", | ||
"RP": "PRT", | ||
"LS": "CD" | ||
}; | ||
; | ||
exports.multiple = [ | ||
{ | ||
type: "NP", | ||
regex: /((#DT-|#ADJ-)+|(#ADJ-|#NP-)+)#NP-/g, | ||
}, | ||
{ | ||
type: "ADV", | ||
regex: /((#ADV-){2,})/g, | ||
}, | ||
{ | ||
type: "ADJ", | ||
regex: /((#ADJ-){2,})/g, | ||
}, | ||
{ | ||
type: "ADJP", | ||
regex: /#ADV-#ADJ-/, | ||
}, | ||
{ | ||
type: "PP", | ||
regex: /#PP-#PP-/ | ||
}, | ||
{ | ||
type: "UH", | ||
regex: /($(#DT|#UH|#PDT)-(#PUNCT)-)/g, | ||
}, | ||
{ | ||
type: "PP", | ||
regex: /((#DT|#PDT|#PP|#IN)-(#IN)-)/g, | ||
}, | ||
{ | ||
type: "NP", | ||
regex: /#DT-/g, | ||
}, | ||
{ | ||
type: "NP", | ||
regex: /#NP-#POS-#NP-/, | ||
}, | ||
]; | ||
exports.unique = [ | ||
["PUNCT", '.'], | ||
["PUNCT", ','], | ||
["PUNCT", ':'], | ||
["PUNCT", '"'], | ||
["PUNCT", ')'], | ||
["PUNCT", '('], | ||
["PUNCT", '#'], | ||
["PP", 'IN'], | ||
["PRT", 'RP'], | ||
["CD", 'LS'], | ||
["NP", 'PRP'], | ||
["NP", 'PRP$'], | ||
["NP", 'NNP'], | ||
["NP", 'NNPS'], | ||
["NP", 'NN'], | ||
["NP", 'DT'], | ||
["NP", 'PDT'], | ||
["ADJ", 'JJ'], | ||
["ADJ", 'JJR'], | ||
["ADJ", 'JJS'], | ||
["NP", 'NNS'], | ||
["VP", 'VBZ'], | ||
["VP", 'VBP'], | ||
["VP", 'VBD'], | ||
["VP", 'VBG'], | ||
["ADV", 'WRB'], | ||
["ADV", 'RB'], | ||
["ADV", 'RBR'], | ||
["ADV", 'RBS'], | ||
["NP", "$"], | ||
["NP", "SYM"], | ||
["NP", "FW"], | ||
]; | ||
exports.postUnique = [ | ||
["SP", ['PP', 'NP']], | ||
["NP", ["NP", "NNP"]] | ||
]; |
import { NodeInterface } from "./index"; | ||
export default function (nodes: Array<NodeInterface>): Array<NodeInterface>; | ||
export default function (nodes: NodeInterface[]): NodeInterface[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const types = require("./rules/types"); | ||
const types_1 = require("./rules/types"); | ||
function default_1(nodes) { | ||
types.preUnique.forEach((typeRule) => { | ||
nodes = typer(typeRule[0], typeRule[1], typeRule[2], nodes); | ||
}); | ||
types.unique.forEach((typeRule) => { | ||
nodes = typer(typeRule[0], typeRule[1], undefined, nodes); | ||
}); | ||
types.postUnique.forEach((typeRule) => { | ||
nodes = typer(typeRule[0], typeRule[1], typeRule[2], nodes); | ||
}); | ||
nodes = singleTyping(nodes); | ||
nodes = multipleTyping(nodes); | ||
return nodes; | ||
@@ -18,23 +11,48 @@ } | ||
; | ||
const typer = function (typeId, typeTags, typeFunction, nodes) { | ||
var isUnique = typeof typeTags === 'string'; | ||
var l = nodes.length - (isUnique ? 1 : 2); | ||
for (l; l >= 0; l -= 1) { | ||
var leftNode = nodes[l]; | ||
if (!isUnique) { | ||
var rightNode = nodes[l + 1]; | ||
var left = typeTags.indexOf(leftNode.type); | ||
var right = typeTags.lastIndexOf(rightNode.tags[0]); | ||
if (left > -1 && right > -1 && left <= right && ((!typeFunction) || typeFunction(leftNode, rightNode, l, nodes))) { | ||
leftNode.type = typeId; | ||
leftNode.index[1] = rightNode.index[1]; | ||
leftNode.tags = leftNode.tags.concat(rightNode.tags); | ||
leftNode.tokens = leftNode.tokens.concat(rightNode.tokens); | ||
nodes.splice(l + 1, 1); | ||
function singleTyping(nodes) { | ||
for (var index = 0; index < nodes.length; index++) { | ||
let newType = types_1.single[nodes[index].type]; | ||
if (newType) | ||
nodes[index].type = newType; | ||
} | ||
return nodes; | ||
} | ||
function multipleTyping(nodes) { | ||
let nodesTypes = nodes.map(x => "#" + x.type).join("-") + "-"; | ||
console.log(nodesTypes); | ||
for (var index = 0; index < types_1.multiple.length; index++) { | ||
var rule = types_1.multiple[index]; | ||
let result; | ||
while (result = rule.regex.exec(nodesTypes)) { | ||
let match = result[0]; | ||
let startingIndex = result.index; | ||
let mostLeftIndex = getMostLeftIndex(nodesTypes, startingIndex); | ||
let mostRightIndex = getMostRightIndex(mostLeftIndex, match); | ||
let count = mostRightIndex - mostLeftIndex + 1; | ||
console.log(match, mostLeftIndex, mostRightIndex); | ||
nodes[mostLeftIndex].type = rule.type; | ||
const dyingNodes = []; | ||
for (let index = 0; index < nodes.length; index++) { | ||
let node = nodes[index]; | ||
if (index <= mostRightIndex && index > mostLeftIndex) | ||
dyingNodes.push({ index, node }); | ||
} | ||
for (var index = 0; index < dyingNodes.length; index++) { | ||
var dyingNode = dyingNodes[index]; | ||
nodes[mostLeftIndex].index[1] = dyingNode.node.index[1]; | ||
nodes[mostLeftIndex].tags = nodes[mostLeftIndex].tags.concat(dyingNode.node.tags); | ||
nodes[mostLeftIndex].tokens = nodes[mostLeftIndex].tokens.concat(dyingNode.node.tokens); | ||
} | ||
if (dyingNodes.length) | ||
nodes.splice(dyingNodes[0].index, dyingNodes.length); | ||
nodesTypes = nodes.map(x => "#" + x.type).join("-") + "-"; | ||
} | ||
else if (typeTags === leftNode.type) | ||
leftNode.type = typeId; | ||
} | ||
return nodes; | ||
}; | ||
} | ||
function getMostLeftIndex(original, startingIndex) { | ||
return original.substr(0, startingIndex).split("-").length - 1; | ||
} | ||
function getMostRightIndex(mostLeftIndex, match) { | ||
return mostLeftIndex + match.split("-").length - 2; | ||
} |
{ | ||
"name": "en-parse", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "English language syntactic dependency parser", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42487
1196