import SrlJsonFormat from "./SrlJsonFormat"; const unifiedLabels = { WHAT: 'did-what', WHO: 'who', WHOM: 'to-whom', FOR_WHOM: 'for-whom', WHEN: 'when', WHERE: 'where', WHY: 'why', HOW: 'how', FROM: 'from', TO: 'to', NOT: 'not', }; const stringMap: Map = new Map([ ['TARGET', unifiedLabels.WHAT], ['PRED', unifiedLabels.WHAT], ['V', unifiedLabels.WHAT], ['ARG0', unifiedLabels.WHO], ['A0', unifiedLabels.WHO], ['ARG1', unifiedLabels.WHOM], ['A1', unifiedLabels.WHOM], ['ARG2', unifiedLabels.FOR_WHOM], ['A2', unifiedLabels.FOR_WHOM], ['ARG3', unifiedLabels.FROM], ['A3', unifiedLabels.FROM], ['ARG4', unifiedLabels.TO], ['A4', unifiedLabels.TO], ['ARGM-NEG', unifiedLabels.NOT], ['AM-NEG', unifiedLabels.NOT], ['ARGM-LOC', unifiedLabels.WHERE], ['AM-LOC', unifiedLabels.WHERE], ['ARGM-TMP', unifiedLabels.WHEN], ['AM-TMP', unifiedLabels.WHEN], ['ARGM-PRP', unifiedLabels.WHY], ['AM-PRP', unifiedLabels.WHY], ]); function unifyString(str: string): string { const ret = stringMap.get(str); if(ret != null) return ret; for(const key in unifiedLabels) { if(!unifiedLabels.hasOwnProperty(key)) continue; const guardedKey = key as keyof typeof unifiedLabels; if(unifiedLabels[guardedKey] === str) return str; } return unifiedLabels.HOW; } function unifyAllStringInJson(srl: SrlJsonFormat): SrlJsonFormat { const nodes = srl.nodes.map(node => <[number, number, string]>[node[0], node[1], unifyString(node[2])]); return new SrlJsonFormat(srl.tokens, nodes, srl.edges, srl.meta); } export default unifyAllStringInJson; export {unifiedLabels};