// Path: src/main/java/renaming/priors/JavaVariableGrammarPrior.java
// public class JavaVariableGrammarPrior implements
// 		IConditionalProbability<String, Pair<Integer, Integer>> {
// 
// 	final DiscreteElementwiseConditionalDistribution<String, Integer> parentPrior = new DiscreteElementwiseConditionalDistribution<String, Integer>();
// 	final DiscreteElementwiseConditionalDistribution<String, Integer> grandParentPrior = new DiscreteElementwiseConditionalDistribution<String, Integer>();
// 
// 	private static final Logger LOGGER = Logger
// 			.getLogger(JavaVariableNameTypeDistribution.class.getName());
// 
// 	public static JavaVariableGrammarPrior buildFromFiles(
// 			final Collection<File> files) {
// 		final JavaVariableGrammarPrior gp = new JavaVariableGrammarPrior();
// 		for (final File f : files) {
// 			try {
// 				for (final Entry<Scope, String> variable : VariableScopeExtractor
// 						.getScopeSnippets(f).entries()) {
// 					gp.parentPrior.addElement(variable.getValue(),
// 							variable.getKey().astNodeType);
// 					gp.grandParentPrior.addElement(variable.getValue(),
// 							variable.getKey().astParentNodeType);
// 				}
// 			} catch (final IOException e) {
// 				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
// 			}
// 		}
// 
// 		return gp;
// 	}
// 
// 	private JavaVariableGrammarPrior() {
// 	}
// 
// 	@Override
// 	public Optional<String> getMaximumLikelihoodElement(
// 			final Pair<Integer, Integer> given) {
// 		throw new NotImplementedException();
// 	}
// 
// 	@Override
// 	public double getMLProbability(final String element,
// 			final Pair<Integer, Integer> given) {
// 		return parentPrior.getMLProbability(element, given.first)
// 				* grandParentPrior.getMLProbability(element, given.second);
// 	}
// 
// }


import java.io.File;
import java.util.Collection;
import java.util.logging.Logger;
import renaming.priors.JavaVariableGrammarPrior;
import codemining.languagetools.ITokenizer;
import codemining.languagetools.Scope;
import codemining.util.data.Pair;
import com.google.common.math.DoubleMath;
/**
 * 
 */
package renaming.renamers;




/**
 * Identifier Renaming with grammar priors.
 * 
 * @author Miltos Allamanis <m.allamanis@ed.ac.uk>
 * 
 */
public class GrammarPriorIdentifierRenaming extends BaseIdentifierRenamings {

	private static final Logger LOGGER = Logger
			.getLogger(GrammarPriorIdentifierRenaming.class.getName());

// Path: src/main/java/renaming/priors/JavaVariableGrammarPrior.java
// public class JavaVariableGrammarPrior implements
// 		IConditionalProbability<String, Pair<Integer, Integer>> {
// 
// 	final DiscreteElementwiseConditionalDistribution<String, Integer> parentPrior = new DiscreteElementwiseConditionalDistribution<String, Integer>();
// 	final DiscreteElementwiseConditionalDistribution<String, Integer> grandParentPrior = new DiscreteElementwiseConditionalDistribution<String, Integer>();
// 
// 	private static final Logger LOGGER = Logger
// 			.getLogger(JavaVariableNameTypeDistribution.class.getName());
// 
// 	public static JavaVariableGrammarPrior buildFromFiles(
// 			final Collection<File> files) {
// 		final JavaVariableGrammarPrior gp = new JavaVariableGrammarPrior();
// 		for (final File f : files) {
// 			try {
// 				for (final Entry<Scope, String> variable : VariableScopeExtractor
// 						.getScopeSnippets(f).entries()) {
// 					gp.parentPrior.addElement(variable.getValue(),
// 							variable.getKey().astNodeType);
// 					gp.grandParentPrior.addElement(variable.getValue(),
// 							variable.getKey().astParentNodeType);
// 				}
// 			} catch (final IOException e) {
// 				LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
// 			}
// 		}
// 
// 		return gp;
// 	}
// 
// 	private JavaVariableGrammarPrior() {
// 	}
// 
// 	@Override
// 	public Optional<String> getMaximumLikelihoodElement(
// 			final Pair<Integer, Integer> given) {
// 		throw new NotImplementedException();
// 	}
// 
// 	@Override
// 	public double getMLProbability(final String element,
// 			final Pair<Integer, Integer> given) {
// 		return parentPrior.getMLProbability(element, given.first)
// 				* grandParentPrior.getMLProbability(element, given.second);
// 	}
// 
// }


// Path: src/main/java/renaming/renamers/GrammarPriorIdentifierRenaming.java
import java.io.File;
import java.util.Collection;
import java.util.logging.Logger;
import renaming.priors.JavaVariableGrammarPrior;
import codemining.languagetools.ITokenizer;
import codemining.languagetools.Scope;
import codemining.util.data.Pair;
import com.google.common.math.DoubleMath;

/**
 * 
 */
package renaming.renamers;




/**
 * Identifier Renaming with grammar priors.
 * 
 * @author Miltos Allamanis <m.allamanis@ed.ac.uk>
 * 
 */
public class GrammarPriorIdentifierRenaming extends BaseIdentifierRenamings {

	private static final Logger LOGGER = Logger
			.getLogger(GrammarPriorIdentifierRenaming.class.getName());

	JavaVariableGrammarPrior gp;