Skip to content

Commit 7fc68df

Browse files
committed
tidy up blank nodes: no copies
1 parent dd8dd1e commit 7fc68df

File tree

8 files changed

+159
-210
lines changed

8 files changed

+159
-210
lines changed

lib/bald/__init__.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -553,19 +553,13 @@ def rdfnode(self, graph):
553553
if not (isinstance(objs, set) or isinstance(objs, list)):
554554
objs = set([objs])
555555
for obj in objs:
556-
if isinstance(obj, Subject):
557-
if obj.identity is None:
558-
node = obj.rdfnode(graph)
559-
else:
560-
obj_ref = rdflib.URIRef(obj.identity)
561-
if (obj_ref, None, None) not in graph:
562-
node = obj.rdfnode(graph)
563-
else:
564-
node = obj_ref
565556

566557
rdfpred = self.unpack_predicate(attr)
567558
if isinstance(obj, Subject):
568-
rdfobj = node #rdflib.URIRef(obj.identity)
559+
if obj.identity is None:
560+
rdfobj = obj.rdfnode(graph)
561+
else:
562+
rdfobj = rdflib.URIRef(obj.identity)
569563
else:
570564
rdfobj = self.unpack_rdfobject(obj, rdfpred)
571565
if is_http_uri(rdfobj):
@@ -587,6 +581,11 @@ def rdfnode(self, graph):
587581
#graph.add((selfnode, rdfpred, rdfobj))
588582
elif isinstance(objs, list):
589583
list_items.append(rdfobj)
584+
# recurse and build the related objects
585+
if isinstance(obj, Subject) and obj.identity is not None:
586+
obj_ref = rdflib.URIRef(obj.identity)
587+
if not ((obj_ref, None, None) in graph):
588+
node = obj.rdfnode(graph)
590589
if list_items:
591590
list_name = rdflib.BNode()
592591
col = rdflib.collection.Collection(graph, list_name, list_items)
@@ -1006,6 +1005,15 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
10061005
var = file_variables[name]
10071006
sattrs = fhandle.variables[name].__dict__.copy()
10081007

1008+
# coordinate variables are bald__references too
1009+
if 'bald__Reference' not in var.rdf__type:
1010+
for dim in fhandle.variables[name].dimensions:
1011+
if file_variables.get(dim) and name != dim:
1012+
_make_ref_entities(var, fhandle, dim, name,
1013+
baseuri, root_container,
1014+
file_variables, prefixes,
1015+
aliases, aliasgraph)
1016+
10091017
# for sattr in sattrs:
10101018
for sattr in (sattr for sattr in sattrs if
10111019
root_container.unpack_predicate(sattr) in ref_prefs):
@@ -1034,21 +1042,13 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
10341042
var.attrs[sattr] = set([file_variables.get(pref)
10351043
for pref in potrefs_set])
10361044
for pref in potrefs_set:
1037-
_make_ref_entities(var, fhandle,
1038-
pref, name, baseuri,
1039-
root_container,
1040-
file_variables, prefixes,
1041-
aliases, aliasgraph)
1042-
1043-
1044-
# coordinate variables are bald__references too
1045-
if 'bald__Reference' not in var.rdf__type:
1046-
for dim in fhandle.variables[name].dimensions:
1047-
if file_variables.get(dim) and name != dim:
1048-
_make_ref_entities(var, fhandle, dim, name,
1049-
baseuri, root_container,
1050-
file_variables, prefixes,
1051-
aliases, aliasgraph)
1045+
# coordinate variables already handled
1046+
if pref not in fhandle.variables[name].dimensions:
1047+
_make_ref_entities(var, fhandle,
1048+
pref, name, baseuri,
1049+
root_container,
1050+
file_variables, prefixes,
1051+
aliases, aliasgraph)
10521052

10531053
return root_container
10541054

@@ -1062,7 +1062,8 @@ def _make_ref_entities(var, fhandle, pref, name, baseuri,
10621062
fhandle.variables[pref].shape):
10631063
try:
10641064
refset = var.attrs.get('bald__references', set())
1065-
1065+
if not isinstance(refset, set):
1066+
refset = set((refset,))
10661067
identity = None
10671068
rattrs = {}
10681069

