Skip to content

Commit ca4a69d

Browse files
committed
graph diagram ordering, type validation
1 parent 927b26e commit ca4a69d

File tree

6 files changed

+65
-65
lines changed

6 files changed

+65
-65
lines changed

lib/bald/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def _network_js():
184184
var cell = new aclass({
185185
source: { id: source.id },
186186
target: { id: target.id },
187-
labels: [{ position: .5, attrs: { text: { text: label || '', 'font-weight': 'bold' } } }],
188187
189188
router: {
190189
name: 'manhattan',
@@ -399,6 +398,8 @@ def viewgraph(self):
399398
"""
400399

401400
instances, links = self.graph_elems()
401+
links.sort()
402+
instances.sort()
402403
ascript = '\n'.join([_network_js(), '\n'.join(instances), '\n'.join(links), _network_js_close()])
403404

404405
html = jinja2.Environment().from_string(_graph_html()).render(title='agraph', script=ascript)
@@ -627,24 +628,26 @@ def validate_hdf5(afilepath):
627628
root_container = load_hdf5(afilepath)
628629
return validate(root_container)
629630

630-
def validate(root_container):
631+
def validate(root_container, sval=None):
631632
"""
632633
Validate a Container with respect to binary-array-linked-data.
633634
Returns a :class:`bald.validation.Validation`
634635
635636
"""
636-
sval = bv.StoredValidation()
637+
if sval is None:
638+
sval = bv.StoredValidation()
637639

638640
root_val = bv.ContainerValidation(subject=root_container)
639641
sval.stored_exceptions += root_val.exceptions()
640642
for subject in root_container.attrs.get('bald__contains', []):
641-
642-
# a dataset's attribute collection inherits from and
643-
# specialises it's container's attrbiute collection
644-
# this only helps with prefixes, afaik, hence:
645-
# #
646-
array_val = bv.ArrayValidation(subject)
647-
sval.stored_exceptions += array_val.exceptions()
643+
if isinstance(subject, Array):
644+
array_val = bv.ArrayValidation(subject)
645+
sval.stored_exceptions += array_val.exceptions()
646+
elif isinstance(subject, Container):
647+
sval = validate(subject, sval=sval)
648+
elif isinstance(subject, Subject):
649+
subject_val = bv.SubjectValidation(subject)
650+
sval.stored_exceptions += subject_val.exceptions()
648651

649652
return sval
650653

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
var cell = new aclass({
161161
source: { id: source.id },
162162
target: { id: target.id },
163-
labels: [{ position: .5, attrs: { text: { text: label || '', 'font-weight': 'bold' } } }],
164163

165164
router: {
166165
name: 'manhattan',
@@ -175,13 +174,13 @@
175174
return cell;
176175
};
177176

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 parent_variable = instance('parent_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/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');
180177
var child_variable = instance('child_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/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
181-
link(parent_variable, child_variable, 'bald__references');
182-
link(root, parent_variable, 'bald__contains', 'top', true);
178+
var parent_variable = instance('parent_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/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');
179+
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');
183180
link(child_variable, child_variable, 'bald__array', 'bottom');
181+
link(parent_variable, child_variable, 'bald__references');
184182
link(root, child_variable, 'bald__contains', 'top', true);
183+
link(root, parent_variable, 'bald__contains', 'top', true);
185184
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
186185
nodeSep: 150, rankSep: 100,
187186
marginX: 100, marginY: 100,

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
var cell = new aclass({
161161
source: { id: source.id },
162162
target: { id: target.id },
163-
labels: [{ position: .5, attrs: { text: { text: label || '', 'font-weight': 'bold' } } }],
164163

165164
router: {
166165
name: 'manhattan',
@@ -175,33 +174,33 @@
175174
return cell;
176175
};
177176

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');
179177
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');
182178
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');
183179
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');
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');
185182
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');
187183
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');
188184
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');
185+
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');
186+
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');
187+
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');
191188
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);
189+
link(alocation, locref, 'bald__references');
190+
link(alocation, locref2, 'bald__references');
195191
link(anotherpair, anotherpair, 'bald__array', 'bottom');
196-
link(discovery, anotherpair, 'bald__contains', 'top', true);
197192
link(apair, anotherpair, 'bald__references');
193+
link(data, alocation, 'bald__references');
194+
link(discovery, anotherpair, 'bald__contains', 'top', true);
198195
link(discovery, apair, 'bald__contains', 'top', true);
199-
link(source, institution, 'bald__contains', 'top', true);
200196
link(discovery, source, 'bald__contains', 'top', true);
201-
link(root, discovery, 'bald__contains', 'top', true);
202197
link(referencing, locref, 'bald__contains', 'top', true);
203198
link(referencing, locref2, 'bald__contains', 'top', true);
199+
link(root, alocation, 'bald__contains', 'top', true);
200+
link(root, data, 'bald__contains', 'top', true);
201+
link(root, discovery, 'bald__contains', 'top', true);
204202
link(root, referencing, 'bald__contains', 'top', true);
203+
link(source, institution, 'bald__contains', 'top', true);
205204
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
206205
nodeSep: 150, rankSep: 100,
207206
marginX: 100, marginY: 100,

0 commit comments

Comments
 (0)