Skip to content

Commit

Permalink
enhanced PoS tagging API, fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
kariminf committed Jan 1, 2023
1 parent d62e25d commit 2bbb60c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/_jslml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down
23 changes: 18 additions & 5 deletions src/syntax.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module syntax
*/

import JslNode from "_jslgraph.mjs"
import JslNode from "_jslgraph.mjs";

/**
* Syntactic functions such as PoS tagging, etc.
Expand Down Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 2bbb60c

Please sign in to comment.