Skip to content

Commit 927b26e

Browse files
committed
output ttl
1 parent 4c41079 commit 927b26e

File tree

10 files changed

+588
-96
lines changed

10 files changed

+588
-96
lines changed

lib/bald/__init__.py

Lines changed: 172 additions & 74 deletions
Large diffs are not rendered by default.

lib/bald/tests/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import difflib
23
import os
34
import tempfile
45
import unittest
@@ -14,3 +15,19 @@ def temp_filename(self, suffix=''):
1415
yield filename
1516
finally:
1617
os.remove(filename)
18+
def assertStringEqual(self, first, second, msg=None):
19+
assertion_func = self._getAssertEqualityFunc(first, second)
20+
if msg is None:
21+
diff = difflib.ndiff(first.splitlines(1), second.splitlines(1))
22+
# diff = ['{0:03}'.format(i) + ' ' + line for i, line in enumerate(diff)
23+
# if line.startswith('+') or line.startswith('-')]
24+
linecount = 0
25+
dlines = [' diff:\n']
26+
for line in diff:
27+
if line.startswith(' ') or line.startswith('-'):
28+
linecount += 1
29+
if line.startswith('+') or line.startswith('-'):
30+
dlines.append('{0:03} {1}'.format(linecount, line))
31+
msg = ''.join(dlines)
32+
33+
assertion_func(first, second, msg=msg)
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
<html>
2+
<head>
3+
<title>agraph</title>
4+
<meta charset="utf-8"/>
5+
<link rel="stylesheet" type="text/css"
6+
href="https://rawgit.com/clientIO/joint/master/dist/joint.min.css" />
7+
8+
</head>
9+
<body>
10+
11+
<div id="paper"></div>
12+
<script
13+
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js"></script>
14+
<script
15+
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
16+
<script
17+
src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone.js"></script>
18+
<script
19+
src="https://rawgit.com/clientIO/joint/master/dist/joint.min.js"></script>
20+
<script src="http://rawgit.com/clientIO/joint/master/dist/joint.layout.DirectedGraph.js"></script>
21+
<script src="https://rawgit.com/cpettitt/graphlib/v2.1.1/dist/graphlib.min.js"></script>
22+
<script src="https://rawgit.com/cpettitt/dagre/v0.7.4/dist/dagre.min.js"></script>
23+
24+
<script type="text/javascript">
25+
26+
27+
var graph = new joint.dia.Graph;
28+
29+
var paper = new joint.dia.Paper({
30+
el: $('#paper'),
31+
width: 2400,
32+
height: 1350,
33+
gridSize: 1,
34+
model: graph
35+
});
36+
37+
var instance_list = [];
38+
39+
LinkedClass = joint.shapes.uml.Class.extend({
40+
41+
42+
markup: [
43+
'<g class="rotatable">',
44+
'<g class="scalable">',
45+
'<rect class="uml-class-name-rect"/><rect class="uml-class-attrs-rect"/>',
46+
'</g>',
47+
'<text class="uml-class-name-text"/><text class="uml-class-attrs-text"/>',
48+
'</g>'
49+
].join(''),
50+
51+
defaults: _.defaultsDeep({
52+
53+
type: 'uml.Class',
54+
55+
attrs: {
56+
rect: { 'width': 200 },
57+
58+
'.uml-class-name-rect': { 'stroke': 'black', 'stroke-width': 2, 'fill': '#3498db' },
59+
'.uml-class-attrs-rect': { 'stroke': 'black', 'stroke-width': 2, 'fill': '#2980b9' },
60+
61+
'.uml-class-name-text': {
62+
'ref': '.uml-class-name-rect', 'ref-y': .5, 'ref-x': .5, 'text-anchor': 'middle', 'y-alignment': 'middle', 'font-weight': 'bold',
63+
'fill': 'black', 'font-size': 12, 'font-family': 'Times New Roman'
64+
},
65+
'.uml-class-attrs-text': {
66+
'ref': '.uml-class-attrs-rect', 'ref-y': 5, 'ref-x': 0.99, 'text-anchor': 'end',
67+
'fill': 'black', 'font-size': 12, 'font-family': 'Times New Roman'
68+
}
69+
},
70+
71+
name: [],
72+
attributes: [],
73+
74+
}, joint.shapes.basic.Generic.prototype.defaults),
75+
76+
updateRectangles: function() {
77+
78+
var attrs = this.get('attrs');
79+
80+
var rects = [
81+
{ type: 'name', text: this.getClassName() },
82+
{ type: 'attrs', text: this.get('attributes') },
83+
];
84+
85+
var offsetY = 0;
86+
87+
_.each(rects, function(rect) {
88+
89+
var lines = _.isArray(rect.text) ? rect.text : [rect.text];
90+
var rectHeight = lines.length * 60 + 60;
91+
var tspanLines = []
92+
for (var i = 0; i < lines.length; i++) {
93+
var line = '<tspan class="v-line" x="0" dy="1em">'
94+
line += lines[i]
95+
line += '</tspan> '
96+
tspanLines.push(line)
97+
}
98+
attrs['.uml-class-' + rect.type + '-text'].html = tspanLines.join('');
99+
100+
attrs['.uml-class-' + rect.type + '-rect'].height = rectHeight;
101+
attrs['.uml-class-' + rect.type + '-rect'].transform = 'translate(0,' + offsetY + ')';
102+
103+
offsetY += rectHeight;
104+
});
105+
}
106+
107+
});
108+
109+
110+
111+
112+
function instance(label, attrs, bfill) {
113+
114+
var cell = new LinkedClass({
115+
name: label,
116+
attributes: attrs,
117+
size: { width: label.length * 2, height: 60 },
118+
attrs: {
119+
'.uml-class-name-rect': {
120+
fill: bfill,
121+
stroke: '#fff',
122+
'stroke-width': 0.5
123+
},
124+
'.uml-class-attrs-rect, .uml-class-methods-rect': {
125+
fill: bfill,
126+
stroke: '#fff',
127+
'stroke-width': 0.5
128+
},
129+
'.uml-class-attrs-text': {
130+
'ref-y': 0.5,
131+
'y-alignment': 'middle'
132+
}
133+
}
134+
});
135+
graph.addCell(cell);
136+
instance_list.push(cell);
137+
return cell;
138+
};
139+
140+
Aggregation = joint.dia.Link.extend({
141+
defaults: {
142+
type: 'uml.Aggregation',
143+
attrs: { '.marker-source': { d: 'M 40 10 L 20 20 L 0 10 L 20 0 z', fill: 'white' }}
144+
}
145+
});
146+
147+
Composition = joint.dia.Link.extend({
148+
defaults: {
149+
type: 'uml.Composition',
150+
attrs: { '.marker-source': { d: 'M 40 10 L 20 20 L 0 10 L 20 0 z', fill: 'black' }}
151+
}
152+
});
153+
154+
function link(source, target, label, ed, comp) {
155+
if (comp) {
156+
var aclass = Composition;
157+
} else {
158+
var aclass = Aggregation;
159+
}
160+
var cell = new aclass({
161+
source: { id: source.id },
162+
target: { id: target.id },
163+
labels: [{ position: .5, attrs: { text: { text: label || '', 'font-weight': 'bold' } } }],
164+
165+
router: {
166+
name: 'manhattan',
167+
args: {
168+
startDirections: ['right'],
169+
endDirections: [ed || 'left']
170+
}
171+
},
172+
connector: { name: 'rounded' }
173+
});
174+
graph.addCell(cell);
175+
return cell;
176+
};
177+
178+
var root = instance('root:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
179+
var alocation = instance('alocation:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
180+
var data = instance('data:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
181+
var discovery = instance('discovery:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
182+
var anotherpair = instance('anotherpair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
183+
var apair = instance('apair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
184+
var source = instance('source:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
185+
var institution = instance('institution:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: a quality establishment', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |'], '#878800');
186+
var referencing = instance('referencing:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
187+
var locref = instance('locref:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for locational purposes', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |'], '#878800');
188+
var locref2 = instance('locref2:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for more locational purposes', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |'], '#878800');
189+
link(alocation, locref2, 'bald__references');
190+
link(alocation, locref, 'bald__references');
191+
link(alocation, alocation, 'bald__array', 'bottom');
192+
link(root, alocation, 'bald__contains', 'top', true);
193+
link(data, alocation, 'bald__references');
194+
link(root, data, 'bald__contains', 'top', true);
195+
link(anotherpair, anotherpair, 'bald__array', 'bottom');
196+
link(discovery, anotherpair, 'bald__contains', 'top', true);
197+
link(apair, anotherpair, 'bald__references');
198+
link(discovery, apair, 'bald__contains', 'top', true);
199+
link(source, institution, 'bald__contains', 'top', true);
200+
link(discovery, source, 'bald__contains', 'top', true);
201+
link(root, discovery, 'bald__contains', 'top', true);
202+
link(referencing, locref, 'bald__contains', 'top', true);
203+
link(referencing, locref2, 'bald__contains', 'top', true);
204+
link(root, referencing, 'bald__contains', 'top', true);
205+
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
206+
nodeSep: 150, rankSep: 100,
207+
marginX: 100, marginY: 100,
208+
rankDir: 'LR' });
209+
210+
211+
for (var i = 0; i < instance_list.length; i++) {
212+
instance_list[i].toFront();
213+
}
214+
215+
216+
</script>
217+
</body>
218+
</html>

lib/bald/tests/integration/HTML/multi_array_reference.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@
181181
var pdim0 = instance('pdim0:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11'], '#878800');
182182
var pdim1 = instance('pdim1:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 17'], '#878800');
183183
var location_variable = instance('location_variable:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
184-
var location_reference_system = instance('location_reference_system:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', 'pcode: 4897'], '#878800');
185-
link(variable1, location_variable, 'bald__references');
184+
var location_reference_system = instance('location_reference_system:<a xlink:href="http://binary-array-ld.net/latest/Subject" xlink:show=new text-decoration="underline">bald__Subject</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', 'pcode: 4897'], '#878800');
186185
link(variable1, pdim0, 'bald__references');
186+
link(variable1, location_variable, 'bald__references');
187187
link(variable1, pdim1, 'bald__references');
188188
link(root, variable1, 'bald__contains', 'top', true);
189-
link(variable2, location_variable, 'bald__references');
190189
link(variable2, pdim0, 'bald__references');
190+
link(variable2, location_variable, 'bald__references');
191191
link(variable2, pdim1, 'bald__references');
192192
link(root, variable2, 'bald__contains', 'top', true);
193193
link(pdim0, pdim0, 'bald__array', 'bottom');
@@ -197,7 +197,6 @@
197197
link(location_variable, location_reference_system, 'bald__references');
198198
link(location_variable, location_variable, 'bald__array', 'bottom');
199199
link(root, location_variable, 'bald__contains', 'top', true);
200-
link(location_reference_system, location_reference_system, 'bald__array', 'bottom');
201200
link(root, location_reference_system, 'bald__contains', 'top', true);
202201
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
203202
nodeSep: 150, rankSep: 100,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@prefix bald: <http://binary-array-ld.net/latest/> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
7+
<root> a bald:Container ;
8+
bald:contains <child_variable>,
9+
<parent_variable> ;
10+
bald:isPrefixedBy "prefix_list" .
11+
12+
<parent_variable> a bald:Array ;
13+
bald:references <child_variable> ;
14+
bald:shape "(11, 17)" .
15+
16+
<child_variable> a bald:Array,
17+
bald:Reference ;
18+
bald:array <child_variable> ;
19+
bald:shape "(11, 17)" .
20+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@prefix bald: <http://binary-array-ld.net/latest/> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
7+
<root> a bald:Container ;
8+
bald:contains <location_reference_system>,
9+
<location_variable>,
10+
<pdim0>,
11+
<pdim1>,
12+
<variable1>,
13+
<variable2> ;
14+
bald:isPrefixedBy "prefix_list" .
15+
16+
<variable1> a bald:Array ;
17+
bald:references <location_variable>,
18+
<pdim0>,
19+
<pdim1> ;
20+
bald:shape "(11, 17)" ;
21+
<long_name> "Gerald" ;
22+
<obtype> <http://codes.wmo.int/common/observation-type/METCE/2013/SamplingObservation> .
23+
24+
<variable2> a bald:Array ;
25+
bald:references <location_variable>,
26+
<pdim0>,
27+
<pdim1> ;
28+
bald:shape "(11, 17)" ;
29+
<long_name> "Imelda" ;
30+
<obtype> <http://codes.wmo.int/common/observation-type/METCE/2013/SamplingObservation> .
31+
32+
<location_reference_system> a bald:Subject ;
33+
bald:array <location_reference_system> ;
34+
<pcode> "4897" .
35+
36+
<location_variable> a bald:Array,
37+
bald:Reference ;
38+
bald:array <location_variable> ;
39+
bald:references <location_reference_system> ;
40+
bald:shape "(11, 17)" .
41+
42+
<pdim0> a bald:Array,
43+
bald:Reference ;
44+
bald:array <pdim0> ;
45+
bald:shape "(11,)" .
46+
47+
<pdim1> a bald:Array,
48+
bald:Reference ;
49+
bald:array <pdim1> ;
50+
bald:shape "(17,)" .
51+

lib/bald/tests/integration/test_cdl_graph.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,20 @@ def test_array_reference(self):
1919
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
2020
root_container = bald.load_netcdf(tfile)
2121
html = root_container.viewgraph()
22-
# for debugging:
23-
# with self.temp_filename('.html') as outfile:
24-
# with open(outfile, 'w') as output:
25-
# output.write(html)
26-
with open(os.path.join(self.html_path, 'array_reference.html'), 'w') as sf:
27-
sf.write(html)
22+
# with open(os.path.join(self.html_path, 'array_reference.html'), 'w') as sf:
23+
# sf.write(html)
2824
with open(os.path.join(self.html_path, 'array_reference.html'), 'r') as sf:
2925
expected_html = sf.read()
30-
self.assertEqual(expected_html, html)
26+
self.assertStringEqual(expected_html, html)
3127

3228
def test_multi_array_reference(self):
3329
with self.temp_filename('.nc') as tfile:
3430
cdl_file = os.path.join(self.cdl_path, 'multi_array_reference.cdl')
3531
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
3632
root_container = bald.load_netcdf(tfile)
3733
html = root_container.viewgraph()
38-
# for debugging:
39-
# with self.temp_filename('.html') as outfile:
40-
# with open(outfile, 'w') as output:
41-
# output.write(html)
42-
with open(os.path.join(self.html_path, 'multi_array_reference.html'), 'w') as sf:
43-
sf.write(html)
34+
# with open(os.path.join(self.html_path, 'multi_array_reference.html'), 'w') as sf:
35+
# sf.write(html)
4436
with open(os.path.join(self.html_path, 'multi_array_reference.html'), 'r') as sf:
4537
expected_html = sf.read()
46-
self.assertEqual(expected_html, html)
38+
self.assertStringEqual(expected_html, html)

0 commit comments

Comments
 (0)