Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if spatial_text:
g.add((spatial_ref, SKOS.prefLabel, Literal(spatial_text)))
if spatial_geom:
# GeoJSON
g.add((spatial_ref,
LOCN.geometry,
Literal(spatial_geom, datatype=GEOJSON_IMT)))
# WKT, because GeoDCAT-AP says so
try:
g.add((spatial_ref,
LOCN.geometry,
Literal(wkt.dumps(json.loads(spatial_geom),
decimals=4),
datatype=GSP.wktLiteral)))
except (TypeError, ValueError, InvalidGeoJSONException):
pass
# License
license_id = self._get_dataset_value(dataset_dict, 'license_id', default='')
license_url = self._get_dataset_value(dataset_dict, 'license_url', default='')
license_title = self._get_dataset_value(dataset_dict, 'license_title', default='')
license = None
if license_id or license_url or license_title:
if license_url and bool(urlparse.urlparse(license_url).netloc):
license = URIRef(license_url)
else:
id_string = dataset_ref.n3() + DCT.license.n3() + license_id + license_url + license_title
bnode_hash = hashlib.sha1(id_string.encode('utf-8'))
license = BNode(bnode_hash.hexdigest())
# maybe a non-valid url
if license_url:
if spatial_text:
g.add((spatial_ref, SKOS.prefLabel, Literal(spatial_text)))
if spatial_geom:
# GeoJSON
g.add((spatial_ref,
LOCN.geometry,
Literal(spatial_geom, datatype=GEOJSON_IMT)))
# WKT, because GeoDCAT-AP says so
try:
g.add((spatial_ref,
LOCN.geometry,
Literal(wkt.dumps(json.loads(spatial_geom),
decimals=4),
datatype=GSP.wktLiteral)))
except (TypeError, ValueError, InvalidGeoJSONException):
pass
# License
license_id = self._get_dataset_value(dataset_dict, 'license_id')
license_url = self._get_dataset_value(dataset_dict, 'license_url')
license_title = self._get_dataset_value(dataset_dict, 'license_title')
license = None
if license_id or license_url or license_title:
if license_url and bool(urlparse.urlparse(license_url).netloc):
license = URIRef(license_url)
else:
license = BNode()
# maybe a non-valid url
if license_url:
g.add((license, RDFS.comment, Literal(license_url)))