2
2
import contextlib
3
3
import copy
4
4
from difflib import SequenceMatcher
5
+
5
6
import json
6
7
import operator
7
8
import os
19
20
import requests
20
21
import six
21
22
22
- from bald import datetime
23
+ from bald import datetime , distribution
23
24
import bald .validation as bv
24
25
25
- __version__ = '0.3'
26
-
26
+ __version__ = '0.3.1'
27
27
28
28
def _graph_html ():
29
29
return ('''<html>
@@ -216,7 +216,7 @@ def _network_js_close():
216
216
return (''' joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
217
217
nodeSep: 150, rankSep: 100,
218
218
marginX: 100, marginY: 100,
219
- rankDir: 'LR' });
219
+ rankDir: 'LR' });
220
220
221
221
222
222
for (var i = 0; i < instance_list.length; i++) {
@@ -542,17 +542,17 @@ def _dcat_location(self, graph, selfnode):
542
542
graph .bind ('dcat' , 'http://www.w3.org/ns/dcat#' )
543
543
graph .bind ('dct' , 'http://purl.org/dc/terms/' )
544
544
# template = ('dcat:distribution [
545
- # a dcat:Distribution;
546
- # dcat:downloadURL <{}>;
547
- # dcat:mediaType [
548
- # a dct:MediaType;
549
- # dct:identifier "application/x-netcdf"
550
- # ];
551
- # dct:format [
552
- # a dct:MediaType;
553
- # dct:identifier <http://vocab.nerc.ac.uk/collection/M01/current/NC/>
554
- # ]
555
- # ].')
545
+ # a dcat:Distribution;
546
+ # dcat:downloadURL <{}>;
547
+ # dcat:mediaType [
548
+ # a dct:MediaType;
549
+ # dct:identifier "application/x-netcdf"
550
+ # ];
551
+ # dct:format [
552
+ # a dct:MediaType;
553
+ # dct:identifier <http://vocab.nerc.ac.uk/collection/M01/current/NC/>
554
+ # ]
555
+ # ].')
556
556
dcatnode = rdflib .BNode ()
557
557
dcfnode = rdflib .BNode ()
558
558
graph .add ((selfnode , rdflib .URIRef ('http://www.w3.org/ns/dcat#distribution' ), dcatnode ))
@@ -561,12 +561,12 @@ def _dcat_location(self, graph, selfnode):
561
561
graph .add ((dcatnode , rdflib .URIRef ('http://www.w3.org/ns/dcat#downloadURL' ), rdflib .URIRef (self .file_locator )))
562
562
dcatmednode = rdflib .BNode ()
563
563
graph .add ((dcatmednode , rdflib .namespace .RDF .type , rdflib .URIRef ('http://www.w3.org/ns/dcat#MediaType' )))
564
- graph .add ((dcatmednode , rdflib .URIRef ('http://purl.org/dc/terms/identifier' ), rdflib .Literal ('application/x-netcdf' )))
564
+ graph .add ((dcatmednode , rdflib .URIRef ('http://purl.org/dc/terms/identifier' ), rdflib .Literal (distribution . BaldDistributionEnum . MIME_TYPE . value )))
565
565
graph .add ((dcatnode , rdflib .URIRef ('http://www.w3.org/ns/dcat#mediaType' ), dcatmednode ))
566
566
567
567
graph .add ((dcfnode , rdflib .namespace .RDF .type , rdflib .URIRef ('http://purl.org/dc/terms/MediaType' )))
568
568
graph .add ((dcfnode , rdflib .URIRef ('http://purl.org/dc/terms/identifier' ),
569
- rdflib .URIRef ('http://vocab.nerc.ac.uk/collection/M01/current/NC/' )))
569
+ rdflib .URIRef (distribution . BaldDistributionEnum . LINKED_DATA_RESOURCE_DEFINING_NETCDF . value )))
570
570
graph .add ((selfnode , rdflib .URIRef ('http://purl.org/dc/terms/format' ), dcfnode ))
571
571
572
572
@@ -1456,7 +1456,51 @@ def _hdf_references(fhandle, root_container, file_variables):
1456
1456
if isinstance (member , Container ):
1457
1457
_hdf_references (fhandle , member , file_variables )
1458
1458
1459
-
1460
-
1461
-
1459
+ class schemaOrg :
1460
+ __schemaGraph = rdflib .Graph ()
1461
+ __so = rdflib .Namespace ("http://schema.org/" )
1462
+ __baldGraph = None
1463
+
1464
+ def __init__ (self , graph , path = None , baseuri = None ):
1465
+ """
1466
+ Export a Schema.org graph for a BALD graph
1467
+
1468
+ Required inputs -
1469
+ graph a BALD Graph URI
1470
+ path
1471
+ baseuri a URI string or None
1472
+
1473
+ Returns a rdflib graph of Schema,org content
1474
+ """
1475
+ if baseuri is not None :
1476
+ container = rdflib .URIRef (baseuri )
1477
+ else :
1478
+ container = rdflib .BNode ()
1479
+ self .__baldGraph = graph
1480
+ self .__schemaGraph .add ( (container , rdflib .URIRef ("http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ), self .__so .Dataset ) )
1481
+
1482
+ self .__distribution (container , path )
1483
+
1484
+
1485
+ def __distribution (self , container , path ):
1486
+ """
1487
+ Export a Schema.org distribution
1488
+
1489
+ Required inputs -
1490
+ container a bald Container URI
1491
+ path a URI string or None
1492
+
1493
+
1494
+ """
1495
+
1496
+ distributionNode = rdflib .BNode ()
1497
+ self .__schemaGraph .add ( (container , self .__so .distribution , distributionNode ) )
1498
+ self .__schemaGraph .add ( (distributionNode , rdflib .RDF .type , self .__so .DataDownload ) )
1499
+ self .__schemaGraph .add ( (distributionNode , self .__so .encodingFormat , rdflib .Literal (distribution .BaldDistributionEnum .MIME_TYPE .value )) )
1500
+ self .__schemaGraph .add ( (distributionNode , self .__so .encodingFormat , rdflib .URIRef (distribution .BaldDistributionEnum .LINKED_DATA_RESOURCE_DEFINING_NETCDF .value )) )
1501
+ if path is not None :
1502
+ self .__schemaGraph .add ( (distributionNode , self .__so .contentUrl , rdflib .URIRef (path )) )
1503
+ return None
1462
1504
1505
+ def getSchemaOrgGraph (self ):
1506
+ return self .__schemaGraph
0 commit comments