Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed May 1, 2024
1 parent 57ffcbf commit 18ff79b
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 1,930 deletions.
57 changes: 20 additions & 37 deletions src/main/java/fr/inria/coming/codefeatures/P4JFeatureAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Map;

import fr.inria.coming.core.entities.interfaces.IRevisionPair;
import fr.inria.prophet4j.feature.extended.ExtendedFeatureCross;
import fr.inria.prophet4j.feature.enhanced.EnhancedFeatureCross;
import org.apache.log4j.Logger;

import com.google.gson.JsonObject;
Expand All @@ -24,7 +24,6 @@
import fr.inria.coming.core.entities.AnalysisResult;
import fr.inria.coming.core.entities.DiffResult;
import fr.inria.coming.core.entities.RevisionResult;
import fr.inria.coming.main.ComingProperties;
import fr.inria.prophet4j.feature.Feature;
import fr.inria.prophet4j.feature.FeatureCross;
import fr.inria.prophet4j.utility.CodeDiffer;
Expand Down Expand Up @@ -98,49 +97,20 @@ public JsonObject extractFeatures(Map<String, File> filePaths) {
return null;
}
Option option = new Option();
option.featureOption = FeatureOption.EXTENDED;
//We set the first parameter of CodeDiffer as False to not allow the code generation at buggy location
//By default, coming extracts simple P4J features, so the cross sets to false
Boolean cross = ComingProperties.getPropertyBoolean("cross");
option.featureOption = FeatureOption.ENHANCED;

CodeDiffer codeDiffer = new CodeDiffer(false, option,cross);
CodeDiffer codeDiffer = new CodeDiffer(false, option);
//Get feature matrix
List<FeatureMatrix> featureMatrix = codeDiffer.runByGenerator(src, target);
//Get feature vector
JsonObject jsonfile = null;
// csvfile = genVectorsCSV(option,target,featureMatrix);
jsonfile = getP4JJSON(option,target,featureMatrix,true);
jsonfile = genVectorsJSON(option,target,featureMatrix);
return jsonfile;
}


public JsonObject getP4JJSON(Option option, File target, List<FeatureMatrix> featureMatrix, Boolean numericalIndixator) {

JsonObject jsonfile = new JsonObject();

for (FeatureVector featureVector : featureMatrix.get(0).getFeatureVectors()) {
List<FeatureCross> featureCrosses = featureVector.getNonSortedFeatureCrosses();

for (FeatureCross featureCross : featureCrosses) {
List<Feature> simpleP4JFeatures= featureCross.getFeatures();
for(Feature f: simpleP4JFeatures) {
Boolean positive = featureCross.containFeature(f);
if(numericalIndixator) {
jsonfile.addProperty("P4J_"+f, positive?"1":"0");
}else {
jsonfile.addProperty("P4J_"+f, positive?"true":"false");
}
}

}
}
return jsonfile;

}



public JsonObject genVectorsCSV(Option option, File patchedFile, List<FeatureMatrix> featureMatrices) {
public JsonObject genVectorsJSON(Option option, File patchedFile, List<FeatureMatrix> featureMatrices) {

String[] pathStr = patchedFile.getAbsolutePath().split("/");
String fileName = pathStr[pathStr.length-1];
Expand All @@ -152,10 +122,23 @@ public JsonObject genVectorsCSV(Option option, File patchedFile, List<FeatureMat
List<String> values = new ArrayList<>();
JsonObject jsonfile = new JsonObject();

//Initial all vector as 0.

for (FeatureVector featureVector : featureMatrices.get(0).getFeatureVectors()) {
List<FeatureCross> featureCrosses = featureVector.getNonSortedFeatureCrosses();
for (FeatureCross featureCross : featureCrosses) {
List<Feature> simpleP4JFeatures= featureCross.getFeatures();
for(Feature f: simpleP4JFeatures) {
Boolean positive = featureCross.containFeature(f);
jsonfile.addProperty("P4J_"+f, positive?"true":"false");
}

}
}

//Initial all vector as 0.
for (int idx = 0; idx < parameterVector.size(); idx++) {
FeatureCross featureCross;
featureCross = new ExtendedFeatureCross(idx);
featureCross = new EnhancedFeatureCross(idx);
header.add(featureCross.getFeatures().toString());
values.add("0");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
public interface FeatureExtractor {
// this is for CodeDiffer.java
FeatureVector extractFeature(Repair repair, CtElement atom);
FeatureVector extractSimpleP4JFeature(Repair repair, CtElement atom);
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,4 @@ public boolean containFeature(Feature feature) {
public String toString() {
return "FeatureCross: " + features;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,4 @@ private void getNearbyStmts(Repair repair, List<CtElement> stmtsF, List<CtElemen
if (!repair.isReplace)
stmtsL.add(srcElem);
}

@Override
public FeatureVector extractSimpleP4JFeature(Repair repair, CtElement atom) {
// TODO Auto-generated method stub
return null;
}
}
240 changes: 0 additions & 240 deletions src/main/java/fr/inria/prophet4j/feature/extended/ExtendedFeature.java

This file was deleted.

Loading

0 comments on commit 18ff79b

Please sign in to comment.