本文整理汇总了Java中codemining.languagetools.Scope类的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Scope类属于codemining.languagetools包,在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFromFiles
import codemining.languagetools.Scope; //导入依赖的package包/类
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;
}
示例2: evaluateJunkRenamings
import codemining.languagetools.Scope; //导入依赖的package包/类
/**
* @param renamer
* @param scopes
*/
private void evaluateJunkRenamings(
final AbstractIdentifierRenamings renamer,
final Multimap<Scope, String> scopes) {
for (final Entry<Scope, String> variable : scopes.entries()) {
try {
final SortedSet<Renaming> renamings = renamer.getRenamings(
variable.getKey(), variable.getValue());
final boolean weServeJunk = junkVariables
.contains(renamings.first().name);
final boolean variableWasJunk = junkVariables
.contains(variable.getValue());
updateResults(variableWasJunk, weServeJunk);
} catch (Throwable e) {
LOGGER.warning("Failed to evaluate renaming " + variable
+ " " + ExceptionUtils.getFullStackTrace(e));
}
}
}
示例3: run
import codemining.languagetools.Scope; //导入依赖的package包/类
@Override
public void run() {
try {
final Collection<File> trainFiles = new TreeSet<File>();
trainFiles.addAll(allFiles);
checkArgument(trainFiles.remove(evaluatedFile));
final Collection<File> testFiles = Lists.newArrayList();
testFiles.add(evaluatedFile);
final AbstractIdentifierRenamings renamer = new BaseIdentifierRenamings(
tokenizer);
renamer.buildRenamingModel(trainFiles);
final Multimap<Scope, String> m;
m = scopeExtractor.getFromFile(evaluatedFile);
evaluateJunkRenamings(renamer, m);
} catch (Exception e) {
LOGGER.warning("Error in file "
+ evaluatedFile.getAbsolutePath() + " "
+ ExceptionUtils.getFullStackTrace(e));
}
}
示例4: evaluateFile
import codemining.languagetools.Scope; //导入依赖的package包/类
void evaluateFile(final File testFile, final Collection<File> trainFiles)
throws IllegalArgumentException, SecurityException,
InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException,
ClassNotFoundException, IOException {
final AbstractIdentifierRenamings renamer = (AbstractIdentifierRenamings) Class
.forName(renamerClass).getDeclaredConstructor(ITokenizer.class)
.newInstance(tokenizer);
renamer.buildRenamingModel(trainFiles);
final Multimap<Scope, String> scopes = scopeExtractor
.getFromFile(testFile);
final String targetPertubedName = "mblamblambla";
for (final Entry<Scope, String> entry : scopes.entries()) {
// TODO, here instead of reading again, give the method
final Multimap<Scope, String> perturbed = perturbedScopes(
FileUtils.readFileToString(testFile), entry.getKey(),
entry.getValue(), targetPertubedName);
final SegmentRenamingSuggestion rn = new SegmentRenamingSuggestion(
renamer, true);
final SortedSet<Suggestion> sg = rn.rankSuggestions(perturbed);
pushResults(sg, targetPertubedName);
}
}
示例5: addRenamingSuggestion
import codemining.languagetools.Scope; //导入依赖的package包/类
private Suggestion addRenamingSuggestion(
final SortedSet<Renaming> renamings, final String idName,
final Scope scope) {
final double topSuggestionXEnt = renamings.first().score;
double currentNameXent = Double.NaN;
for (final Renaming renaming : renamings) {
if (renaming.name.equals(idName)
|| (renaming.name.equals("UNK_SYMBOL") && useUNK)) {
currentNameXent = renaming.score;
break;
}
}
checkArgument(!Double.isNaN(currentNameXent));
final double confidence = topSuggestionXEnt - currentNameXent;
return new Suggestion(idName, scope, confidence, renamings);
}
示例6: rankSuggestions
import codemining.languagetools.Scope; //导入依赖的package包/类
/**
* @param identifiers
* @return
*/
public SortedSet<Suggestion> rankSuggestions(
final Multimap<Scope, String> identifiers) {
final SortedSet<Suggestion> suggestions = Sets.newTreeSet();
for (final Entry<Scope, String> s : identifiers.entries()) {
try {
final SortedSet<Renaming> renamings = renamer.getRenamings(
s.getKey(), s.getValue());
suggestions.add(addRenamingSuggestion(renamings, s.getValue(),
s.getKey()));
} catch (final Throwable e) {
LOGGER.warning("Failed to get suggestions for " + s
+ ExceptionUtils.getFullStackTrace(e));
}
}
return suggestions;
}
示例7: extractStats
import codemining.languagetools.Scope; //导入依赖的package包/类
public void extractStats() throws IOException {
for (final File f : allFiles) {
final Multimap<Scope, String> scopes = scopeExtractor
.getFromFile(f);
for (final Entry<Scope, String> entry : scopes.entries()) {
final String varName = entry.getValue();
final List<String> tokens = tokenizer.tokenListFromCode(entry
.getKey().code.toCharArray());
int count = 0;
for (final String token : tokens) {
if (token.equals(varName)) {
count++;
}
}
final UsageStats stats;
if (statistics.containsKey(varName)) {
stats = statistics.get(varName);
} else {
stats = new UsageStats();
statistics.put(varName, stats);
}
stats.sumContexts += count;
stats.timesSeen++;
}
}
}
示例8: calculateScores
import codemining.languagetools.Scope; //导入依赖的package包/类
@Override
public SortedSet<Renaming> calculateScores(
final Multiset<NGram<String>> ngrams,
final Set<String> alternatives, final Scope scope) {
final SortedSet<Renaming> scoreMap = Sets.newTreeSet();
for (final String identifierName : alternatives) {
double score = 0;
for (final Entry<NGram<String>> ngram : ngrams.entrySet()) {
try {
final NGram<String> identNGram = NGram.substituteTokenWith(
ngram.getElement(), WILDCARD_TOKEN, identifierName);
final double ngramScore = scoreNgram(identNGram);
score += DoubleMath.log2(ngramScore) * ngram.getCount();
} catch (final Throwable e) {
LOGGER.warning(ExceptionUtils.getFullStackTrace(e));
}
}
scoreMap.add(new Renaming(identifierName, (addScopePriors(
identifierName, scope) - score) / ngrams.size(), ngrams
.size() / ngramLM.getN(), scope));
}
return scoreMap;
}
示例9: calculateScores
import codemining.languagetools.Scope; //导入依赖的package包/类
/**
* Predict the max-likelihood tokens given the ngrams.
*
* @param ngrams
* @param alternatives
* @return
*/
@Override
public SortedSet<Renaming> calculateScores(
final Multiset<NGram<String>> ngrams,
final Set<String> alternatives, final Scope scope) {
final SortedSet<Renaming> suggestions = Sets.newTreeSet();
for (final String alternative : alternatives) {
double score = 0;
for (final NGram<String> ngram : ngrams) {
score += DoubleMath.log2(getNgramLM().getProbabilityFor(
NGram.substituteTokenWith(ngram, WILDCARD_TOKEN,
alternative)));
}
suggestions.add(new Renaming(alternative, -score, 1, null));
}
return suggestions;
}
示例10: getScopeSnippets
import codemining.languagetools.Scope; //导入依赖的package包/类
public static Multimap<Scope, String> getScopeSnippets(final ASTNode node,
final boolean methodAsRoots) {
final ScopeFinder scopeFinder = new ScopeFinder(methodAsRoots);
node.accept(scopeFinder);
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final Entry<ASTNode, Method> method : scopeFinder.methods
.entries()) {
scopes.put(new Scope(method.getKey().toString(),
method.getValue().type, METHOD_CALL, 0, 0), method
.getValue().name);
}
return scopes;
}
示例11: getScopeSnippets
import codemining.languagetools.Scope; //导入依赖的package包/类
/**
* Return a multimap containing all the (local) variables of the given
* scope.
*
* @param cu
* @return Multimap<Snippet, VariableName>
*/
public static Multimap<Scope, String> getScopeSnippets(final ASTNode cu) {
final VariableScopeFinder scopeFinder = new VariableScopeFinder();
cu.accept(scopeFinder);
final Multimap<Scope, String> scopes = TreeMultimap.create();
for (final Entry<ASTNode, Variable> variable : scopeFinder.variableScopes
.entries()) {
final int astNodeType = variable.getKey().getNodeType();
final int astNodeParentType;
if (variable.getKey().getParent() == null) {
astNodeParentType = -1;
} else {
astNodeParentType = variable.getKey().getParent().getNodeType();
}
scopes.put(
new Scope(variable.getKey().toString(),
variable.getValue().scope,
variable.getValue().type, astNodeType,
astNodeParentType), variable.getValue().name);
}
return scopes;
}
示例12: getClassnames
import codemining.languagetools.Scope; //导入依赖的package包/类
private Multimap<Scope, String> getClassnames(final ASTNode node) {
final ClassnameFinder cf = new ClassnameFinder(methodsAsRoots);
node.accept(cf);
final Multimap<Scope, String> classnames = TreeMultimap.create();
for (final Entry<ASTNode, String> classname : cf.types.entries()) {
final ASTNode parentNode = classname.getKey();
final Scope sc = new Scope(
classname.getKey().toString(),
parentNode.getNodeType() == ASTNode.METHOD_DECLARATION ? ScopeType.SCOPE_METHOD
: ScopeType.SCOPE_CLASS, TYPENAME,
parentNode.getNodeType(), -1);
classnames.put(sc, classname.getValue());
}
return classnames;
}
示例13: run
import codemining.languagetools.Scope; //导入依赖的package包/类
@Override
public void run() {
try {
final Multimap<Scope, String> scopes = (new VariableScopeExtractor.VariableScopeSnippetExtractor())
.getFromFile(testFile);
final List<Entry<Scope, String>> selectedScopes = sampleScopes(scopes);
if (selectedScopes.isEmpty()) {
return;
}
final Set<File> trainFiles = Sets.newTreeSet(allFiles);
checkArgument(trainFiles.remove(testFile));
final AbstractIdentifierRenamings renamer = createRenamer(
renamerClass, renamerConstructorParams);
renamer.buildRenamingModel(trainFiles);
final long nVars = selectedScopes.size();
long nJunk = 0;
for (final Entry<Scope, String> variable : selectedScopes) {
final SortedSet<Renaming> renamings = renamer.getRenamings(
variable.getKey(), variable.getValue());
if (renamings.first().name.matches("^junk[0-9]+$")) {
nJunk++;
}
}
resultObject.putResults(nVars, nJunk);
} catch (final IOException ioe) {
LOGGER.warning("Failed to get scopes from "
+ testFile.getAbsolutePath() + " "
+ ExceptionUtils.getFullStackTrace(ioe));
}
}
示例14: sampleScopes
import codemining.languagetools.Scope; //导入依赖的package包/类
/**
* @param scopes
* @return
*/
private List<Entry<Scope, String>> sampleScopes(
final Multimap<Scope, String> scopes) {
final List<Entry<Scope, String>> selectedScopes = Lists
.newArrayList();
// Sample
for (final Entry<Scope, String> variable : scopes.entries()) {
if (RandomUtils.nextDouble() > SAMPLING_RATIO) {
continue;
}
selectedScopes.add(variable);
}
return selectedScopes;
}
示例15: run
import codemining.languagetools.Scope; //导入依赖的package包/类
@Override
public void run() {
final Multimap<Scope, String> m;
try {
m = scopeExtractor.getFromFile(fi);
evaluateRenamings(m, fi);
} catch (final IOException e) {
LOGGER.warning("Failed to open file " + fi.getAbsolutePath()
+ ExceptionUtils.getFullStackTrace(e));
}
}