package iitb.cfilt.cpost.ma;

//import java.util.HashMap;
import java.util.HashMap;
//import java.util.Iterator;
import java.util.LinkedList;
//import java.util.regex.Pattern;

import iitb.cfilt.cpost.newstemmer.*;

public class MorphologicalAnalyzerRuleResult extends StemmerRuleResult {
	//private HashMap features;
	private String analysis;
	private HashMap<String, String> features;

	public MorphologicalAnalyzerRuleResult(String root, String paradigm, String ultimateDeletion, LinkedList<String> suffixList) {
		super(root, paradigm, ultimateDeletion, suffixList);
		features = new HashMap<String, String>();
	}

	public MorphologicalAnalyzerRuleResult(String root, String paradigm, String category, String ultimateDeletion, LinkedList<String> suffixList) {
		super(root, paradigm, category, ultimateDeletion, suffixList);
		features = new HashMap<String, String>();
	}

	public MorphologicalAnalyzerRuleResult(StemmerRuleResult srresult){
		super(srresult.getRoot(), srresult.getParadigm(), srresult.getCategory(), srresult.getUltimateDeletion(), srresult.getSuffixList());
		features = new HashMap<String, String>();
	}
	public MorphologicalAnalyzerRuleResult(StemmerRuleResult srresult,String analysis){
		super(srresult.getRoot(), srresult.getParadigm(), srresult.getCategory(), srresult.getUltimateDeletion(), srresult.getSuffixList());
		features = new HashMap<String, String>();
		setAnalysis(analysis);
	}

	public MorphologicalAnalyzerRuleResult(String root, String paradigm, String category, String ultimateDeletion, LinkedList<String> suffixList,String analysis) {
		super(root, paradigm, category, ultimateDeletion, suffixList);
		features = new HashMap<String, String>();
		this.analysis=analysis;
		String[] fets = analysis.split(",");
		for (int i=0 ;i<fets.length;i++){
			String[] fet = fets[i].split(":");
			features.put(fet[0],fet[1]);
		}

	}
	public void setProperties(String root, String paradigm, String category, String ultimateDeletion, LinkedList<String> suffixList,String analysis) {
		//	super(root, paradigm, category, ultimateDeletion, suffixList);
		this.setRoot(root);
		this.setCategory(category);
		this.setParadigm(paradigm);
		this.setSuffixList(suffixList);
		this.analysis=analysis;
		if(analysis!=""){
			String[] fets = analysis.split(",");
			for (int i=0 ;i<fets.length;i++){
				String[] fet = fets[i].split(":");
				features.put(fet[0],fet[1]);
			}
		}

	}
	public void setAnalysis(String analysis){
		if(analysis!=""){
			this.analysis=analysis;
			String[] fets = analysis.split(",");
			for (int i=0 ;i<fets.length;i++){
				String[] fet = fets[i].split(":");
				features.put(fet[0],fet[1]);
			}
		}
	}
	public void setFeature(String key,String value){
		features.put(key,value);
	}
	public String getAnalysisString(){
		return analysis;
	}
	public HashMap getAnalysis(){

		return features;
	}
	public String getFeature(String featureKey){
		if (features.containsKey(featureKey)){
		return features.get(featureKey);
		}else{
			return null;
		}
	}
	/*
	public MorphologicalAnalyzerRuleResult(String root, String paradigm, String ultimateDeletion, LinkedList<String> suffixList, HashMap<String, String> features) {
		super(root, paradigm, ultimateDeletion, suffixList);
		this.features = features;
	}
	 */
	public String toString(){
		String retVal = null;
		retVal = "Root : " + this.getRoot() + " Paradigm : " + this.getParadigm() + " Category : " + this.getCategory() +" Analysis : "+this.getAnalysis()+" }";
		retVal = retVal.substring(0, retVal.length() - 1);
		return retVal;
	}
	
	public String getSuffixType()
	{
		String suffixType = "";
		
		if(this.getCategory().trim().startsWith("verb"))
		{
			String analysis;
			if(this.getAnalysisString() != null)
				analysis = this.getAnalysisString().trim();
			else
				analysis = "";
			if(analysis != null && analysis.contains("Type:"))
			{
				int index = analysis.lastIndexOf("Type:");
				analysis = analysis.substring(index);
				suffixType = analysis.substring(5);
			}
		}
		
		return(suffixType);
	}

}
