diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph')
12 files changed, 599 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/graph/.EMFGraph.java._trace b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.EMFGraph.java._trace new file mode 100644 index 00000000..6e2ea420 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.EMFGraph.java._trace | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.EMFGraph.xtendbin b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.EMFGraph.xtendbin new file mode 100644 index 00000000..e949bb11 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.EMFGraph.xtendbin | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.java._trace b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.java._trace new file mode 100644 index 00000000..e1d021fd --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.java._trace | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.xtendbin b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.xtendbin new file mode 100644 index 00000000..547fdc38 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.Graph.xtendbin | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.java._trace b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.java._trace new file mode 100644 index 00000000..5928ed9d --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.java._trace | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.xtendbin b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.xtendbin new file mode 100644 index 00000000..e9269f16 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.GraphStatistic.xtendbin | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.java._trace b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.java._trace new file mode 100644 index 00000000..f19eb46c --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.java._trace | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.xtendbin b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.xtendbin new file mode 100644 index 00000000..c634ef10 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/.PartialInterpretationGraph.xtendbin | |||
Binary files differ | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java new file mode 100644 index 00000000..8a9aa8d3 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.java | |||
@@ -0,0 +1,140 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.Graph; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic; | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
6 | import java.util.ArrayList; | ||
7 | import java.util.HashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.function.Consumer; | ||
10 | import org.eclipse.emf.common.util.EList; | ||
11 | import org.eclipse.emf.ecore.EObject; | ||
12 | import org.eclipse.emf.ecore.EReference; | ||
13 | import org.eclipse.xtend.lib.annotations.AccessorType; | ||
14 | import org.eclipse.xtend.lib.annotations.Accessors; | ||
15 | import org.eclipse.xtext.xbase.lib.IteratorExtensions; | ||
16 | import org.eclipse.xtext.xbase.lib.Pure; | ||
17 | |||
18 | @SuppressWarnings("all") | ||
19 | public class EMFGraph extends Graph { | ||
20 | @Accessors(AccessorType.PUBLIC_GETTER) | ||
21 | private EObject root; | ||
22 | |||
23 | public void init(final EObject root, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) { | ||
24 | final List<EObject> otherContents = IteratorExtensions.<EObject>toList(root.eAllContents()); | ||
25 | this.root = root; | ||
26 | otherContents.add(root); | ||
27 | this.init(otherContents, metrics, name, referenceTypes); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * init the graph with all nodes and reference types in the meta model | ||
32 | * @param objects: objects in the instance model (exclude root) | ||
33 | * @param metrics: metrics to be evaluated | ||
34 | * @param name: name of the instance model | ||
35 | * @param ReferenceTypes: reference types defined in the meta model | ||
36 | */ | ||
37 | public void init(final List<EObject> objects, final List<Metric> metrics, final String name, final List<EReference> referenceTypes) { | ||
38 | final Consumer<EObject> _function = (EObject it) -> { | ||
39 | HashSet<String> types = new HashSet<String>(); | ||
40 | types.add(it.eClass().getName()); | ||
41 | this.statistic.addNodeWithAllTypes(it, types); | ||
42 | }; | ||
43 | objects.forEach(_function); | ||
44 | final Consumer<EReference> _function_1 = (EReference it) -> { | ||
45 | boolean _isDerived = it.isDerived(); | ||
46 | boolean _not = (!_isDerived); | ||
47 | if (_not) { | ||
48 | this.statistic.addEdgeType(it.getName()); | ||
49 | } | ||
50 | }; | ||
51 | referenceTypes.forEach(_function_1); | ||
52 | final Consumer<EObject> _function_2 = (EObject source) -> { | ||
53 | final Consumer<EReference> _function_3 = (EReference r) -> { | ||
54 | boolean _isMany = r.isMany(); | ||
55 | if (_isMany) { | ||
56 | final Consumer<EObject> _function_4 = (EObject target) -> { | ||
57 | this.addEdge(source, target, r); | ||
58 | }; | ||
59 | this.getNeighbours(source, r).forEach(_function_4); | ||
60 | } else { | ||
61 | Object _eGet = source.eGet(r); | ||
62 | final EObject target = ((EObject) _eGet); | ||
63 | this.addEdge(source, target, r); | ||
64 | } | ||
65 | }; | ||
66 | source.eClass().getEAllReferences().forEach(_function_3); | ||
67 | }; | ||
68 | objects.forEach(_function_2); | ||
69 | this.metrics = metrics; | ||
70 | this.name = name; | ||
71 | } | ||
72 | |||
73 | public void removeReference(final EReference r) { | ||
74 | boolean _containsEdgeType = this.statistic.containsEdgeType(r.getName()); | ||
75 | if (_containsEdgeType) { | ||
76 | this.statistic.removeReference(r.getName(), r.isContainment()); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Set basic information for the output | ||
82 | */ | ||
83 | @Override | ||
84 | public void setBasicInformation(final ArrayList<ArrayList<String>> output) { | ||
85 | final ArrayList<String> metaInfo = new ArrayList<String>(); | ||
86 | metaInfo.add(Graph.META_MODEL_HEADER); | ||
87 | metaInfo.add(this.metaModel); | ||
88 | final ArrayList<String> edgeInfo = new ArrayList<String>(); | ||
89 | edgeInfo.add(Graph.NUM_EDGE_TYPE_HEADER); | ||
90 | int _size = this.statistic.getAllTypes().size(); | ||
91 | String _plus = (Integer.valueOf(_size) + ""); | ||
92 | edgeInfo.add(_plus); | ||
93 | final ArrayList<String> nodeInfo = new ArrayList<String>(); | ||
94 | nodeInfo.add(Graph.NUM_NODE_HEADER); | ||
95 | int _size_1 = this.statistic.getAllNodes().size(); | ||
96 | String _plus_1 = (Integer.valueOf(_size_1) + ""); | ||
97 | nodeInfo.add(_plus_1); | ||
98 | final ArrayList<String> stateInfo = new ArrayList<String>(); | ||
99 | stateInfo.add(Graph.STATE_ID_HEADER); | ||
100 | stateInfo.add(this.name); | ||
101 | output.add(metaInfo); | ||
102 | output.add(edgeInfo); | ||
103 | output.add(nodeInfo); | ||
104 | output.add(stateInfo); | ||
105 | } | ||
106 | |||
107 | public EList<EObject> getNeighbours(final EObject o, final EReference r) { | ||
108 | Object _eGet = o.eGet(r, true); | ||
109 | return ((EList<EObject>) _eGet); | ||
110 | } | ||
111 | |||
112 | public void addEdge(final EObject source, final EObject target, final EReference r) { | ||
113 | if ((((target != null) && (r != null)) && (!r.isDerived()))) { | ||
114 | this.statistic.addEdge(source, target, r.getName()); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | @Override | ||
119 | public GraphStatistic getStatistic() { | ||
120 | return this.statistic; | ||
121 | } | ||
122 | |||
123 | @Override | ||
124 | public String getName() { | ||
125 | return this.name; | ||
126 | } | ||
127 | |||
128 | public void setMetaModel(final String model) { | ||
129 | this.metaModel = model; | ||
130 | } | ||
131 | |||
132 | public String getMetaModel() { | ||
133 | return this.metaModel; | ||
134 | } | ||
135 | |||
136 | @Pure | ||
137 | public EObject getRoot() { | ||
138 | return this.root; | ||
139 | } | ||
140 | } | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.java new file mode 100644 index 00000000..f9923a63 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.java | |||
@@ -0,0 +1,96 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.EdgeTypeMetric; | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup; | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric; | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric; | ||
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeTypeMetric; | ||
10 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric; | ||
11 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.TypedOutDegree; | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Collection; | ||
14 | import java.util.HashMap; | ||
15 | import java.util.List; | ||
16 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
17 | |||
18 | @SuppressWarnings("all") | ||
19 | public abstract class Graph { | ||
20 | protected final static String META_MODEL_HEADER = "Meta Mode"; | ||
21 | |||
22 | protected final static String NUM_NODE_HEADER = "Number Of Nodes"; | ||
23 | |||
24 | protected final static String NUM_EDGE_TYPE_HEADER = "Number of Edge types"; | ||
25 | |||
26 | protected final static String STATE_ID_HEADER = "State Id"; | ||
27 | |||
28 | protected final GraphStatistic statistic = new GraphStatistic(); | ||
29 | |||
30 | protected List<Metric> metrics; | ||
31 | |||
32 | protected String name = ""; | ||
33 | |||
34 | protected String metaModel = ""; | ||
35 | |||
36 | /** | ||
37 | * evaluate all metrics for this model | ||
38 | * return the result as a two dimentional list | ||
39 | */ | ||
40 | public ArrayList<ArrayList<String>> evaluateAllMetrics() { | ||
41 | final ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>(); | ||
42 | this.setBasicInformation(result); | ||
43 | for (final Metric metric : this.metrics) { | ||
44 | { | ||
45 | final String[][] datas = metric.evaluate(this.statistic); | ||
46 | for (final String[] row : datas) { | ||
47 | ArrayList<String> _arrayList = new ArrayList<String>((Collection<? extends String>)Conversions.doWrapArray(row)); | ||
48 | result.add(_arrayList); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | return result; | ||
53 | } | ||
54 | |||
55 | public MetricSampleGroup evaluateAllMetricsToSamples() { | ||
56 | MetricSampleGroup sample = new MetricSampleGroup(); | ||
57 | for (final Metric metric : this.metrics) { | ||
58 | if ((metric instanceof MultiplexParticipationCoefficientMetric)) { | ||
59 | Object _evaluateSamples = ((MultiplexParticipationCoefficientMetric)metric).evaluateSamples(this.statistic); | ||
60 | sample.mpcSamples = ((ArrayList<Double>) _evaluateSamples); | ||
61 | } else { | ||
62 | if ((metric instanceof NodeActivityMetric)) { | ||
63 | Object _evaluateSamples_1 = ((NodeActivityMetric)metric).evaluateSamples(this.statistic); | ||
64 | sample.naSamples = ((ArrayList<Double>) _evaluateSamples_1); | ||
65 | } else { | ||
66 | if ((metric instanceof OutDegreeMetric)) { | ||
67 | Object _evaluateSamples_2 = ((OutDegreeMetric)metric).evaluateSamples(this.statistic); | ||
68 | sample.outDegreeSamples = ((ArrayList<Double>) _evaluateSamples_2); | ||
69 | } else { | ||
70 | if ((metric instanceof TypedOutDegree)) { | ||
71 | Object _evaluateSamples_3 = ((TypedOutDegree)metric).evaluateSamples(this.statistic); | ||
72 | sample.typedOutDegreeSamples = ((HashMap<String, List<Integer>>) _evaluateSamples_3); | ||
73 | } else { | ||
74 | if ((metric instanceof NodeTypeMetric)) { | ||
75 | Object _evaluateSamples_4 = ((NodeTypeMetric)metric).evaluateSamples(this.statistic); | ||
76 | sample.nodeTypeSamples = ((HashMap<String, Double>) _evaluateSamples_4); | ||
77 | } else { | ||
78 | if ((metric instanceof EdgeTypeMetric)) { | ||
79 | Object _evaluateSamples_5 = ((EdgeTypeMetric)metric).evaluateSamples(this.statistic); | ||
80 | sample.edgeTypeSamples = ((HashMap<String, Double>) _evaluateSamples_5); | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | return sample; | ||
89 | } | ||
90 | |||
91 | public abstract void setBasicInformation(final ArrayList<ArrayList<String>> result); | ||
92 | |||
93 | public abstract GraphStatistic getStatistic(); | ||
94 | |||
95 | public abstract String getName(); | ||
96 | } | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java new file mode 100644 index 00000000..7bd1d899 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java | |||
@@ -0,0 +1,201 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import com.google.common.collect.ArrayListMultimap; | ||
4 | import com.google.common.collect.Multimap; | ||
5 | import java.util.Collection; | ||
6 | import java.util.HashMap; | ||
7 | import java.util.HashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | import java.util.Set; | ||
11 | import java.util.function.Consumer; | ||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
14 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
15 | |||
16 | @SuppressWarnings("all") | ||
17 | public class GraphStatistic { | ||
18 | private final HashMap<String, Multimap<EObject, EObject>> incomingEdges = new HashMap<String, Multimap<EObject, EObject>>(); | ||
19 | |||
20 | private final HashMap<String, Multimap<EObject, EObject>> outgoingEdges = new HashMap<String, Multimap<EObject, EObject>>(); | ||
21 | |||
22 | private final HashSet<String> edgeTypes = new HashSet<String>(); | ||
23 | |||
24 | private final HashMap<EObject, Set<String>> nodeToType = new HashMap<EObject, Set<String>>(); | ||
25 | |||
26 | /** | ||
27 | * Add an edge type to to the graph | ||
28 | * @param type: type to add | ||
29 | */ | ||
30 | public void addEdgeType(final String type) { | ||
31 | boolean _contains = this.edgeTypes.contains(type); | ||
32 | if (_contains) { | ||
33 | return; | ||
34 | } | ||
35 | this.edgeTypes.add(type); | ||
36 | this.incomingEdges.put(type, ArrayListMultimap.<EObject, EObject>create()); | ||
37 | this.outgoingEdges.put(type, ArrayListMultimap.<EObject, EObject>create()); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Add a node to the graph with one type in its type hierarchy | ||
42 | * @param node: node to add | ||
43 | */ | ||
44 | public void addNodeWithType(final EObject n, final String Type) { | ||
45 | HashSet<String> _hashSet = new HashSet<String>(); | ||
46 | Set<String> types = this.nodeToType.getOrDefault(n, _hashSet); | ||
47 | types.add(Type); | ||
48 | this.nodeToType.put(n, types); | ||
49 | } | ||
50 | |||
51 | public boolean containsNode(final EObject o) { | ||
52 | return this.nodeToType.containsKey(o); | ||
53 | } | ||
54 | |||
55 | public Set<String> getTypesForNode(final EObject o) { | ||
56 | HashSet<String> _hashSet = new HashSet<String>(); | ||
57 | return this.nodeToType.getOrDefault(o, _hashSet); | ||
58 | } | ||
59 | |||
60 | public void overwriteCurrentType(final EObject o, final String type) { | ||
61 | HashSet<String> _hashSet = new HashSet<String>(); | ||
62 | Set<String> typeSet = this.nodeToType.getOrDefault(o, _hashSet); | ||
63 | typeSet.clear(); | ||
64 | typeSet.add(type); | ||
65 | this.nodeToType.put(o, typeSet); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Add a node to the graph with all types in its type hierarchy | ||
70 | */ | ||
71 | public void addNodeWithAllTypes(final EObject n, final Set<String> types) { | ||
72 | this.nodeToType.put(n, types); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * Add an edge to the graph | ||
77 | * @param source: source node | ||
78 | * @param target: target node | ||
79 | * @param type: type of the reference | ||
80 | */ | ||
81 | public void addEdge(final EObject source, final EObject target, final String type) { | ||
82 | this.outgoingEdges.get(type).put(source, target); | ||
83 | this.incomingEdges.get(type).put(target, source); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * check if this graph contains a specific edge type | ||
88 | */ | ||
89 | public boolean containsEdgeType(final String typeName) { | ||
90 | if ((this.outgoingEdges.containsKey(typeName) && this.incomingEdges.containsKey(typeName))) { | ||
91 | return true; | ||
92 | } | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * remove references from the statistics, potentially remove the nodes associated with it | ||
98 | * @Param name: name of the reference | ||
99 | * @Param isContainment: if true then the corresponding nodes on the incoming side will also be removed | ||
100 | */ | ||
101 | public void removeReference(final String name, final boolean isContainment) { | ||
102 | boolean _contains = this.edgeTypes.contains(name); | ||
103 | boolean _not = (!_contains); | ||
104 | if (_not) { | ||
105 | return; | ||
106 | } | ||
107 | this.edgeTypes.remove(name); | ||
108 | Multimap<EObject, EObject> incomingSet = this.incomingEdges.remove(name); | ||
109 | this.outgoingEdges.remove(name); | ||
110 | if ((!isContainment)) { | ||
111 | return; | ||
112 | } | ||
113 | final Set<EObject> nodesToRemove = incomingSet.keySet(); | ||
114 | final Consumer<EObject> _function = (EObject it) -> { | ||
115 | this.nodeToType.remove(it); | ||
116 | }; | ||
117 | nodesToRemove.forEach(_function); | ||
118 | final Procedure1<Multimap<EObject, EObject>> _function_1 = (Multimap<EObject, EObject> refMap) -> { | ||
119 | final Consumer<EObject> _function_2 = (EObject it) -> { | ||
120 | refMap.removeAll(it); | ||
121 | }; | ||
122 | nodesToRemove.forEach(_function_2); | ||
123 | Collection<EObject> values = refMap.values(); | ||
124 | values.removeAll(nodesToRemove); | ||
125 | return; | ||
126 | }; | ||
127 | final Procedure1<Multimap<EObject, EObject>> removeForMultimap = _function_1; | ||
128 | IterableExtensions.<Multimap<EObject, EObject>>forEach(this.incomingEdges.values(), removeForMultimap); | ||
129 | IterableExtensions.<Multimap<EObject, EObject>>forEach(this.outgoingEdges.values(), removeForMultimap); | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * calculate the out degree for an object | ||
134 | */ | ||
135 | public int outDegree(final EObject o) { | ||
136 | int count = 0; | ||
137 | for (final String type : this.edgeTypes) { | ||
138 | int _count = count; | ||
139 | int _size = this.outgoingEdges.get(type).get(o).size(); | ||
140 | count = (_count + _size); | ||
141 | } | ||
142 | return count; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * calculate the in degree of an object | ||
147 | */ | ||
148 | public int inDegree(final EObject o) { | ||
149 | int count = 0; | ||
150 | for (final String type : this.edgeTypes) { | ||
151 | int _count = count; | ||
152 | int _size = this.incomingEdges.get(type).get(o).size(); | ||
153 | count = (_count + _size); | ||
154 | } | ||
155 | return count; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * calculate the dimentional degree of a node | ||
160 | */ | ||
161 | public int dimentionalDegree(final EObject o, final String type) { | ||
162 | int _size = this.incomingEdges.get(type).get(o).size(); | ||
163 | int _size_1 = this.outgoingEdges.get(type).get(o).size(); | ||
164 | return (_size + _size_1); | ||
165 | } | ||
166 | |||
167 | /** | ||
168 | * calculate the number of edge types for a given node. | ||
169 | */ | ||
170 | public int numOfEdgeTypes(final EObject o) { | ||
171 | int count = 0; | ||
172 | for (final String type : this.edgeTypes) { | ||
173 | int _dimentionalDegree = this.dimentionalDegree(o, type); | ||
174 | boolean _greaterThan = (_dimentionalDegree > 0); | ||
175 | if (_greaterThan) { | ||
176 | count++; | ||
177 | } | ||
178 | } | ||
179 | return count; | ||
180 | } | ||
181 | |||
182 | public List<String> getAllTypes() { | ||
183 | return IterableExtensions.<String>toList(this.edgeTypes); | ||
184 | } | ||
185 | |||
186 | public Map<EObject, Set<String>> getNodeToTypesMap() { | ||
187 | return this.nodeToType; | ||
188 | } | ||
189 | |||
190 | public List<EObject> getAllNodes() { | ||
191 | return IterableExtensions.<EObject>toList(this.nodeToType.keySet()); | ||
192 | } | ||
193 | |||
194 | public HashMap<String, Multimap<EObject, EObject>> getOutgoingEdges() { | ||
195 | return this.outgoingEdges; | ||
196 | } | ||
197 | |||
198 | public HashMap<String, Multimap<EObject, EObject>> incomingEdges() { | ||
199 | return this.incomingEdges; | ||
200 | } | ||
201 | } | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.java new file mode 100644 index 00000000..83bb92ca --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.java | |||
@@ -0,0 +1,162 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.Graph; | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.GraphStatistic; | ||
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric; | ||
6 | import com.google.common.collect.Iterables; | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement; | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration; | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition; | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink; | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation; | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.PartialComplexTypeInterpretationImpl; | ||
15 | import java.util.ArrayList; | ||
16 | import java.util.List; | ||
17 | import java.util.function.Consumer; | ||
18 | import org.eclipse.emf.common.util.EList; | ||
19 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
20 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
21 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
22 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
23 | |||
24 | @SuppressWarnings("all") | ||
25 | public class PartialInterpretationGraph extends Graph { | ||
26 | private final String typeToExclude = "undefinedpart"; | ||
27 | |||
28 | private final String classSuffix = " class"; | ||
29 | |||
30 | /** | ||
31 | * Define a new PartialInterpretationGraph by parse every element from a PartialInterpretation | ||
32 | */ | ||
33 | public PartialInterpretationGraph(final PartialInterpretation partial, final List<Metric> metrics, final String name) { | ||
34 | final Consumer<RelationDeclaration> _function = (RelationDeclaration it) -> { | ||
35 | String n = it.getName().split(" ")[0]; | ||
36 | this.statistic.addEdgeType(n); | ||
37 | }; | ||
38 | Iterables.<RelationDeclaration>filter(partial.getProblem().getRelations(), RelationDeclaration.class).forEach(_function); | ||
39 | final Iterable<PartialComplexTypeInterpretationImpl> typeInterpretations = this.getTypes(partial); | ||
40 | for (final PartialComplexTypeInterpretationImpl type : typeInterpretations) { | ||
41 | boolean _isConcreteType = this.isConcreteType(type.getInterpretationOf()); | ||
42 | if (_isConcreteType) { | ||
43 | String typeName = type.getInterpretationOf().getName().replace(this.classSuffix, ""); | ||
44 | EList<DefinedElement> _elements = type.getElements(); | ||
45 | for (final DefinedElement node : _elements) { | ||
46 | boolean _containsNode = this.statistic.containsNode(node); | ||
47 | boolean _not = (!_containsNode); | ||
48 | if (_not) { | ||
49 | this.statistic.addNodeWithType(node, typeName); | ||
50 | } else { | ||
51 | String currentType = ((String[])Conversions.unwrapArray(this.statistic.getTypesForNode(node), String.class))[0]; | ||
52 | boolean _isSuperType = this.isSuperType(currentType, type.getInterpretationOf()); | ||
53 | if (_isSuperType) { | ||
54 | this.statistic.overwriteCurrentType(node, typeName); | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | EList<PartialRelationInterpretation> _partialrelationinterpretation = partial.getPartialrelationinterpretation(); | ||
61 | for (final PartialRelationInterpretation relationInterpretation : _partialrelationinterpretation) { | ||
62 | { | ||
63 | final String type_1 = relationInterpretation.getInterpretationOf().getName().split(" ")[0]; | ||
64 | Iterable<BinaryElementRelationLink> _filter = Iterables.<BinaryElementRelationLink>filter(relationInterpretation.getRelationlinks(), BinaryElementRelationLink.class); | ||
65 | for (final BinaryElementRelationLink edge : _filter) { | ||
66 | this.statistic.addEdge(edge.getParam1(), edge.getParam2(), type_1); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | this.name = name; | ||
71 | this.metrics = metrics; | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * recursively check if a type is the super type of another | ||
76 | */ | ||
77 | public boolean isSuperType(final String typeName, final Type subtypeToCheck) { | ||
78 | EList<Type> superTypes = subtypeToCheck.getSupertypes(); | ||
79 | int _size = superTypes.size(); | ||
80 | boolean _equals = (_size == 0); | ||
81 | if (_equals) { | ||
82 | return false; | ||
83 | } else { | ||
84 | final Function1<Type, String> _function = (Type it) -> { | ||
85 | return it.getName().replace(this.classSuffix, ""); | ||
86 | }; | ||
87 | boolean _contains = ListExtensions.<Type, String>map(subtypeToCheck.getSupertypes(), _function).contains(typeName); | ||
88 | if (_contains) { | ||
89 | return true; | ||
90 | } else { | ||
91 | for (final Type superType : superTypes) { | ||
92 | boolean _isSuperType = this.isSuperType(typeName, superType); | ||
93 | if (_isSuperType) { | ||
94 | return true; | ||
95 | } | ||
96 | } | ||
97 | return false; | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Check if a Type object is the class that we want to consider | ||
104 | * A type object is to be considered if it satisfy one of the following: | ||
105 | * 1. if it is not abstract | ||
106 | * 2. if it is abstract but has a subclass of type TypeDefinition (This means the generation is | ||
107 | * started with nodes in this type) | ||
108 | */ | ||
109 | public boolean isConcreteType(final Type t) { | ||
110 | if (((!t.isIsAbstract()) || (IterableExtensions.<Type>findFirst(t.getSubtypes(), ((Function1<Type, Boolean>) (Type it) -> { | ||
111 | return Boolean.valueOf((it instanceof TypeDefinition)); | ||
112 | })) != null))) { | ||
113 | return true; | ||
114 | } | ||
115 | return false; | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * Set basic information for the output | ||
120 | */ | ||
121 | @Override | ||
122 | public void setBasicInformation(final ArrayList<ArrayList<String>> output) { | ||
123 | final ArrayList<String> metaInfo = new ArrayList<String>(); | ||
124 | metaInfo.add(Graph.META_MODEL_HEADER); | ||
125 | metaInfo.add(this.metaModel); | ||
126 | final ArrayList<String> edgeInfo = new ArrayList<String>(); | ||
127 | edgeInfo.add(Graph.NUM_EDGE_TYPE_HEADER); | ||
128 | int _size = this.statistic.getAllTypes().size(); | ||
129 | String _plus = (Integer.valueOf(_size) + ""); | ||
130 | edgeInfo.add(_plus); | ||
131 | final ArrayList<String> nodeInfo = new ArrayList<String>(); | ||
132 | nodeInfo.add(Graph.NUM_NODE_HEADER); | ||
133 | int _size_1 = this.statistic.getAllNodes().size(); | ||
134 | String _plus_1 = (Integer.valueOf(_size_1) + ""); | ||
135 | nodeInfo.add(_plus_1); | ||
136 | final ArrayList<String> stateInfo = new ArrayList<String>(); | ||
137 | stateInfo.add(Graph.STATE_ID_HEADER); | ||
138 | stateInfo.add(this.name); | ||
139 | output.add(metaInfo); | ||
140 | output.add(edgeInfo); | ||
141 | output.add(nodeInfo); | ||
142 | output.add(stateInfo); | ||
143 | } | ||
144 | |||
145 | private Iterable<PartialComplexTypeInterpretationImpl> getTypes(final PartialInterpretation partial) { | ||
146 | final Function1<PartialComplexTypeInterpretationImpl, Boolean> _function = (PartialComplexTypeInterpretationImpl it) -> { | ||
147 | boolean _contains = it.getInterpretationOf().getName().toLowerCase().contains(this.typeToExclude); | ||
148 | return Boolean.valueOf((!_contains)); | ||
149 | }; | ||
150 | return IterableExtensions.<PartialComplexTypeInterpretationImpl>filter(Iterables.<PartialComplexTypeInterpretationImpl>filter(partial.getPartialtypeinterpratation(), PartialComplexTypeInterpretationImpl.class), _function); | ||
151 | } | ||
152 | |||
153 | @Override | ||
154 | public GraphStatistic getStatistic() { | ||
155 | throw new UnsupportedOperationException("TODO: auto-generated method stub"); | ||
156 | } | ||
157 | |||
158 | @Override | ||
159 | public String getName() { | ||
160 | return this.name; | ||
161 | } | ||
162 | } | ||