// Path: src/main/java/com/asher_stern/crf/postagging/postaggers/PosTagger.java
// public interface PosTagger
// {
// 	/**
// 	 * Assigns tags for each token in the given sentence.
// 	 * @param sentence An input sentence, given as a list of tokens.
// 	 * @return The tagged sentence.
// 	 */
// 	public List<TaggedToken<String,String>> tagSentence(List<String> sentence);
// }
// 
// Path: src/main/java/com/asher_stern/crf/postagging/postaggers/PosTaggerTrainer.java
// public interface PosTaggerTrainer<C extends Iterable<? extends List<? extends TaggedToken<String, String>>>>
// {
// 	/**
// 	 * Train the pos-tagger with the given corpus.
// 	 * @param corpus
// 	 */
// 	public void train(C corpus);
// 	
// 	/**
// 	 * Get the trained pos-tagger, which has been created earlier by the method {@link #train(PosTagCorpus)}.
// 	 * @return
// 	 */
// 	public PosTagger getTrainedPosTagger();
// 	
// 	/**
// 	 * Save the pos-tagger model which has been learned earlier by the method {@link #train(PosTagCorpus)}. 
// 	 * @param modelDirectory
// 	 */
// 	public void save(File modelDirectory);
// 
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/CrfException.java
// public class CrfException extends RuntimeException
// {
// 	private static final long serialVersionUID = 5414394233000815286L;
// 
// 	public CrfException()
// 	{
// 		super();
// 	}
// 
// 	public CrfException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public CrfException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public CrfException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public CrfException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// 
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/TaggedToken.java
// public class TaggedToken<K,G>
// {
// 	public TaggedToken(K token, G tag)
// 	{
// 		super();
// 		this.token = token;
// 		this.tag = tag;
// 	}
// 	
// 	
// 	
// 	public K getToken()
// 	{
// 		return token;
// 	}
// 	public G getTag()
// 	{
// 		return tag;
// 	}
// 
// 	
// 
// 
// 	@Override
// 	public String toString()
// 	{
// 		return "CrfTaggedToken [getToken()=" + getToken() + ", getTag()="
// 				+ getTag() + "]";
// 	}
// 	
// 	
// 
// 
// 
// 
// 	@Override
// 	public int hashCode()
// 	{
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((tag == null) ? 0 : tag.hashCode());
// 		result = prime * result + ((token == null) ? 0 : token.hashCode());
// 		return result;
// 	}
// 
// 
// 
// 	@Override
// 	public boolean equals(Object obj)
// 	{
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		TaggedToken<?,?> other = (TaggedToken<?,?>) obj;
// 		if (tag == null)
// 		{
// 			if (other.tag != null)
// 				return false;
// 		} else if (!tag.equals(other.tag))
// 			return false;
// 		if (token == null)
// 		{
// 			if (other.token != null)
// 				return false;
// 		} else if (!token.equals(other.token))
// 			return false;
// 		return true;
// 	}
// 
// 
// 
// 
// 
// 
// 	private final K token;
// 	private final G tag;
// }


import java.io.File;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.asher_stern.crf.postagging.postaggers.PosTagger;
import com.asher_stern.crf.postagging.postaggers.PosTaggerTrainer;
import com.asher_stern.crf.utilities.CrfException;
import com.asher_stern.crf.utilities.TaggedToken;
package com.asher_stern.crf.postagging.postaggers.majority;




/**
 * Trains a {@link MajorityPosTagger} from a given corpus.
 * For each token the trainer counts how many times each tag was assigned to that token in the corpus.
 * Then, for each token, the tag that was the most frequent for that token is considered as the tag to be used in
 * annotating a test example.
 *  
 * @author Asher Stern
 * Date: Nov 4, 2014
 *
 */
public class MajorityPosTaggerTrainer implements PosTaggerTrainer<Iterable<List<TaggedToken<String, String>>>>
{

	@Override
	public void train(Iterable<List<TaggedToken<String, String>>> corpus)
	{
		processCorpus(corpus);
		
		majorityForToken = calculateMajorityForTokens();
		majorGeneralTag = getMajority(majorityMapGeneralTag);
		
		posTagger = new MajorityPosTagger(majorityForToken, majorGeneralTag);
	}

