diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend new file mode 100644 index 00000000..4b7af959 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/GenericTypeRefinementGenerator.xtend | |||
@@ -0,0 +1,102 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.patterns | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.ecore2logicannotations.InverseRelationAssertion | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.Modality | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.TypeAnalysisResult | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
11 | import java.util.HashMap | ||
12 | |||
13 | class GenericTypeRefinementGenerator extends TypeRefinementGenerator { | ||
14 | public new(PatternGenerator base) { | ||
15 | super(base) | ||
16 | } | ||
17 | override requiresTypeAnalysis() { false } | ||
18 | |||
19 | override generateRefineObjectQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
20 | val containment = p.containmentHierarchies.head | ||
21 | val newObjectTypes = p.types.filter(TypeDeclaration).filter[!isAbstract] | ||
22 | val inverseRelations = new HashMap | ||
23 | p.annotations.filter(InverseRelationAssertion).forEach[ | ||
24 | inverseRelations.put(it.inverseA,it.inverseB) | ||
25 | inverseRelations.put(it.inverseB,it.inverseA) | ||
26 | ] | ||
27 | return ''' | ||
28 | «FOR type:newObjectTypes» | ||
29 | «IF(containment.typesOrderedInHierarchy.contains(type))» | ||
30 | «FOR containmentRelation : containment.containmentRelations.filter[canBeContainedByRelation(it,type)]» | ||
31 | «IF inverseRelations.containsKey(containmentRelation)» | ||
32 | pattern «this.patternName(containmentRelation,inverseRelations.get(containmentRelation),type)»( | ||
33 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
34 | relationInterpretation:PartialRelationInterpretation, inverseInterpretation:PartialRelationInterpretation ,typeInterpretation:PartialTypeInterpratation, | ||
35 | container:DefinedElement) | ||
36 | { | ||
37 | find interpretation(problem,interpretation); | ||
38 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
39 | PartialTypeInterpratation.interpretationOf.name(typeInterpretation,"«type.name»"); | ||
40 | PartialInterpretation.partialrelationinterpretation(interpretation,relationInterpretation); | ||
41 | PartialRelationInterpretation.interpretationOf.name(relationInterpretation,"«containmentRelation.name»"); | ||
42 | PartialInterpretation.partialrelationinterpretation(interpretation,inverseInterpretation); | ||
43 | PartialRelationInterpretation.interpretationOf.name(inverseInterpretation,"«inverseRelations.get(containmentRelation).name»"); | ||
44 | «base.typeIndexer.referInstanceOf((containmentRelation.parameters.get(0) as ComplexTypeReference).referred,Modality.MUST,"container")» | ||
45 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
46 | «base.relationDeclarationIndexer.referRelation(containmentRelation as RelationDeclaration,"container","newObject",Modality.MAY)» | ||
47 | find mustExist(problem, interpretation, container); | ||
48 | neg find mustExist(problem, interpretation, newObject); | ||
49 | } | ||
50 | «ELSE» | ||
51 | pattern «this.patternName(containmentRelation,null,type)»( | ||
52 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
53 | relationInterpretation:PartialRelationInterpretation, typeInterpretation:PartialTypeInterpratation, | ||
54 | container:DefinedElement) | ||
55 | { | ||
56 | find interpretation(problem,interpretation); | ||
57 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
58 | PartialTypeInterpratation.interpretationOf.name(typeInterpretation,"«type.name»"); | ||
59 | PartialInterpretation.partialrelationinterpretation(interpretation,relationInterpretation); | ||
60 | PartialRelationInterpretation.interpretationOf.name(relationInterpretation,"«containmentRelation.name»"); | ||
61 | «base.typeIndexer.referInstanceOf((containmentRelation.parameters.get(0) as ComplexTypeReference).referred,Modality.MUST,"container")» | ||
62 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
63 | «base.relationDeclarationIndexer.referRelation(containmentRelation as RelationDeclaration,"container","newObject",Modality.MAY)» | ||
64 | find mustExist(problem, interpretation, container); | ||
65 | neg find mustExist(problem, interpretation, newObject); | ||
66 | } | ||
67 | «ENDIF» | ||
68 | «ENDFOR» | ||
69 | «ELSE» | ||
70 | pattern createObject_«this.patternName(null,null,type)»( | ||
71 | problem:LogicProblem, interpretation:PartialInterpretation, | ||
72 | typeInterpretation:PartialTypeInterpratation) | ||
73 | { | ||
74 | find interpretation(problem,interpretation); | ||
75 | PartialInterpretation.partialtypeinterpratation(interpretation,typeInterpretation); | ||
76 | PartialTypeInterpratation.interpretationOf.name(type,"«type.name»"); | ||
77 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"newObject")» | ||
78 | find mayExist(problem, interpretation, newObject); | ||
79 | neg find mustExist(problem, interpretation, newObject); | ||
80 | } | ||
81 | «ENDIF» | ||
82 | «ENDFOR» | ||
83 | ''' | ||
84 | } | ||
85 | |||
86 | override generateRefineTypeQueries(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
87 | return ''' | ||
88 | «FOR type : p.types.filter(TypeDeclaration).filter[!it.isAbstract]» | ||
89 | pattern refineTypeTo_«base.canonizeName(type.name)»(problem:LogicProblem, interpretation:PartialInterpretation, object: DefinedElement) { | ||
90 | find interpretation(problem,interpretation); | ||
91 | find mustExist(problem, interpretation, object); | ||
92 | «base.typeIndexer.referInstanceOf(type,Modality.MAY,"object")» | ||
93 | neg «base.typeIndexer.referInstanceOf(type,Modality.MUST,"object")» | ||
94 | } | ||
95 | «ENDFOR» | ||
96 | ''' | ||
97 | } | ||
98 | |||
99 | override getRefineTypeQueryNames(LogicProblem p, PartialInterpretation emptySolution, TypeAnalysisResult typeAnalysisResult) { | ||
100 | p.types.filter(TypeDeclaration).toInvertedMap['''refineTypeTo_«base.canonizeName(it.name)»'''] | ||
101 | } | ||
102 | } \ No newline at end of file | ||