Skip to content

Commit

Permalink
#3 Implemented top words for directly contained types
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPirnbaum committed Jul 28, 2017
1 parent e02df09 commit 2d16d1b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Set<ComponentDescriptor> execute() {

public static void prettyPrint(Set<ComponentDescriptor> components, String indentation , PrintWriter pW) {
for (ComponentDescriptor component : components) {
pW.println(indentation + " " + component.getName());
pW.println(indentation + " " + component.getName() + " " + Arrays.toString(component.getTopWords()));
Result<CompositeRowObject > 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<ComponentDescriptor> componentDescriptors = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -83,6 +84,7 @@ public Set<ComponentDescriptor> classify(Integer iteration, Map<Long, Set<Long>>
private Set<Long> materializeGroups(Map<Long, Set<Long>> partitioning, int iteration, int level) {
SARFRunner.xoManager.currentTransaction().begin();
Set<Long> identifiedGroups = new HashSet<>();
ComponentRepository componentRepository = SARFRunner.xoManager.getRepository(ComponentRepository.class);
for (Map.Entry<Long, Set<Long>> component : partitioning.entrySet()) {
ComponentDescriptor componentDescriptor = SARFRunner.xoManager.create(ComponentDescriptor.class);
componentDescriptor.setShape("Component");
Expand All @@ -97,7 +99,23 @@ private Set<Long> materializeGroups(Map<Long, Set<Long>> partitioning, int itera
}
}
identifiedGroups.add(SARFRunner.xoManager.getId(componentDescriptor));

Result<TypeDescriptor> typeDescriptors = componentRepository.getContainedTypesRecursively(SARFRunner.xoManager.getId(componentDescriptor));
Map<String, Long> 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<Long, String> sorted = new ImmutableListMultimap.Builder<Long, String>()
.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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public interface ComponentDescriptor extends SARFNode {
@Relation("CONTAINS")
@Outgoing
Set<TypeDescriptor> getContainedTypes();

String[] getTopWords();

void setTopWords(String[] topWords);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TypeDescriptor> getContainedTypesRecursively(@Parameter("id") long id);
}

0 comments on commit 2d16d1b

Please sign in to comment.