codemining.util.data.Pair Java Examples

The following examples show how to use codemining.util.data.Pair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaTypeHierarchyExtractor.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
private void addTypes(String parent, String child) {
	if (parent.contains("<")) {
		// Manually compute erasure.
		parent = parent.substring(0, parent.indexOf("<"))
				+ parent.substring(parent.indexOf(">") + 1);
	}
	if (child.contains("<")) {
		// Manually compute erasure.
		child = child.substring(0, child.indexOf("<"))
				+ child.substring(child.indexOf(">") + 1);
	}

	if (!child.contains(".") && importedNames.containsKey(child)) {
		child = importedNames.get(child);
	} else if (!child.contains(".")) {
		child = currentPackageName + "." + child;
	}
	if (!parent.contains(".") && importedNames.containsKey(parent)) {
		parent = importedNames.get(parent);
	} else if (!parent.contains(".")) {
		parent = currentPackageName + "." + parent;
	}
	final Pair<String, String> typeRelationship = Pair.create(parent,
			child);
	parentChildRelationships.add(typeRelationship);
}
 
Example #2
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTypes(String parent, String child) {
	if (parent.contains("<")) {
		// Manually compute erasure.
		parent = parent.substring(0, parent.indexOf("<"))
				+ parent.substring(parent.indexOf(">") + 1);
	}
	if (child.contains("<")) {
		// Manually compute erasure.
		child = child.substring(0, child.indexOf("<"))
				+ child.substring(child.indexOf(">") + 1);
	}

	if (!child.contains(".") && importedNames.containsKey(child)) {
		child = importedNames.get(child);
	} else if (!child.contains(".")) {
		child = currentPackageName + "." + child;
	}
	if (!parent.contains(".") && importedNames.containsKey(parent)) {
		parent = importedNames.get(parent);
	} else if (!parent.contains(".")) {
		parent = currentPackageName + "." + parent;
	}
	final Pair<String, String> typeRelationship = Pair.create(parent,
			child);
	parentChildRelationships.add(typeRelationship);
}
 
Example #3
Source File: JavaTypeHierarchyExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTypes(String parent, String child) {
	if (parent.contains("<")) {
		// Manually compute erasure.
		parent = parent.substring(0, parent.indexOf("<"))
				+ parent.substring(parent.indexOf(">") + 1);
	}
	if (child.contains("<")) {
		// Manually compute erasure.
		child = child.substring(0, child.indexOf("<"))
				+ child.substring(child.indexOf(">") + 1);
	}

	if (!child.contains(".") && importedNames.containsKey(child)) {
		child = importedNames.get(child);
	} else if (!child.contains(".")) {
		child = currentPackageName + "." + child;
	}
	if (!parent.contains(".") && importedNames.containsKey(parent)) {
		parent = importedNames.get(parent);
	} else if (!parent.contains(".")) {
		parent = currentPackageName + "." + parent;
	}
	final Pair<String, String> typeRelationship = Pair.create(parent,
			child);
	parentChildRelationships.add(typeRelationship);
}
 
Example #4
Source File: JavaTypeHierarchyExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
private Collection<Pair<String, String>> getParentTypeRelationshipsFrom(
		final File file) {
	final JavaASTExtractor ex = new JavaASTExtractor(true);
	try {
		final CompilationUnit ast = ex.getAST(file);
		final HierarchyExtractor hEx = new HierarchyExtractor();
		ast.accept(hEx);
		return hEx.parentChildRelationships;
	} catch (final IOException e) {
		LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
	}
	return Collections.emptySet();
}
 
Example #5
Source File: AllPriorIdentifierRenaming.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private double addGrammarPrior(final String identifierName,
		final Scope scope) {
	if (!USE_GRAMMAR) {
		return 0;
	}
	final double prob = gp.getMLProbability(identifierName,
			Pair.create(scope.astNodeType, scope.astParentNodeType));
	if (prob > 0) {
		return -DoubleMath.log2(prob);
	} else if (!this.isTrueUNK(identifierName)) {
		return 6;
	} else {
		return 0;
	}
}
 
Example #6
Source File: GrammarPriorIdentifierRenaming.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected double addScopePriors(final String identifierName,
		final Scope scope) {
	final double prob = gp.getMLProbability(identifierName,
			Pair.create(scope.astNodeType, scope.astParentNodeType));
	if (prob > 0) {
		return -DoubleMath.log2(prob);
	} else if (!this.isTrueUNK(identifierName)) {
		return 100;
	} else {
		return 0;
	}
}
 
Example #7
Source File: ChangingIdentifiersRepositoryWalker.java    From naturalize with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Return the equivalence classes of the variables. This is essentially, a
 * list of variables that could be identical.
 *
 * @param state
 * @param newIdentifierInfo
 * @return
 */
Collection<Pair<IdentifierInformationThroughTime, Set<IdentifierInformation>>> matchByType(
		final Collection<IdentifierInformationThroughTime> state,
		final Set<IdentifierInformation> newIdentifierInfo) {
	final List<Pair<IdentifierInformationThroughTime, Set<IdentifierInformation>>> equivalenceClasses = Lists
			.newArrayList();
	for (final IdentifierInformationThroughTime iitt : state) {
		if (!iitt.isDeleted()) {
			equivalenceClasses.add(Pair.create(iitt, Sets.newHashSet()));
		}
	}

	for (final IdentifierInformation newIdentifierInformation : newIdentifierInfo) {
		// First try to match to an existing set
		boolean atLeastOneMatchFound = false;
		for (final Pair<IdentifierInformationThroughTime, Set<IdentifierInformation>> idPair : equivalenceClasses) {
			if (idPair.first == null) {
				continue;
			} else if (idPair.first.getLast().areTypeEqual(
					newIdentifierInformation)) {
				atLeastOneMatchFound = true;
				idPair.second.add(newIdentifierInformation);
			}
		}
		// If we fail, add
		if (!atLeastOneMatchFound) {
			equivalenceClasses.add(Pair.create(null,
					Sets.newHashSet(newIdentifierInformation)));
		}
	}
	return equivalenceClasses;
}
 
Example #8
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Collection<Pair<String, String>> getParentTypeRelationshipsFrom(
		final File file) {
	final JavaASTExtractor ex = new JavaASTExtractor(true);
	try {
		final CompilationUnit ast = ex.getAST(file);
		final HierarchyExtractor hEx = new HierarchyExtractor();
		ast.accept(hEx);
		return hEx.parentChildRelationships;
	} catch (final IOException e) {
		LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
	}
	return Collections.emptySet();
}
 
Example #9
Source File: JavaTypeHierarchyExtractor.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Collection<Pair<String, String>> getParentTypeRelationshipsFrom(
		final File file) {
	final JavaASTExtractor ex = new JavaASTExtractor(true);
	try {
		final CompilationUnit ast = ex.getAST(file);
		final HierarchyExtractor hEx = new HierarchyExtractor();
		ast.accept(hEx);
		return hEx.parentChildRelationships;
	} catch (final IOException e) {
		LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
	}
	return Collections.emptySet();
}
 
Example #10
Source File: JavaVariableGrammarPrior.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Optional<String> getMaximumLikelihoodElement(
		final Pair<Integer, Integer> given) {
	throw new NotImplementedException();
}
 
Example #11
Source File: JavaVariableGrammarPrior.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public double getMLProbability(final String element,
		final Pair<Integer, Integer> given) {
	return parentPrior.getMLProbability(element, given.first)
			* grandParentPrior.getMLProbability(element, given.second);
}