function applyClassifierToTestCorpus(testCorpus, tagger, classifier) {
  var totalWords = 0;
  var correctyTaggedLexicon = 0;
  var correctlyTaggedMaxEnt = 0;

  testCorpus.sentences.forEach(function(sentence){
    // Put the words of the sentence in an array
    var s = sentence.taggedWords.map(function(token) {
      return token.token;
    });

    // Use the lexicon to tag the sentence
    var taggedSentence = tagger.tagWithLexicon(s);
    // Count the right tags
    sentence.taggedWords.forEach(function(token, i) {
      totalWords++;
      if (token.tag === taggedSentence.taggedWords[i].tag) {
        correctyTaggedLexicon++;
      }
    });

    // Classify tags using maxent
    taggedSentence.taggedWords.forEach(function(taggedWord, index) {

      // Create context for classication
      var context = new Context({
          wordWindow: {},
          tagWindow: {}
      });
      // And fill it:

      // Current wordWindow
      context.data.wordWindow["0"] = taggedWord.token;
      // Previous bigram
      if (index > 1) {
        context.data.tagWindow["-2"] = taggedSentence.taggedWords[index - 2].tag;
      }
      // Left bigram
      if (index > 0) {
        context.data.tagWindow["-1"] = taggedSentence.taggedWords[index - 1].tag;
      }
      // Right bigram
      if (index < sentence.length - 1) {
        context.data.tagWindow["1"] = taggedSentence.taggedWords[index + 1].tag;
      }
      // Next bigram
      if (index < sentence.length - 2) {
        context.data.tagWindow["2"] = taggedSentence.taggedWords[index + 2].tag;
      }
      // Left bigram words
      if (index > 0) {
        context.data.wordWindow["-1"] = taggedSentence.taggedWords[index - 1].token;
      }
      // Right bigram words
      if (index < sentence.length - 1) {
        context.data.wordWindow["1"] = taggedSentence.taggedWords[index + 1].token;
      }

      // Classify using maximum entropy model
      var tag = classifier.classify(context);

      if (tag === "") {
        tag = tagger.lexicon.tagWordWithDefaults(context.data.wordWindow["0"])
      }

      // Collect stats
      if (tag === sentence.taggedWords[index].tag) {
        // Correctly tagged
        correctlyTaggedMaxEnt++;
      }
      DEBUG && console.log("(word, classification, right tag): " + "(" + taggedWord[0] +
        ", " + tag + ", " + sentence.taggedWords[index].tag + ")");
    });
  });

  DEBUG && console.log("Number of words tagged: " + totalWords);
  DEBUG && console.log("Percentage correctly tagged lexicon: " + correctyTaggedLexicon/totalWords * 100 + "%");
  DEBUG && console.log("Percentage correctly tagged maxent:  " + correctlyTaggedMaxEnt/totalWords * 100 + "%");
}
// - A context consists of a window of words and a window of tags
A context consists of a window of words and a window of tags
A context consists of a window of words and a window of tags
function applyClassifierToTestCorpus(testCorpus, tagger, classifier) {
  var totalWords = 0;
  var correctyTaggedLexicon = 0;
  var correctlyTaggedMaxEnt = 0;
  testCorpus.sentences.forEach(function(sentence){
    var s = sentence.taggedWords.map(function(token) {
      return token.token;
    });
    var taggedSentence = tagger.tagWithLexicon(s);
    sentence.taggedWords.forEach(function(token, i) {
      totalWords++;
      if (token.tag === taggedSentence.taggedWords[i].tag) {
        correctyTaggedLexicon++;
      }
    });
    taggedSentence.taggedWords.forEach(function(taggedWord, index) {
      var context = new Context({
          wordWindow: {},
          tagWindow: {}
      });
      context.data.wordWindow["0"] = taggedWord.token;
      if (index > 1) {
        context.data.tagWindow["-2"] = taggedSentence.taggedWords[index - 2].tag;
      }
      if (index > 0) {
        context.data.tagWindow["-1"] = taggedSentence.taggedWords[index - 1].tag;
      }
      if (index < sentence.length - 1) {
        context.data.tagWindow["1"] = taggedSentence.taggedWords[index + 1].tag;
      }
      if (index < sentence.length - 2) {
        context.data.tagWindow["2"] = taggedSentence.taggedWords[index + 2].tag;
      }
       words
      if (index > 0) {
        context.data.wordWindow["-1"] = taggedSentence.taggedWords[index - 1].token;
      }
       words
      if (index < sentence.length - 1) {
        context.data.wordWindow["1"] = taggedSentence.taggedWords[index + 1].token;
      }
      var tag = classifier.classify(context);
      if (tag === "") {
        tag = tagger.lexicon.tagWordWithDefaults(context.data.wordWindow["0"])
      }
      if (tag === sentence.taggedWords[index].tag) {
        correctlyTaggedMaxEnt++;
      }
      DEBUG && console.log("(word, classification, right tag): " + "(" + taggedWord[0] +
        ", " + tag + ", " + sentence.taggedWords[index].tag + ")");
    });
  });
  DEBUG && console.log("Number of words tagged: " + totalWords);
  DEBUG && console.log("Percentage correctly tagged lexicon: " + correctyTaggedLexicon/totalWords * 100 + "%");
  DEBUG && console.log("Percentage correctly tagged maxent:  " + correctlyTaggedMaxEnt/totalWords * 100 + "%");
}
function applyClassifierToTestCorpus ( testCorpus , tagger , classifier ) { var totalWords = 0 ; var correctyTaggedLexicon = 0 ; var correctlyTaggedMaxEnt = 0 ; testCorpus . sentences . forEach ( function ( sentence ) { var s = sentence . taggedWords . map ( function ( token ) { return token . token ; } ) ; var taggedSentence = tagger . tagWithLexicon ( s ) ; sentence . taggedWords . forEach ( function ( token , i ) { totalWords ++ ; if ( token . tag === taggedSentence . taggedWords [ i ] . tag ) { correctyTaggedLexicon ++ ; } } ) ; taggedSentence . taggedWords . forEach ( function ( taggedWord , index ) { var context = new Context ( { wordWindow : { } , tagWindow : { } } ) ; context . data . wordWindow [ "0" ] = taggedWord . token ; if ( index > 1 ) { context . data . tagWindow [ "-2" ] = taggedSentence . taggedWords [ index - 2 ] . tag ; } if ( index > 0 ) { context . data . tagWindow [ "-1" ] = taggedSentence . taggedWords [ index - 1 ] . tag ; } if ( index < sentence . length - 1 ) { context . data . tagWindow [ "1" ] = taggedSentence . taggedWords [ index + 1 ] . tag ; } if ( index < sentence . length - 2 ) { context . data . tagWindow [ "2" ] = taggedSentence . taggedWords [ index + 2 ] . tag ; } if ( index > 0 ) { context . data . wordWindow [ "-1" ] = taggedSentence . taggedWords [ index - 1 ] . token ; } if ( index < sentence . length - 1 ) { context . data . wordWindow [ "1" ] = taggedSentence . taggedWords [ index + 1 ] . token ; } var tag = classifier . classify ( context ) ; if ( tag === "" ) { tag = tagger . lexicon . tagWordWithDefaults ( context . data . wordWindow [ "0" ] ) } if ( tag === sentence . taggedWords [ index ] . tag ) { correctlyTaggedMaxEnt ++ ; } DEBUG && console . log ( "(word, classification, right tag): " + "(" + taggedWord [ 0 ] + ", " + tag + ", " + sentence . taggedWords [ index ] . tag + ")" ) ; } ) ; } ) ; DEBUG && console . log ( "Number of words tagged: " + totalWords ) ; DEBUG && console . log ( "Percentage correctly tagged lexicon: " + correctyTaggedLexicon / totalWords * 100 + "%" ) ; DEBUG && console . log ( "Percentage correctly tagged maxent:  " + correctlyTaggedMaxEnt / totalWords * 100 + "%" ) ; }
A context consists of a window of words and a window of tags
A context consists of a window of words and a window of tags
// Put the words of the sentence in an array // Use the lexicon to tag the sentence // Count the right tags // Classify tags using maxent // Create context for classication // And fill it: // Current wordWindow // Previous bigram // Left bigram // Right bigram // Next bigram // Left bigram words // Right bigram words // Classify using maximum entropy model // Collect stats // Correctly tagged