1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement
import java.util.Map
import java.util.HashMap
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink
import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Relation
import java.util.Set
class PartialInterpretation2Gml {
def public transform(PartialInterpretation i) {
val p = i.problem
val Map<DefinedElement, Integer> objectToID = new HashMap
val containmentRelations = p.containmentHierarchies.map[it.containmentRelations].flatten.toSet
'''
graph
[
«FOR object:p.elements + i.newElements SEPARATOR '\n'»
«this.transformObject(object,object.typesOfElement(i),objectToID)»
«ENDFOR»
«FOR relation:i.partialrelationinterpretation»
«FOR link:relation.relationlinks.filter(BinaryElementRelationLink)»
«transformLink(relation,link,objectToID,containmentRelations)»
«ENDFOR»
«ENDFOR»
]
'''.toString
}
def typesOfElement(DefinedElement e, PartialInterpretation i) {
i.problem.types.filter(TypeDefinition).filter[it.elements.contains(e)] +
i.partialtypeinterpratation.filter[it.elements.contains(e)].map[it.interpretationOf]
}
val protected titleSize = 16
val protected attributeSize = 14
val protected borderDistance = 6
val protected attributeBorderDistance = 8
val protected ratio = 11.0/20.0
def protected transformObject(DefinedElement object,Iterable<Type> types,Map<DefinedElement, Integer> objectToID){
val title = object.transormTitle
val attributes = types.map[it.name]
var double width = title.length*titleSize + borderDistance*2;
for(x:attributes.map[length*attributeSize + borderDistance*2 + attributeBorderDistance*2])
width = Math::max(width,x)
width = width*ratio
val height = Math::max(
titleSize+4,
(attributes.size+1)*attributeSize + borderDistance*2)
val id = objectToID.size
objectToID.put(object,id)
'''
node
[
id «id»
graphics
[
w «width»
h «height»
type "rectangle"
fill "#FFFFFF"
fill2 "#FFFFFF"
outline "#000000"
]
LabelGraphics
[
text "«title»"
outline "#000000"
fill "#FFFFFF"
fontSize «titleSize»
fontName "Monospace"
autoSizePolicy "node_width"
anchor "t"
borderDistance 0.0
]
LabelGraphics
[
text "
«FOR attribute : attributes»
«attribute»
«ENDFOR»"
fontSize «attributeSize»
fontName "Consolas"
alignment "left"
anchor "tl"
borderDistance «borderDistance»
]
]
'''
}
def protected transormTitle(DefinedElement object) {
if(object.name!= null)object.name
else "null"
}
def protected transformLink(
PartialRelationInterpretation reference,
BinaryElementRelationLink link,
Map<DefinedElement, Integer> objectToID,
Set<Relation> containmentRelations)
{
'''
edge
[
source «objectToID.get(link.param1)»
target «objectToID.get(link.param2)»
graphics
[
fill "#000000"
«IF containmentRelations.contains(reference.interpretationOf)»
width 3
«ENDIF»
targetArrow "standard"
]
LabelGraphics
[
text "«reference.interpretationOf.name»"
fontSize 14
fontName "Consolas"
configuration "AutoFlippingLabel"
model "six_pos"
position "thead"
]
]
'''
}
}
|