package iitb.cfilt.cpost.ma;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;
import iitb.cfilt.cpost.newstemmer.*;

public class MorphologicallyAnalyzedToken {

	private StemmedToken stemmedToken;
	private Vector<MorphologicalAnalyzerRuleResult> morphologicalAnalyzerOutputs;
	boolean isTagFixed;
	private HashSet<String> Flags;
	private Integer AS;
	private int lwflag = 0;
	public MorphologicallyAnalyzedToken(StemmedToken stemmedToken, Vector<MorphologicalAnalyzerRuleResult> morphologicalAnalyzerOutputs) {
		super();
		this.stemmedToken = stemmedToken;
		this.morphologicalAnalyzerOutputs = morphologicalAnalyzerOutputs;
		this.isTagFixed = false;
	}
	public MorphologicallyAnalyzedToken(StemmedToken stemmedToken) {
		super();
		this.stemmedToken = stemmedToken;
		this.isTagFixed = false;
		morphologicalAnalyzerOutputs = new Vector<MorphologicalAnalyzerRuleResult>();
	}
	
	public void setLWFlag(int f)
	{
		lwflag = f;
	}
	
	public int getLWFlag()
	{
		return(lwflag);
	}
	
	public void setAS(Integer asID){
		AS=new Integer(asID);
	}
	public Integer getAS(){
		return AS;
	}
	public void setFlags(HashSet flgs){
		Flags= flgs;
	}
	public HashSet getFlags() {
		return Flags;
	}
	public boolean isTagFixed(){
		return this.isTagFixed;
	}
	
	public String getToken(){
		return stemmedToken.getToken();
	}
	
	public Vector<StemmerRuleResult> getStemmedOutputs(){
		return stemmedToken.getStemmedOutputs();
	}
	
	public Vector<MorphologicalAnalyzerRuleResult> getMorphologicalAnalyzerOutputs(){
		return this.morphologicalAnalyzerOutputs;
	}
	
	public boolean addMorphologicalAnalyzerOutput(MorphologicalAnalyzerRuleResult marr){
		StemmerRuleResult srrtemp = new StemmerRuleResult(this.stemmedToken.getToken(),marr.getParadigm(),marr.getCategory(),marr.getUltimateDeletion(),marr.getSuffixList());
		this.stemmedToken.addStemmerOutput(srrtemp);
		return this.morphologicalAnalyzerOutputs.add(marr);
	}
	
	public boolean addAllMorphologicalAnalyzerOutputs(Vector<MorphologicalAnalyzerRuleResult> marrv){
		return this.morphologicalAnalyzerOutputs.addAll(marrv);
	}

	public String getCategoryString() {
		String retVal = "";
		HashSet<String> retSet = new HashSet<String>();
		for(int i = 0; i < morphologicalAnalyzerOutputs.size(); i++){
			retSet.add(morphologicalAnalyzerOutputs.get(i).getCategory());
		}
		Iterator retSetIter = retSet.iterator();
		while(retSetIter.hasNext()){
			String currentCategory = (String) retSetIter.next();
			retVal += currentCategory + "*";
		}
		return retVal;
	}

	public void resetMorphologicalAnalyzerOutputs(){
		this.stemmedToken.resetStemmedOutputs();
		this.morphologicalAnalyzerOutputs = new Vector<MorphologicalAnalyzerRuleResult>();
	}

	public void fixTag() {
		isTagFixed = true;
//		System.out.println("Tag fixed for Token : " + this.getToken());
	}
	
	public String getAmbiguityScheme(){
		return stemmedToken.getAmbiguityScheme();
	}
}