Skip to content

Commit f67cc50

Browse files
committed
adopt OGC Naming Authority
1 parent 45a390b commit f67cc50

15 files changed

+109
-82
lines changed

lib/bald/__init__.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def identity(self):
321321
if self.relative_id is None:
322322
result = None
323323
elif self.relative_id:
324-
result = '/'.join([self.baseuri, self.relative_id])
324+
result = self.baseuri + self.relative_id
325325
else:
326326
result = self.baseuri
327327
return result
@@ -599,8 +599,11 @@ def rdfgraph(self):
599599
600600
"""
601601
graph = rdflib.Graph()
602-
graph.bind('bald', 'http://def.binary-array-ld.net/development/')
603-
graph.bind('this', self.baseuri + '/')
602+
graph.bind('bald', 'https://www.opengis.net/def/binary-array-ld/')
603+
# why is a trailing slash added here?
604+
# should all identities of root groups include the trailing slash??
605+
## all include trailing slash
606+
graph.bind('this', self.baseuri)# + '/')
604607
for prefix_name in self.prefixes():
605608

606609
#strip the double underscore suffix
@@ -650,13 +653,13 @@ def graph_elems(self):
650653
alink = alink.format(var=self.identity, target=aref.identity)
651654
links.append(alink)
652655

653-
if hasattr(self, 'bald__array'):
654-
for aref in self.bald__array:
655-
if isinstance(aref, str):
656-
raise TypeError('unexpected string: {}'.format(aref))
657-
alink = "link({var}, {target}, 'bald__array', 'bottom');"
658-
alink = alink.format(var=self.identity, target=aref.identity)
659-
links.append(alink)
656+
# if hasattr(self, 'bald__array'):
657+
# for aref in self.bald__array:
658+
# if isinstance(aref, str):
659+
# raise TypeError('unexpected string: {}'.format(aref))
660+
# alink = "link({var}, {target}, 'bald__array', 'bottom');"
661+
# alink = alink.format(var=self.identity, target=aref.identity)
662+
# links.append(alink)
660663

661664

662665
return instances, links
@@ -762,8 +765,11 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
762765
cache = HttpCache()
763766

764767
with load(afilepath) as fhandle:
768+
# ensure that baseuri always temrinates in a '/'
765769
if baseuri is None:
766-
baseuri = 'file://{}'.format(afilepath)
770+
baseuri = 'file://{}/'.format(afilepath)
771+
elif type(baseuri) == str and not baseuri.endswith('/'):
772+
baseuri = '{}/'.format(baseuri)
767773
identity = baseuri
768774
prefix_var_name = None
769775
if hasattr(fhandle, 'bald__isPrefixedBy'):
@@ -786,7 +792,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
786792

787793
# check that default set is handled, i.e. bald__ and rdf__
788794
if 'bald__' not in prefixes:
789-
prefixes['bald__'] = "http://def.binary-array-ld.net/development/"
795+
prefixes['bald__'] = "https://www.opengis.net/def/binary-array-ld/"
790796

791797
if 'rdf__' not in prefixes:
792798
prefixes['rdf__'] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -832,7 +838,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
832838
# uri = 'http://def.scitools.org.uk/CFTerms?_format=ttl'
833839
# aliasgraph.parse(uri)
834840
# uri = 'http://vocab.nerc.ac.uk/standard_name/'
835-
# aliasgraph.parse(uri, format='xml')
841+
# aliasgraph.parse(uri, format='n3')
836842
# qstr = ('select ?alias ?uri where '
837843
# '{?uri dct:identifier ?alias .}')
838844
# qres = aliasgraph.query(qstr)
@@ -852,10 +858,10 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
852858
continue
853859

854860
sattrs = fhandle.variables[name].__dict__.copy()
855-
# inconsistent use of '/'; fix it
861+
856862
identity = name
857863
if baseuri is not None:
858-
identity = baseuri + "/" + name
864+
identity = baseuri + name
859865

860866
# netCDF coordinate variable special case
861867
if (len(fhandle.variables[name].dimensions) == 1 and
@@ -944,11 +950,11 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
944950
reference_prefixes = dict()
945951
reference_graph = copy.copy(aliasgraph)
946952

947-
response = cache['http://def.binary-array-ld.net/development']
948-
reference_graph.parse(data=response.text, format='xml')
953+
response = cache['https://www.opengis.net/def/binary-array-ld']
954+
reference_graph.parse(data=response.text, format='n3')
949955

950-
# # reference_graph.parse('http://binary-array-ld.net/latest?_format=ttl')
951-
# qstr = ('prefix bald: <http://binary-array-ld.net/latest/> '
956+
# # reference_graph.parse('https://www.opengis.net/def/binary-array-ld')
957+
# qstr = ('prefix bald: <https://www.opengis.net/def/binary-array-ld/> '
952958
# 'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
953959
# 'select ?s '
954960
# 'where { '
@@ -959,7 +965,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
959965

960966
# refs_ = reference_graph.query(qstr)
961967

962-
qstr = ('prefix bald: <http://def.binary-array-ld.net/development/> '
968+
qstr = ('prefix bald: <https://www.opengis.net/def/binary-array-ld/> '
963969
'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
964970
'prefix owl: <http://www.w3.org/2002/07/owl#> '
965971
'select ?s '
@@ -969,7 +975,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
969975
'filter(?rtype = owl:Class) '
970976
'}')
971977

972-
qstr = ('prefix bald: <http://def.binary-array-ld.net/development/> '
978+
qstr = ('prefix bald: <https://www.opengis.net/def/binary-array-ld/> '
973979
'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
974980
'prefix owl: <http://www.w3.org/2002/07/owl#> '
975981
'select ?s '
@@ -982,7 +988,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
982988

983989
non_ref_prefs = [str(ref[0]) for ref in list(refs)]
984990

985-
qstr = ('prefix bald: <http://def.binary-array-ld.net/development/> '
991+
qstr = ('prefix bald: <https://www.opengis.net/def/binary-array-ld/> '
986992
'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
987993
'prefix owl: <http://www.w3.org/2002/07/owl#> '
988994
'select ?s '
@@ -1013,7 +1019,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
10131019
baseuri, root_container,
10141020
file_variables, prefixes,
10151021
aliases, aliasgraph)
1016-
1022+
# import pdb; pdb.set_trace()
10171023
# for sattr in sattrs:
10181024
for sattr in (sattr for sattr in sattrs if
10191025
root_container.unpack_predicate(sattr) in ref_prefs):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ group: prefix_list {
2121
:DA__ = "https://codes.nws.noaa.gov/DataAssimilation" ;
2222
:NWP__ = "https://codes.nws.noaa.gov/NumericalWeatherPrediction" ;
2323
:StatPP__ = "https://codes.nws.noaa.gov/StatisticalPostProcessing" ;
24-
:bald__ = "http://binary-array-ld.net/latest/" ;
24+
:bald__ = "https://www.opengis.net/def/binary-array-ld/x" ;
2525

2626
} // group bald__prefix_list
2727
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dimensions:
44
pdim1 = 17 ;
55
variables:
66
int prefix_list ;
7-
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
7+
prefix_list:bald__ = "https://www.opengis.net/def/binary-array-ld/" ;
88
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
99
prefix_list:rdfs__ = "http://www.w3.org/2000/01/rdf-schema#" ;
1010
prefix_list:cf__ = "http://def.scitools.org.uk/CFTerms/" ;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dimensions:
44
pdim1 = 17 ;
55
variables:
66
int prefix_list ;
7-
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
7+
prefix_list:bald__ = "https://www.opengis.net/def/binary-array-ld/" ;
88
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
99
prefix_list:rdfs__ = "http://www.w3.org/2000/01/rdf-schema#" ;
1010
prefix_list:cf__ = "http://def.scitools.org.uk/CFTerms/" ;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ variables:
88
parent_variable:bald__references = "child_variable" ;
99
int child_variable(pdim0, pdim1) ;
1010
child_variable:rdf__type = "bald__Reference" ;
11-
child_variable:bald__array = "child_variable" ;
12-
int prefix_list ;
13-
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
11+
int prefix_list ;
12+
prefix_list:bald__ = "https://www.opengis.net/def/binary-array-ld/" ;
1413
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
1514

1615
// global attributes:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ variables:
128128

129129
group: prefix_list {
130130
// group attributes:
131-
:bald__ = "http://binary-array-ld.net/latest/" ;
131+
:bald__ = "https://www.opengis.net/def/binary-array-ld/" ;
132132
:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
133133
} // group bald__prefix_list
134134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dimensions:
44
pdim1 = 17 ;
55
variables:
66
int prefix_list ;
7-
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
7+
prefix_list:bald__ = "https://www.opengis.net/def/binary-array-ld/" ;
88
prefix_list:metce__ = "http://codes.wmo.int/common/observation-type/METCE/2013/" ;
99
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
1010

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
@prefix CFTerms: <http://def.scitools.org.uk/CFTerms/> .
22
@prefix NetCDF: <http://def.scitools.org.uk/NetCDF/> .
3-
@prefix bald: <http://binary-array-ld.net/latest/> .
3+
@prefix bald: <https://www.opengis.net/def/binary-array-ld/> .
44
@prefix cf_sname: <http://vocab.nerc.ac.uk/standard_name/> .
55
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
66
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
77
@prefix this: <file://CDL/GEMS_CO2_Apr2006.cdl/> .
88
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
99
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1010

11-
<file://CDL/GEMS_CO2_Apr2006.cdl> a bald:Container ;
11+
this: a bald:Container ;
12+
NetCDF:Conventions "CF-1.0" ;
1213
bald:contains this:co2,
1314
this:latitude,
1415
this:levelist,
1516
this:lnsp,
1617
this:longitude,
17-
this:time ;
18-
NetCDF:Conventions "CF-1.0" .
18+
this:time .
1919

2020
this:co2 a bald:Array ;
21+
CFTerms:missing_value "-32767" ;
22+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/mass_fraction_of_carbon_dioxide_in_air/> ;
23+
NetCDF:FillValue "-32767" ;
24+
NetCDF:add_offset 403.192219379918 ;
25+
NetCDF:long_name "Carbon Dioxide" ;
26+
NetCDF:scale_factor 0.000981685145029486 ;
27+
NetCDF:units "kg kg**-1" ;
2128
bald:references [ a bald:Reference ;
22-
bald:target this:latitude ;
23-
bald:targetReshape ( 1 1 181 1 ) ;
24-
bald:targetShape ( 181 ) ],
25-
[ a bald:Reference ;
2629
bald:target this:time ;
2730
bald:targetReshape ( 1 1 1 1 ) ;
2831
bald:targetShape ( 1 ) ],
@@ -33,62 +36,59 @@ this:co2 a bald:Array ;
3336
[ a bald:Reference ;
3437
bald:target this:levelist ;
3538
bald:targetReshape ( 1 60 1 1 ) ;
36-
bald:targetShape ( 60 ) ] ;
37-
bald:shape ( 1 60 181 360 ) ;
38-
CFTerms:missing_value "-32767" ;
39-
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/mass_fraction_of_carbon_dioxide_in_air/> ;
40-
NetCDF:FillValue "-32767" ;
41-
NetCDF:add_offset 403.192219379918 ;
42-
NetCDF:long_name "Carbon Dioxide" ;
43-
NetCDF:scale_factor 0.000981685145029486 ;
44-
NetCDF:units "kg kg**-1" .
39+
bald:targetShape ( 60 ) ],
40+
[ a bald:Reference ;
41+
bald:target this:latitude ;
42+
bald:targetReshape ( 1 1 181 1 ) ;
43+
bald:targetShape ( 181 ) ] ;
44+
bald:shape ( 1 60 181 360 ) .
4545

4646
this:lnsp a bald:Array ;
47+
CFTerms:missing_value "-32767" ;
48+
NetCDF:FillValue "-32767" ;
49+
NetCDF:add_offset 11.2087164280841 ;
50+
NetCDF:long_name "Logarithm of surface pressure" ;
4751
bald:references [ a bald:Reference ;
48-
bald:target this:levelist ;
49-
bald:targetReshape ( 1 60 1 1 ) ;
50-
bald:targetShape ( 60 ) ],
51-
[ a bald:Reference ;
5252
bald:target this:latitude ;
5353
bald:targetReshape ( 1 1 181 1 ) ;
5454
bald:targetShape ( 181 ) ],
5555
[ a bald:Reference ;
5656
bald:target this:time ;
5757
bald:targetReshape ( 1 1 1 1 ) ;
5858
bald:targetShape ( 1 ) ],
59+
[ a bald:Reference ;
60+
bald:target this:levelist ;
61+
bald:targetReshape ( 1 60 1 1 ) ;
62+
bald:targetShape ( 60 ) ],
5963
[ a bald:Reference ;
6064
bald:target this:longitude ;
6165
bald:targetReshape ( 1 1 1 360 ) ;
6266
bald:targetShape ( 360 ) ] ;
63-
bald:shape ( 1 60 181 360 ) ;
64-
CFTerms:missing_value "-32767" ;
65-
NetCDF:FillValue "-32767" ;
66-
NetCDF:add_offset 11.2087164280841 ;
67-
NetCDF:long_name "Logarithm of surface pressure" .
67+
bald:shape ( 1 60 181 360 ) .
6868

6969
this:latitude a bald:Array ;
70+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/latitude/> ;
71+
NetCDF:units "degrees_north" ;
7072
bald:first_value 90.0 ;
7173
bald:last_value -90.0 ;
72-
bald:shape ( 181 ) ;
73-
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/latitude/> ;
74-
NetCDF:units "degrees_north" .
74+
bald:shape ( 181 ) .
7575

7676
this:levelist a bald:Array ;
77+
NetCDF:long_name "model_level_number" ;
7778
bald:first_value 1 ;
7879
bald:last_value 60 ;
79-
bald:shape ( 60 ) ;
80-
NetCDF:long_name "model_level_number" .
80+
bald:shape ( 60 ) .
8181

8282
this:longitude a bald:Array ;
83+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/longitude/> ;
84+
NetCDF:units "degrees_east" ;
8385
bald:first_value 0.0 ;
8486
bald:last_value 359.0 ;
85-
bald:shape ( 360 ) ;
86-
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/longitude/> ;
87-
NetCDF:units "degrees_east" .
87+
bald:shape ( 360 ) .
8888

8989
this:time a bald:Array ;
90-
bald:first_value "2006-04-01T00:00:00"^^xsd:dateTime ;
91-
bald:shape ( 1 ) ;
9290
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/time/> ;
93-
NetCDF:units "hours since 1900-01-01 00:00:0.0" .
91+
NetCDF:units "hours since 1900-01-01 00:00:0.0" ;
92+
bald:first_value "2006-04-01T00:00:00"^^xsd:dateTime ;
93+
bald:shape ( 1 ) .
9494

lib/bald/tests/integration/test_aliases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def _fattrs(f):
1010
f.attrs['rdf__type'] = 'bald__Container'
1111
group_pref = f.create_group('prefix_list')
12-
group_pref.attrs['bald__'] = 'http://binary-array-ld.net/latest/'
12+
group_pref.attrs['bald__'] = 'https://www.opengis.net/def/binary-array-ld/'
1313
group_pref.attrs['rdf__'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
1414
f.attrs['bald__isPrefixedBy'] = group_pref.ref
1515
return f
@@ -55,8 +55,8 @@ def test_invalid_uri(self):
5555
validation = bald.validate_hdf5(tfile, cache=self.acache,
5656
uris_resolve=True)
5757
exns = validation.exceptions()
58-
expected = ['http://binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
59-
'http://binary-array-ld.net/latest/walnut is not resolving as a resource (404).']
58+
expected = ['http://def.binary-array-ld.net/latest/turtle is not resolving as a resource (404).',
59+
'http://def.binary-array-ld.net/latest/walnut is not resolving as a resource (404).']
6060
self.assertTrue((not validation.is_valid()) and exns == expected,
6161
msg='{} != {}'.format(exns, expected))
6262

lib/bald/tests/integration/test_cdl_rdfgraph.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import os
23
import subprocess
34
import unittest
@@ -17,13 +18,21 @@ def setUp(self):
1718
self.maxDiff = None
1819

1920
def check_result(self, result, expected):
21+
lbb = ('\n#######inBothResults#######\n')
2022
lbr = ('\n#######inTestResult#######\n')
2123
lbe = ('\n#######inExpected#######\n')
24+
lb = [lbb, lbr, lbe]
2225

2326
self.assertTrue(rdflib.compare.isomorphic(result, expected),
24-
lbr + lbe.join([g.serialize(format='n3').decode("utf-8") for g in
27+
''.join(list(itertools.chain(*zip(lb, [g.serialize(format='n3').decode("utf-8") for g in
2528
rdflib.compare.graph_diff(result,
26-
expected)[1:]]))
29+
# expected)[1:]]))
30+
expected)])))))
31+
32+
# lbr + lbe.join([g.serialize(format='n3').decode("utf-8") for g in
33+
# rdflib.compare.graph_diff(result,
34+
# # expected)[1:]]))
35+
# expected)]))
2736

2837

2938
def test_array_reference(self):

0 commit comments

Comments
 (0)