	@Override
// Path: src/main/java/com/asher_stern/crf/postagging/postaggers/PosTagger.java
// public interface PosTagger
// {
// 	/**
// 	 * Assigns tags for each token in the given sentence.
// 	 * @param sentence An input sentence, given as a list of tokens.
// 	 * @return The tagged sentence.
// 	 */
// 	public List<TaggedToken<String,String>> tagSentence(List<String> sentence);
// }
// 
// Path: src/main/java/com/asher_stern/crf/postagging/postaggers/PosTaggerTrainer.java
// public interface PosTaggerTrainer<C extends Iterable<? extends List<? extends TaggedToken<String, String>>>>
// {
// 	/**
// 	 * Train the pos-tagger with the given corpus.
// 	 * @param corpus
// 	 */
// 	public void train(C corpus);
// 	
// 	/**
// 	 * Get the trained pos-tagger, which has been created earlier by the method {@link #train(PosTagCorpus)}.
// 	 * @return
// 	 */
// 	public PosTagger getTrainedPosTagger();
// 	
// 	/**
// 	 * Save the pos-tagger model which has been learned earlier by the method {@link #train(PosTagCorpus)}. 
// 	 * @param modelDirectory
// 	 */
// 	public void save(File modelDirectory);
// 
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/CrfException.java
// public class CrfException extends RuntimeException
// {
// 	private static final long serialVersionUID = 5414394233000815286L;
// 
// 	public CrfException()
// 	{
// 		super();
// 	}
// 
// 	public CrfException(String message, Throwable cause,
// 			boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public CrfException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public CrfException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public CrfException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// 
// }
// 
// Path: src/main/java/com/asher_stern/crf/utilities/TaggedToken.java
// public class TaggedToken<K,G>
// {
// 	public TaggedToken(K token, G tag)
// 	{
// 		super();
// 		this.token = token;
// 		this.tag = tag;
// 	}
// 	
// 	
// 	
// 	public K getToken()
// 	{
// 		return token;
// 	}
// 	public G getTag()
// 	{
// 		return tag;
// 	}
// 
// 	
// 
// 
// 	@Override
// 	public String toString()
// 	{
// 		return "CrfTaggedToken [getToken()=" + getToken() + ", getTag()="
// 				+ getTag() + "]";
// 	}
// 	
// 	
// 
// 
// 
// 
// 	@Override
// 	public int hashCode()
// 	{
// 		final int prime = 31;
// 		int result = 1;
// 		result = prime * result + ((tag == null) ? 0 : tag.hashCode());
// 		result = prime * result + ((token == null) ? 0 : token.hashCode());
// 		return result;
// 	}
// 
// 
// 
// 	@Override
// 	public boolean equals(Object obj)
// 	{
// 		if (this == obj)
// 			return true;
// 		if (obj == null)
// 			return false;
// 		if (getClass() != obj.getClass())
// 			return false;
// 		TaggedToken<?,?> other = (TaggedToken<?,?>) obj;
// 		if (tag == null)
// 		{
// 			if (other.tag != null)
// 				return false;
// 		} else if (!tag.equals(other.tag))
// 			return false;
// 		if (token == null)
// 		{
// 			if (other.token != null)
// 				return false;
// 		} else if (!token.equals(other.token))
// 			return false;
// 		return true;
// 	}
// 
// 
// 
// 
// 
// 
// 	private final K token;
// 	private final G tag;
// }


// Path: src/main/java/com/asher_stern/crf/postagging/postaggers/majority/MajorityPosTaggerTrainer.java
import java.io.File;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.asher_stern.crf.postagging.postaggers.PosTagger;
import com.asher_stern.crf.postagging.postaggers.PosTaggerTrainer;
import com.asher_stern.crf.utilities.CrfException;
import com.asher_stern.crf.utilities.TaggedToken;

package com.asher_stern.crf.postagging.postaggers.majority;




/**
 * Trains a {@link MajorityPosTagger} from a given corpus.
 * For each token the trainer counts how many times each tag was assigned to that token in the corpus.
 * Then, for each token, the tag that was the most frequent for that token is considered as the tag to be used in
 * annotating a test example.
 *  
 * @author Asher Stern
 * Date: Nov 4, 2014
 *
 */
public class MajorityPosTaggerTrainer implements PosTaggerTrainer<Iterable<List<TaggedToken<String, String>>>>
{

	@Override
	public void train(Iterable<List<TaggedToken<String, String>>> corpus)
	{
		processCorpus(corpus);
		
		majorityForToken = calculateMajorityForTokens();
		majorGeneralTag = getMajority(majorityMapGeneralTag);
		
		posTagger = new MajorityPosTagger(majorityForToken, majorGeneralTag);
	}

	@Override
	public PosTagger getTrainedPosTagger()