diff --git a/src/main/java/com/buchmais/sarf/classification/configuration/ActiveClassificationConfiguration.java b/src/main/java/com/buchmais/sarf/classification/configuration/ActiveClassificationConfiguration.java index 4dbb6af..190780e 100644 --- a/src/main/java/com/buchmais/sarf/classification/configuration/ActiveClassificationConfiguration.java +++ b/src/main/java/com/buchmais/sarf/classification/configuration/ActiveClassificationConfiguration.java @@ -134,7 +134,7 @@ public Set execute() { public static void prettyPrint(Set components, String indentation , PrintWriter pW) { for (ComponentDescriptor component : components) { - pW.println(indentation + " " + component.getName()); + pW.println(indentation + " " + component.getName() + " " + Arrays.toString(component.getTopWords())); Result res = SARFRunner.xoManager.createQuery("MATCH (c) WHERE ID(c) = " + SARFRunner.xoManager.getId(component) + " " + "OPTIONAL MATCH (c)-[:CONTAINS]->(e) RETURN e").execute(); // TODO: 05.07.2017 Improve !!! Set componentDescriptors = new HashSet<>(); diff --git a/src/main/java/com/buchmais/sarf/classification/criterion/cohesion/CohesionCriterion.java b/src/main/java/com/buchmais/sarf/classification/criterion/cohesion/CohesionCriterion.java index 373d563..79d07b6 100644 --- a/src/main/java/com/buchmais/sarf/classification/criterion/cohesion/CohesionCriterion.java +++ b/src/main/java/com/buchmais/sarf/classification/criterion/cohesion/CohesionCriterion.java @@ -8,7 +8,8 @@ import com.buchmais.sarf.repository.TypeRepository; import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor; import com.buschmais.xo.api.Query.Result; -import com.google.common.collect.Sets; +import com.google.common.collect.*; +import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -83,6 +84,7 @@ public Set classify(Integer iteration, Map> private Set materializeGroups(Map> partitioning, int iteration, int level) { SARFRunner.xoManager.currentTransaction().begin(); Set identifiedGroups = new HashSet<>(); + ComponentRepository componentRepository = SARFRunner.xoManager.getRepository(ComponentRepository.class); for (Map.Entry> component : partitioning.entrySet()) { ComponentDescriptor componentDescriptor = SARFRunner.xoManager.create(ComponentDescriptor.class); componentDescriptor.setShape("Component"); @@ -97,7 +99,23 @@ private Set materializeGroups(Map> partitioning, int itera } } identifiedGroups.add(SARFRunner.xoManager.getId(componentDescriptor)); - + Result typeDescriptors = componentRepository.getContainedTypesRecursively(SARFRunner.xoManager.getId(componentDescriptor)); + Map wordCount = new HashMap<>(); + for (TypeDescriptor typeDescriptor : typeDescriptors) { + String[] words = StringUtils.splitByCharacterTypeCamelCase(typeDescriptor.getName()); + for (String word : words) { + wordCount.merge( + word, + 1L, + (w1, w2) -> w1 + 1 + ); + } + } + ListMultimap sorted = new ImmutableListMultimap.Builder() + .orderKeysBy(Ordering.natural().reverse()) + .putAll(Multimaps.invertFrom(Multimaps.forMap(wordCount), ArrayListMultimap.create())) + .build(); + componentDescriptor.setTopWords(sorted.entries().stream().limit(10).map(Map.Entry::getValue).toArray(String[]::new)); } SARFRunner.xoManager.currentTransaction().commit(); return identifiedGroups; diff --git a/src/main/java/com/buchmais/sarf/metamodel/ComponentDescriptor.java b/src/main/java/com/buchmais/sarf/metamodel/ComponentDescriptor.java index cb6111c..9e7db67 100644 --- a/src/main/java/com/buchmais/sarf/metamodel/ComponentDescriptor.java +++ b/src/main/java/com/buchmais/sarf/metamodel/ComponentDescriptor.java @@ -62,4 +62,8 @@ public interface ComponentDescriptor extends SARFNode { @Relation("CONTAINS") @Outgoing Set getContainedTypes(); + + String[] getTopWords(); + + void setTopWords(String[] topWords); } diff --git a/src/main/java/com/buchmais/sarf/repository/ComponentRepository.java b/src/main/java/com/buchmais/sarf/repository/ComponentRepository.java index 1b9e85e..0be3d71 100644 --- a/src/main/java/com/buchmais/sarf/repository/ComponentRepository.java +++ b/src/main/java/com/buchmais/sarf/repository/ComponentRepository.java @@ -2,6 +2,7 @@ import com.buchmais.sarf.classification.criterion.ClassificationInfoDescriptor; import com.buchmais.sarf.metamodel.ComponentDescriptor; +import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor; import com.buschmais.xo.api.Query.Result; import com.buschmais.xo.api.annotation.Repository; import com.buschmais.xo.api.annotation.ResultOf; @@ -232,4 +233,13 @@ Long computeComplementCardinality(@Parameter("shape1") String ofShape, @Paramete "MERGE\n" + " (c1)-[:IS_SIMILAR_TO{similarity:(intersection / (c1Coup + c2Coup))}]-(c2)") void computeSimilarityBetweenComponents(@Parameter("ids") long[] ids); + + @ResultOf + @Cypher("MATCH" + + " (c:Component)-[:CONTAINS]-(t:Type:Internal) " + + "WHERE" + + " ID(c) = {id} " + + "RETURN" + + " DISTINCT t") + Result getContainedTypesRecursively(@Parameter("id") long id); }