From 2bbb60c56f0d527d5840116f008d886f4c83344f Mon Sep 17 00:00:00 2001 From: kariminf Date: Sun, 1 Jan 2023 20:13:23 +0100 Subject: [PATCH] enhanced PoS tagging API, fixes #60 --- src/_jslml.mjs | 2 +- src/syntax.mjs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/_jslml.mjs b/src/_jslml.mjs index 8d2f6b6..47e4aa2 100644 --- a/src/_jslml.mjs +++ b/src/_jslml.mjs @@ -136,7 +136,7 @@ class BeamMEMM { let j = 0; //since the first one is the max while(i > 0){ next_e = this.BV[i][j]; - result.push(this.maxent.get_class(next_e[0][0])); + result.unshift(this.maxent.get_class(next_e[0][0])); j = next_e[0][1]; i--; } diff --git a/src/syntax.mjs b/src/syntax.mjs index 68d19e7..ce3f403 100644 --- a/src/syntax.mjs +++ b/src/syntax.mjs @@ -3,7 +3,7 @@ * @module syntax */ - import JslNode from "_jslgraph.mjs" + import JslNode from "_jslgraph.mjs"; /** * Syntactic functions such as PoS tagging, etc. @@ -101,21 +101,30 @@ class Syntax { dep: "unspecified dependency" }; + //========================================== + // VARIABLES + //========================================== + + //These static members must be overriden in extended classes; + //otherwise, the class won't function properly + static memm = null; + //========================================== // PROTECTED FUNCTIONS //========================================== /** - * Tagging a list of words + * Encoding a word * * @protected * @final * @static + * @param {int} i current position * @param {String[]} sentence list of words in sentence - * @return {String[]} list of tags of these words + * @return {float[]} encoding of the current word */ - static _pos_tag(sentence){ + static _word_encode(i, sentence){ return []; } @@ -161,7 +170,11 @@ class Syntax { * @return {String[]} list of tags of these words */ static pos_tag(sentence){ - return this._pos_tag(sentence); + this.memm.init(this._word_encode(0, sentence)); + for(let i = 1; i < sentence.length; i++){ + this.memm.step(this._word_encode(i, sentence)); + } + return this.memm.final(); } /**