Search in sources :

Example 1 with GuessDecider

use of de.dagere.peass.analysis.guessing.GuessDecider in project peass by DaGeRe.

the class ClassifyByRules method classifyProject.

private void classifyProject(final Set<String> allFeatures, final String project) throws IOException, JsonParseException, JsonMappingException {
    final RepoFolders repos = new RepoFolders();
    final File learnFile = new File(repos.getClassificationFolder(), project + ".json");
    final File learnPropertyFile = repos.getProjectPropertyFile(project);
    final Classification learn = Constants.OBJECTMAPPER.readValue(learnFile, Classification.class);
    final VersionChangeProperties changes = Constants.OBJECTMAPPER.readValue(learnPropertyFile, VersionChangeProperties.class);
    final File methodFileFolder = new File(learnPropertyFile.getParentFile(), "methods");
    try (BufferedWriter csvWriter = new BufferedWriter(new FileWriter(new File(project + ".csv")))) {
        for (final Entry<String, ChangeProperties> version : changes.getVersions().entrySet()) {
            final File versionFolder = new File(methodFileFolder, version.getKey());
            for (final Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
                for (final ChangeProperty property : testcase.getValue()) {
                    final VersionClass versionClass = learn.getVersions().get(version.getKey());
                    final ChangedEntity entity = new ChangedEntity(testcase.getKey(), "", property.getMethod());
                    final TestcaseClass testcaseClass = versionClass.getTestcases().get(entity);
                    final GuessDecider guesser = new GuessDecider(versionFolder);
                    final Set<String> types = testcaseClass.getTypes();
                    writeFeatures(allFeatures, csvWriter, property, guesser);
                    writeType(csvWriter, types);
                    csvWriter.write("\n");
                    csvWriter.flush();
                }
            }
        }
    }
}
Also used : VersionClass(de.dagere.peass.analysis.groups.VersionClass) FileWriter(java.io.FileWriter) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) BufferedWriter(java.io.BufferedWriter) Classification(de.dagere.peass.analysis.groups.Classification) ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider) RepoFolders(de.dagere.peass.analysis.all.RepoFolders) TestcaseClass(de.dagere.peass.analysis.groups.TestcaseClass)

Example 2 with GuessDecider

use of de.dagere.peass.analysis.guessing.GuessDecider in project peass by DaGeRe.

the class ClassifyByRules method getAllWords.

private void getAllWords(final Classification learn, final VersionChangeProperties changes, final File methodFileFolder, final Set<String> allFeatures) throws IOException {
    for (final Entry<String, ChangeProperties> version : changes.getVersions().entrySet()) {
        final File versionFolder = new File(methodFileFolder, version.getKey());
        for (final Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
            for (final ChangeProperty property : testcase.getValue()) {
                final GuessDecider guesser = new GuessDecider(versionFolder);
                for (final String method : property.getAffectedMethods()) {
                    final Patch<String> diff = guesser.getDiff(method);
                    final List<String> features = getOriginalFeatures(diff);
                    final List<String> featuresRevised = getRevisedFeatures(diff);
                    allFeatures.addAll(features);
                    allFeatures.addAll(featuresRevised);
                // indexBuilder.addDocument("doc_" + index++, features.toArray(new String[0]), categoryNames);
                }
            }
        }
    }
}
Also used : ChangeProperties(de.dagere.peass.analysis.properties.ChangeProperties) VersionChangeProperties(de.dagere.peass.analysis.properties.VersionChangeProperties) LinkedList(java.util.LinkedList) List(java.util.List) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider)

Example 3 with GuessDecider

use of de.dagere.peass.analysis.guessing.GuessDecider in project peass by DaGeRe.

the class GuessClassificationsByRules method guessVersion.

private void guessVersion(final Classification manual, final Entry<String, ChangeProperties> version) throws IOException {
    File versionFolder = new File(methodFileFolder, version.getKey());
    for (Entry<String, List<ChangeProperty>> testcase : version.getValue().getProperties().entrySet()) {
        GuessDecider guesser = new GuessDecider(versionFolder);
        for (ChangeProperty property : testcase.getValue()) {
            all++;
            if (version.getKey().equals("4ed6e923cb2033272fcb993978d69e325990a5aa")) {
                System.err.println();
            }
            Guess guess = guesser.guess(property.getAffectedMethods());
            testStructuralChanges(guesser, property, guess);
            if (guess != null) {
                VersionClass versionClass = manual.getVersions().get(version.getKey());
                if (versionClass != null) {
                    ChangedEntity entity = new ChangedEntity(testcase.getKey(), "", property.getMethod());
                    TestcaseClass testcaseClass = versionClass.getTestcases().get(entity);
                    if (testcaseClass != null) {
                        checkCorrectness(guess, testcaseClass, version.getKey(), entity);
                    } else {
                        LOG.error("In version {}, Testcase {} is missing - changes not consistent with properties!", version.getKey(), testcase);
                    }
                } else {
                    LOG.error("Version {} is missing - changes not consistent with properties!", version.getKey());
                }
            }
        }
    }
}
Also used : VersionClass(de.dagere.peass.analysis.groups.VersionClass) Guess(de.dagere.peass.analysis.guessing.Guess) List(java.util.List) ChangeProperty(de.dagere.peass.analysis.properties.ChangeProperty) ChangedEntity(de.dagere.peass.dependency.analysis.data.ChangedEntity) File(java.io.File) GuessDecider(de.dagere.peass.analysis.guessing.GuessDecider) TestcaseClass(de.dagere.peass.analysis.groups.TestcaseClass)

Aggregations

GuessDecider (de.dagere.peass.analysis.guessing.GuessDecider)3 ChangeProperty (de.dagere.peass.analysis.properties.ChangeProperty)3 File (java.io.File)3 List (java.util.List)3 TestcaseClass (de.dagere.peass.analysis.groups.TestcaseClass)2 VersionClass (de.dagere.peass.analysis.groups.VersionClass)2 ChangeProperties (de.dagere.peass.analysis.properties.ChangeProperties)2 VersionChangeProperties (de.dagere.peass.analysis.properties.VersionChangeProperties)2 ChangedEntity (de.dagere.peass.dependency.analysis.data.ChangedEntity)2 LinkedList (java.util.LinkedList)2 RepoFolders (de.dagere.peass.analysis.all.RepoFolders)1 Classification (de.dagere.peass.analysis.groups.Classification)1 Guess (de.dagere.peass.analysis.guessing.Guess)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1