Package com.samir_ahmed.Iris

Source Code of com.samir_ahmed.Iris.PoSTagger

package com.samir_ahmed.Iris;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class PoSTagger implements Runnable{

  private boolean loaded;
  private MaxentTagger tagger;
  public PoSTagger(){
  }

  public String Tag(String Utterance) throws Exception{
    if(tagger == null || loaded ==false){
      throw new Exception("No Grammar Loaded Exception");
    }

    return tagger.tagString(Utterance);
  }

  public void run(){

    // Redirect the error Stream Temporarily ...
    try {
      PrintStream oldErr = System.err;
      PrintStream newErr = new PrintStream(new ByteArrayOutputStream());
      System.setErr(newErr);

      tagger = new MaxentTagger(System.getProperty("user.dir")+"/misc/left3words-wsj-0-18.tagger");
      //@SuppressWarnings("unchecked")
      System.setErr(oldErr);
      loaded = true;
    }
    catch (IOException e) {
      e.printStackTrace();
      loaded = false;
    }
    catch (ClassNotFoundException e) {
      e.printStackTrace();
      loaded = false;
    }

  }


}
TOP

Related Classes of com.samir_ahmed.Iris.PoSTagger

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.