lib/bald/tests/integration/CDL/GEMS_CO2_Apr2006.cdl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ variables:
2525
co2:long_name = "Carbon Dioxide" ;
2626
co2:standard_name = "mass_fraction_of_carbon_dioxide_in_air" ;
2727
short lnsp(time, levelist, latitude, longitude) ;
28-
lnsp:scale_factor = 1.03952457840347e-05 ;
2928
lnsp:add_offset = 11.2087164280841 ;
3029
lnsp:_FillValue = -32767s ;
3130
lnsp:missing_value = -32767s ;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,8 @@
191191
link(file://CDL/multi_array_reference.cdl, file://CDL/multi_array_reference.cdl/pdim0, 'bald__contains', 'top', true);
192192
link(file://CDL/multi_array_reference.cdl, file://CDL/multi_array_reference.cdl/pdim1, 'bald__contains', 'top', true);
193193
link(file://CDL/multi_array_reference.cdl, file://CDL/multi_array_reference.cdl/set_collection, 'bald__contains', 'top', true);
194-
link(file://CDL/multi_array_reference.cdl/data_variable1, None, 'bald__references');
195-
link(file://CDL/multi_array_reference.cdl/data_variable1, None, 'bald__references');
196194
link(file://CDL/multi_array_reference.cdl/data_variable1, file://CDL/multi_array_reference.cdl/location_variable, 'bald__references');
197-
link(file://CDL/multi_array_reference.cdl/data_variable2, None, 'bald__references');
198-
link(file://CDL/multi_array_reference.cdl/data_variable2, None, 'bald__references');
199195
link(file://CDL/multi_array_reference.cdl/data_variable2, file://CDL/multi_array_reference.cdl/location_variable, 'bald__references');
200-
link(file://CDL/multi_array_reference.cdl/location_variable, None, 'bald__references');
201-
link(file://CDL/multi_array_reference.cdl/location_variable, None, 'bald__references');
202196
link(file://CDL/multi_array_reference.cdl/location_variable, file://CDL/multi_array_reference.cdl/location_reference_system, 'bald__references');
203197
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
204198
nodeSep: 150, rankSep: 100,

lib/bald/tests/integration/TTL/GEMS_CO2_Apr2006.ttl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,26 @@ this:co2 a bald:Array ;
4545

4646
this:lnsp a bald:Array ;
4747
bald:references [ a bald:Reference ;
48-
bald:target this:longitude ;
49-
bald:targetReshape ( 1 1 1 360 ) ;
50-
bald:targetShape ( 360 ) ],
48+
bald:target this:levelist ;
49+
bald:targetReshape ( 1 60 1 1 ) ;
50+
bald:targetShape ( 60 ) ],
5151
[ a bald:Reference ;
5252
bald:target this:latitude ;
5353
bald:targetReshape ( 1 1 181 1 ) ;
5454
bald:targetShape ( 181 ) ],
55-
[ a bald:Reference ;
56-
bald:target this:levelist ;
57-
bald:targetReshape ( 1 60 1 1 ) ;
58-
bald:targetShape ( 60 ) ],
5955
[ a bald:Reference ;
6056
bald:target this:time ;
6157
bald:targetReshape ( 1 1 1 1 ) ;
62-
bald:targetShape ( 1 ) ] ;
58+
bald:targetShape ( 1 ) ],
59+
[ a bald:Reference ;
60+
bald:target this:longitude ;
61+
bald:targetReshape ( 1 1 1 360 ) ;
62+
bald:targetShape ( 360 ) ] ;
6363
bald:shape ( 1 60 181 360 ) ;
6464
CFTerms:missing_value "-32767" ;
6565
NetCDF:FillValue "-32767" ;
6666
NetCDF:add_offset 11.2087164280841 ;
67-
NetCDF:long_name "Logarithm of surface pressure" ;
68-
NetCDF:scale_factor 1.03952457840347e-05 .
67+
NetCDF:long_name "Logarithm of surface pressure" .
6968

7069
this:latitude a bald:Array ;
7170
bald:first_value 90.0 ;

lib/bald/tests/integration/TTL/ereefs_gbr4_ncld.ttl

Lines changed: 38 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ this:eta a bald:Array ;
5151
bald:target this:time ;
5252
bald:targetReshape ( 5 1 1 ) ;
5353
bald:targetShape ( 5 ) ],
54-
[ a bald:Reference ;
55-
bald:target this:time ;
56-
bald:targetReshape ( 5 1 1 ) ;
57-
bald:targetShape ( 5 ) ],
5854
[ a bald:Reference ;
5955
bald:target this:longitude ;
6056
bald:targetReshape ( 1 180 600 ) ;
@@ -80,25 +76,21 @@ this:salt a bald:Array ;
8076
this:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
8177
this:unit_id <http://environment.data.gov.au/water/quality/def/unit/PSU> ;
8278
bald:references [ a bald:Reference ;
83-
bald:target this:time ;
84-
bald:targetReshape ( 5 1 1 1 ) ;
85-
bald:targetShape ( 5 ) ],
79+
bald:target this:latitude ;
80+
bald:targetReshape ( 1 1 180 600 ) ;
81+
bald:targetShape ( 180 600 ) ],
8682
[ a bald:Reference ;
8783
bald:target this:zc ;
8884
bald:targetReshape ( 1 47 1 1 ) ;
8985
bald:targetShape ( 47 ) ],
9086
[ a bald:Reference ;
91-
bald:target this:latitude ;
92-
bald:targetReshape ( 1 1 180 600 ) ;
93-
bald:targetShape ( 180 600 ) ],
87+
bald:target this:time ;
88+
bald:targetReshape ( 5 1 1 1 ) ;
89+
bald:targetShape ( 5 ) ],
9490
[ a bald:Reference ;
9591
bald:target this:longitude ;
9692
bald:targetReshape ( 1 1 180 600 ) ;
97-
bald:targetShape ( 180 600 ) ],
98-
[ a bald:Reference ;
99-
bald:target this:time ;
100-
bald:targetReshape ( 5 1 1 1 ) ;
101-
bald:targetShape ( 5 ) ] ;
93+
bald:targetShape ( 180 600 ) ] ;
10294
bald:shape ( 5 47 180 600 ) ;
10395
CFTerms:coordinates this:latitude,
10496
this:longitude,
@@ -114,25 +106,21 @@ this:temp a bald:Array ;
114106
this:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
115107
this:unit_id <http://qudt.org/vocab/unit#DegreeCelsius> ;
116108
bald:references [ a bald:Reference ;
117-
bald:target this:zc ;
118-
bald:targetReshape ( 1 47 1 1 ) ;
119-
bald:targetShape ( 47 ) ],
120-
[ a bald:Reference ;
121-
bald:target this:time ;
122-
bald:targetReshape ( 5 1 1 1 ) ;
123-
bald:targetShape ( 5 ) ],
109+
bald:target this:latitude ;
110+
bald:targetReshape ( 1 1 180 600 ) ;
111+
bald:targetShape ( 180 600 ) ],
124112
[ a bald:Reference ;
125113
bald:target this:time ;
126114
bald:targetReshape ( 5 1 1 1 ) ;
127115
bald:targetShape ( 5 ) ],
128116
[ a bald:Reference ;
129-
bald:target this:latitude ;
117+
bald:target this:longitude ;
130118
bald:targetReshape ( 1 1 180 600 ) ;
131119
bald:targetShape ( 180 600 ) ],
132120
[ a bald:Reference ;
133-
bald:target this:longitude ;
134-
bald:targetReshape ( 1 1 180 600 ) ;
135-
bald:targetShape ( 180 600 ) ] ;
121+
bald:target this:zc ;
122+
bald:targetReshape ( 1 47 1 1 ) ;
123+
bald:targetShape ( 47 ) ] ;
136124
bald:shape ( 5 47 180 600 ) ;
137125
CFTerms:coordinates this:latitude,
138126
this:longitude,
@@ -151,21 +139,17 @@ this:u a bald:Array ;
151139
this:vector_components "u v" ;
152140
this:vector_name "Currents" ;
153141
bald:references [ a bald:Reference ;
154-
bald:target this:zc ;
155-
bald:targetReshape ( 1 47 1 1 ) ;
156-
bald:targetShape ( 47 ) ],
157-
[ a bald:Reference ;
158-
bald:target this:time ;
159-
bald:targetReshape ( 5 1 1 1 ) ;
160-
bald:targetShape ( 5 ) ],
161-
[ a bald:Reference ;
162142
bald:target this:latitude ;
163143
bald:targetReshape ( 1 1 180 600 ) ;
164144
bald:targetShape ( 180 600 ) ],
165145
[ a bald:Reference ;
166146
bald:target this:longitude ;
167147
bald:targetReshape ( 1 1 180 600 ) ;
168148
bald:targetShape ( 180 600 ) ],
149+
[ a bald:Reference ;
150+
bald:target this:zc ;
151+
bald:targetReshape ( 1 47 1 1 ) ;
152+
bald:targetShape ( 47 ) ],
169153
[ a bald:Reference ;
170154
bald:target this:time ;
171155
bald:targetReshape ( 5 1 1 1 ) ;
@@ -189,25 +173,21 @@ this:v a bald:Array ;
189173
this:vector_components "u v" ;
190174
this:vector_name "Currents" ;
191175
bald:references [ a bald:Reference ;
192-
bald:target this:longitude ;
176+
bald:target this:latitude ;
193177
bald:targetReshape ( 1 1 180 600 ) ;
194178
bald:targetShape ( 180 600 ) ],
195179
[ a bald:Reference ;
196-
bald:target this:time ;
197-
bald:targetReshape ( 5 1 1 1 ) ;
198-
bald:targetShape ( 5 ) ],
199-
[ a bald:Reference ;
200-
bald:target this:time ;
201-
bald:targetReshape ( 5 1 1 1 ) ;
202-
bald:targetShape ( 5 ) ],
180+
bald:target this:zc ;
181+
bald:targetReshape ( 1 47 1 1 ) ;
182+
bald:targetShape ( 47 ) ],
203183
[ a bald:Reference ;
204-
bald:target this:latitude ;
184+
bald:target this:longitude ;
205185
bald:targetReshape ( 1 1 180 600 ) ;
206186
bald:targetShape ( 180 600 ) ],
207187
[ a bald:Reference ;
208-
bald:target this:zc ;
209-
bald:targetReshape ( 1 47 1 1 ) ;
210-
bald:targetShape ( 47 ) ] ;
188+
bald:target this:time ;
189+
bald:targetReshape ( 5 1 1 1 ) ;
190+
bald:targetShape ( 5 ) ] ;
211191
bald:shape ( 5 47 180 600 ) ;
212192
CFTerms:coordinates this:latitude,
213193
this:longitude,
@@ -221,19 +201,15 @@ this:v a bald:Array ;
221201

222202
this:wspeed_u a bald:Array ;
223203
bald:references [ a bald:Reference ;
224-
bald:target this:longitude ;
204+
bald:target this:latitude ;
225205
bald:targetReshape ( 1 180 600 ) ;
226206
bald:targetShape ( 180 600 ) ],
227207
[ a bald:Reference ;
228208
bald:target this:time ;
229209
bald:targetReshape ( 5 1 1 ) ;
230210
bald:targetShape ( 5 ) ],
231211
[ a bald:Reference ;
232-
bald:target this:time ;
233-
bald:targetReshape ( 5 1 1 ) ;
234-
bald:targetShape ( 5 ) ],
235-
[ a bald:Reference ;
236-
bald:target this:latitude ;
212+
bald:target this:longitude ;
237213
bald:targetReshape ( 1 180 600 ) ;
238214
bald:targetShape ( 180 600 ) ] ;
239215
bald:shape ( 5 180 600 ) ;
@@ -250,18 +226,14 @@ this:wspeed_v a bald:Array ;
250226
bald:target this:time ;
251227
bald:targetReshape ( 5 1 1 ) ;
252228
bald:targetShape ( 5 ) ],
253-
[ a bald:Reference ;
254-
bald:target this:longitude ;
255-
bald:targetReshape ( 1 180 600 ) ;
256-
bald:targetShape ( 180 600 ) ],
257229
[ a bald:Reference ;
258230
bald:target this:latitude ;
259231
bald:targetReshape ( 1 180 600 ) ;
260232
bald:targetShape ( 180 600 ) ],
261233
[ a bald:Reference ;
262-
bald:target this:time ;
263-
bald:targetReshape ( 5 1 1 ) ;
264-
bald:targetShape ( 5 ) ] ;
234+
bald:target this:longitude ;
235+
bald:targetReshape ( 1 180 600 ) ;
236+
bald:targetShape ( 180 600 ) ] ;
265237
bald:shape ( 5 180 600 ) ;
266238
CFTerms:coordinates this:latitude,
267239
this:longitude,
@@ -279,6 +251,13 @@ this:zc a bald:Array ;
279251
NetCDF:long_name "Z coordinate" ;
280252
NetCDF:units "m" .
281253

254+
this:time a bald:Array ;
255+
this:coordinate_type "time" ;
256+
bald:shape ( 5 ) ;
257+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/time/> ;
258+
NetCDF:long_name "Time" ;
259+
NetCDF:units "days since 1990-01-01 00:00:00 +10" .
260+
282261
this:latitude a bald:Array ;
283262
this:coordinate_type "latitude" ;
284263
this:projection "geographic" ;
@@ -295,10 +274,3 @@ this:longitude a bald:Array ;
295274
NetCDF:long_name "Longitude" ;
296275
NetCDF:units "degrees_east" .
297276

298-
this:time a bald:Array ;
299-
this:coordinate_type "time" ;
300-
bald:shape ( 5 ) ;
301-
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/time/> ;
302-
NetCDF:long_name "Time" ;
303-
NetCDF:units "days since 1990-01-01 00:00:00 +10" .
304-

0 commit comments

Comments
 (0)