diff options
Diffstat (limited to 'Solvers')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend index b400652f..1e86f826 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra/src/hu/bme/mit/inf/dslreasoner/viatrasolver/logic2viatra/patterns/RelationDefinitionIndexer.xtend | |||
@@ -45,10 +45,30 @@ class RelationDefinitionIndexer { | |||
45 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.MUST)» | 45 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.MUST)» |
46 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.MAY)» | 46 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.MAY)» |
47 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.CURRENT)» | 47 | «relation.transformPattern(relation.lookup(relation2PQuery), Modality.CURRENT)» |
48 | «IF fqn2PQuery.values.relationDefinitionIsUsedInTransitiveClosure(relation.lookup(relation2PQuery))» | ||
49 | «relation.transformPatternWithTwoParameters(relation.lookup(relation2PQuery), Modality.MUST)» | ||
50 | «relation.transformPatternWithTwoParameters(relation.lookup(relation2PQuery), Modality.MAY)» | ||
51 | «relation.transformPatternWithTwoParameters(relation.lookup(relation2PQuery), Modality.CURRENT)» | ||
52 | «ENDIF» | ||
48 | «ENDFOR» | 53 | «ENDFOR» |
49 | ''' | 54 | ''' |
50 | } | 55 | } |
51 | 56 | ||
57 | private def relationDefinitionIsUsedInTransitiveClosure(Iterable<PQuery> all, PQuery r) { | ||
58 | all.exists[ | ||
59 | it.disjunctBodies.bodies.exists[ | ||
60 | it.constraints.exists[ | ||
61 | val constraint = it | ||
62 | if(constraint instanceof BinaryTransitiveClosure) { | ||
63 | return constraint.referredQuery === r | ||
64 | } else { | ||
65 | return false | ||
66 | } | ||
67 | ] | ||
68 | ] | ||
69 | ] | ||
70 | } | ||
71 | |||
52 | private def relationDefinitionName(RelationDefinition relation, Modality modality) | 72 | private def relationDefinitionName(RelationDefinition relation, Modality modality) |
53 | '''«modality.name.toLowerCase»InRelation_«base.canonizeName(relation.name)»''' | 73 | '''«modality.name.toLowerCase»InRelation_«base.canonizeName(relation.name)»''' |
54 | 74 | ||
@@ -73,6 +93,13 @@ class RelationDefinitionIndexer { | |||
73 | throw new UnsupportedOperationException('''Can not transform pattern "«p.fullyQualifiedName»"!''',e) | 93 | throw new UnsupportedOperationException('''Can not transform pattern "«p.fullyQualifiedName»"!''',e) |
74 | } | 94 | } |
75 | } | 95 | } |
96 | private def transformPatternWithTwoParameters(RelationDefinition relation, PQuery p, Modality modality) { | ||
97 | return ''' | ||
98 | private pattern twoParam_«relationDefinitionName(relation,modality)»(«FOR param : p.parameters SEPARATOR ', '»var_«param.name»«ENDFOR») { | ||
99 | find «relationDefinitionName(relation,modality)»(_,_,«FOR param : p.parameters SEPARATOR ', '»var_«param.name»«ENDFOR»); | ||
100 | } | ||
101 | ''' | ||
102 | } | ||
76 | 103 | ||
77 | private def toMustMay(Modality modality) { | 104 | private def toMustMay(Modality modality) { |
78 | if(modality == Modality::MAY) return Modality::MAY | 105 | if(modality == Modality::MAY) return Modality::MAY |
@@ -80,7 +107,7 @@ class RelationDefinitionIndexer { | |||
80 | } | 107 | } |
81 | 108 | ||
82 | def public referPattern(PQuery p, String[] variables, Modality modality, boolean positive, boolean transitive) ''' | 109 | def public referPattern(PQuery p, String[] variables, Modality modality, boolean positive, boolean transitive) ''' |
83 | «IF !positive»neg «ENDIF»find «modality.name.toLowerCase»InRelation_pattern_«p.fullyQualifiedName.replace('.','_')»«IF transitive»+«ENDIF»(problem,interpretation,«variables.join(',')»); | 110 | «IF !positive»neg «ENDIF»find «IF transitive»twoParam_«ENDIF»«modality.name.toLowerCase»InRelation_pattern_«p.fullyQualifiedName.replace('.','_')»«IF transitive»+«ENDIF»(«IF !transitive»problem,interpretation,«ENDIF»«variables.join(',')»); |
84 | ''' | 111 | ''' |
85 | 112 | ||
86 | private dispatch def transformConstraint(TypeConstraint constraint, Modality modality) { | 113 | private dispatch def transformConstraint(TypeConstraint constraint, Modality modality) { |