diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend new file mode 100644 index 00000000..a2934eb9 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend | |||
@@ -0,0 +1,134 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.PartialComplexTypeInterpretationImpl | ||
10 | import java.util.ArrayList | ||
11 | import java.util.List | ||
12 | |||
13 | class PartialInterpretationGraph extends Graph{ | ||
14 | val typeToExclude = "undefinedpart"; | ||
15 | val classSuffix = " class"; | ||
16 | |||
17 | /** | ||
18 | * Define a new PartialInterpretationGraph by parse every element from a PartialInterpretation | ||
19 | */ | ||
20 | new(PartialInterpretation partial, List<Metric> metrics, String name){ | ||
21 | //the edge types are defined in terms of RelationDeclaration | ||
22 | partial.problem.relations.filter(RelationDeclaration).forEach[ | ||
23 | //only need the name of the reference type (remove everything with and after "reference") | ||
24 | var n = it.name.split(" ").get(0); | ||
25 | this.statistic.addEdgeType(n); | ||
26 | ] | ||
27 | // add all elements | ||
28 | val typeInterpretations = getTypes(partial); | ||
29 | for(type : typeInterpretations){ | ||
30 | //Only consider the most concrete class | ||
31 | if(isConcreteType(type.interpretationOf)){ | ||
32 | var typeName = type.interpretationOf.name.replace(classSuffix, ''); | ||
33 | for(node : type.elements){ | ||
34 | if(!this.statistic.containsNode(node)){ | ||
35 | this.statistic.addNodeWithType(node, typeName); | ||
36 | }else{ | ||
37 | // if the current type of the node is a super type of the type to check, | ||
38 | // substitute the current type with the new type | ||
39 | var currentType = statistic.getTypesForNode(node).get(0); | ||
40 | if(isSuperType(currentType, type.interpretationOf)){ | ||
41 | statistic.overwriteCurrentType(node, typeName); | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | for(relationInterpretation : partial.partialrelationinterpretation) { | ||
49 | //only need the name of the reference type (remove everything with and after "reference") | ||
50 | val type = relationInterpretation.interpretationOf.name.split(" ").get(0); | ||
51 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ | ||
52 | statistic.addEdge(edge.param1, edge.param2, type); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | this.name = name; | ||
57 | this.metrics = metrics; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * recursively check if a type is the super type of another | ||
62 | */ | ||
63 | def boolean isSuperType(String typeName, Type subtypeToCheck){ | ||
64 | var superTypes = subtypeToCheck.supertypes; | ||
65 | if(superTypes.size == 0){ | ||
66 | return false; | ||
67 | }else if(subtypeToCheck.supertypes.map[it.name.replace(classSuffix, '')].contains(typeName)){ | ||
68 | return true; | ||
69 | }else{ | ||
70 | for(superType : superTypes){ | ||
71 | if(isSuperType(typeName, superType)){ | ||
72 | return true; | ||
73 | } | ||
74 | } | ||
75 | return false; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Check if a Type object is the class that we want to consider | ||
81 | * A type object is to be considered if it satisfy one of the following: | ||
82 | * 1. if it is not abstract | ||
83 | * 2. if it is abstract but has a subclass of type TypeDefinition (This means the generation is | ||
84 | * started with nodes in this type) | ||
85 | */ | ||
86 | def boolean isConcreteType(Type t){ | ||
87 | if(!t.isAbstract || t.subtypes.findFirst[it instanceof TypeDefinition] !== null){ | ||
88 | return true; | ||
89 | } | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Set basic information for the output | ||
95 | */ | ||
96 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
97 | val metaInfo = new ArrayList<String>(); | ||
98 | metaInfo.add(META_MODEL_HEADER); | ||
99 | metaInfo.add(this.metaModel); | ||
100 | |||
101 | val edgeInfo = new ArrayList<String>(); | ||
102 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
103 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
104 | |||
105 | val nodeInfo = new ArrayList<String>(); | ||
106 | nodeInfo.add(NUM_NODE_HEADER); | ||
107 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
108 | |||
109 | val stateInfo = new ArrayList<String>(); | ||
110 | stateInfo.add(STATE_ID_HEADER); | ||
111 | stateInfo.add(this.name); | ||
112 | |||
113 | output.add(metaInfo); | ||
114 | output.add(edgeInfo); | ||
115 | output.add(nodeInfo); | ||
116 | output.add(stateInfo); | ||
117 | } | ||
118 | |||
119 | private def getTypes(PartialInterpretation partial){ | ||
120 | //only the complex type interpretations are the ones defined in meta model | ||
121 | //do not care about undefined types as it will be included in the class type | ||
122 | return partial.partialtypeinterpratation.filter(PartialComplexTypeInterpretationImpl) | ||
123 | .filter[!it.interpretationOf.name.toLowerCase.contains(typeToExclude)]; | ||
124 | } | ||
125 | |||
126 | override getStatistic() { | ||
127 | throw new UnsupportedOperationException("TODO: auto-generated method stub") | ||
128 | } | ||
129 | |||
130 | override getName() { | ||
131 | return name; | ||
132 | } | ||
133 | |||
134 | } \ No newline at end of file | ||