diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/TypedClusteringCoefficientMetric.java')
1 files changed, 74 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/TypedClusteringCoefficientMetric.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/TypedClusteringCoefficientMetric.java new file mode 100644 index 00000000..042af5c3 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/metrics/TypedClusteringCoefficientMetric.java | |||
@@ -0,0 +1,74 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
5 | import com.google.common.base.Objects; | ||
6 | import java.text.DecimalFormat; | ||
7 | import java.util.ArrayList; | ||
8 | import java.util.Collection; | ||
9 | import java.util.HashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.function.Consumer; | ||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | |||
14 | @SuppressWarnings("all") | ||
15 | public class TypedClusteringCoefficientMetric extends Metric { | ||
16 | public final static String countName = "TCCCount"; | ||
17 | |||
18 | public final static String valueName = "TCCValue"; | ||
19 | |||
20 | private final DecimalFormat formatter = new DecimalFormat("#0.00000"); | ||
21 | |||
22 | @Override | ||
23 | public String[][] evaluate(final GraphStatistic g) { | ||
24 | throw new Error("Unresolved compilation problems:" | ||
25 | + "\nInvalid number of arguments. The method newArrayOfSize(int) is not applicable for the arguments (int,int)"); | ||
26 | } | ||
27 | |||
28 | @Override | ||
29 | public Object evaluateSamples(final GraphStatistic g) { | ||
30 | final ArrayList<Double> samples = new ArrayList<Double>(); | ||
31 | final Consumer<EObject> _function = (EObject it) -> { | ||
32 | samples.add(Double.valueOf(this.calculateTCC1(it, g))); | ||
33 | }; | ||
34 | g.getAllNodes().forEach(_function); | ||
35 | return samples; | ||
36 | } | ||
37 | |||
38 | /** | ||
39 | * Compute TCC1 metric for node n | ||
40 | */ | ||
41 | public double calculateTCC1(final EObject n, final GraphStatistic g) { | ||
42 | int wedges = 0; | ||
43 | int triangles = 0; | ||
44 | List<String> _allTypes = g.getAllTypes(); | ||
45 | for (final String type1 : _allTypes) { | ||
46 | { | ||
47 | Collection<EObject> _get = g.getOutgoingEdges().get(type1).get(n); | ||
48 | final HashSet<EObject> typed1RelatedOfN = new HashSet<EObject>(_get); | ||
49 | Collection<EObject> _get_1 = g.incomingEdges().get(type1).get(n); | ||
50 | final HashSet<EObject> type1EdgeSourceNodesOfN = new HashSet<EObject>(_get_1); | ||
51 | typed1RelatedOfN.addAll(type1EdgeSourceNodesOfN); | ||
52 | final int d = typed1RelatedOfN.size(); | ||
53 | int _wedges = wedges; | ||
54 | wedges = (_wedges + (d * (d - 1))); | ||
55 | for (final EObject n1 : typed1RelatedOfN) { | ||
56 | for (final EObject n2 : typed1RelatedOfN) { | ||
57 | List<String> _allTypes_1 = g.getAllTypes(); | ||
58 | for (final String type2 : _allTypes_1) { | ||
59 | if (((!Objects.equal(type1, type2)) && (g.getOutgoingEdges().get(type2).containsEntry(n1, n2) || | ||
60 | g.getOutgoingEdges().get(type2).containsEntry(n2, n1)))) { | ||
61 | triangles++; | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | if ((wedges == 0.0)) { | ||
69 | return 0.0; | ||
70 | } else { | ||
71 | return (((double) triangles) / wedges); | ||
72 | } | ||
73 | } | ||
74 | } | ||