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/PartialInterpretationGraph.java')
1 files changed, 162 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/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 | } | ||