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 | 60 |
1 files changed, 49 insertions, 11 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 index ef68f366..a2934eb9 100644 --- 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 | |||
@@ -2,6 +2,8 @@ package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | |||
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | 3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | 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 | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | 7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink |
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.PartialComplexTypeInterpretationImpl | 9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.PartialComplexTypeInterpretationImpl |
@@ -20,19 +22,25 @@ class PartialInterpretationGraph extends Graph{ | |||
20 | partial.problem.relations.filter(RelationDeclaration).forEach[ | 22 | partial.problem.relations.filter(RelationDeclaration).forEach[ |
21 | //only need the name of the reference type (remove everything with and after "reference") | 23 | //only need the name of the reference type (remove everything with and after "reference") |
22 | var n = it.name.split(" ").get(0); | 24 | var n = it.name.split(" ").get(0); |
23 | // TODO: Here is to only consider one part of opposite edges | ||
24 | if(!n.equals('target') && !n.equals('source') /* && !n.equals('incomingTransitions')*/){ | ||
25 | this.statistic.addEdgeType(n); | 25 | this.statistic.addEdgeType(n); |
26 | } | ||
27 | ] | 26 | ] |
28 | // add all elements | 27 | // add all elements |
29 | val typeInterpretations = getTypes(partial); | 28 | val typeInterpretations = getTypes(partial); |
30 | for(type : typeInterpretations){ | 29 | for(type : typeInterpretations){ |
31 | //Only consider the most concrete class | 30 | //Only consider the most concrete class |
32 | if(type.interpretationOf.subtypes.size == 0){ | 31 | if(isConcreteType(type.interpretationOf)){ |
33 | var typeName = type.interpretationOf.name.replace(classSuffix, ''); | 32 | var typeName = type.interpretationOf.name.replace(classSuffix, ''); |
34 | for(node : type.elements){ | 33 | for(node : type.elements){ |
35 | this.statistic.addNodeWithType(node, typeName); | 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 | } | ||
36 | } | 44 | } |
37 | } | 45 | } |
38 | } | 46 | } |
@@ -40,12 +48,9 @@ class PartialInterpretationGraph extends Graph{ | |||
40 | for(relationInterpretation : partial.partialrelationinterpretation) { | 48 | for(relationInterpretation : partial.partialrelationinterpretation) { |
41 | //only need the name of the reference type (remove everything with and after "reference") | 49 | //only need the name of the reference type (remove everything with and after "reference") |
42 | val type = relationInterpretation.interpretationOf.name.split(" ").get(0); | 50 | val type = relationInterpretation.interpretationOf.name.split(" ").get(0); |
43 | // TODO: Here is to only consider one part of opposite edges | 51 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ |
44 | if(!type.equals('target') && !type.equals('source') /*&& !type.equals('incomingTransitions')*/){ | 52 | statistic.addEdge(edge.param1, edge.param2, type); |
45 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ | 53 | } |
46 | statistic.addEdge(edge.param1, edge.param2, type); | ||
47 | } | ||
48 | } | ||
49 | } | 54 | } |
50 | 55 | ||
51 | this.name = name; | 56 | this.name = name; |
@@ -53,6 +58,39 @@ class PartialInterpretationGraph extends Graph{ | |||
53 | } | 58 | } |
54 | 59 | ||
55 | /** | 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 | /** | ||
56 | * Set basic information for the output | 94 | * Set basic information for the output |
57 | */ | 95 | */ |
58 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | 96 | override setBasicInformation(ArrayList<ArrayList<String>> output){ |