Python rdflib.namespace.RDF.type() Examples
The following are 30
code examples of rdflib.namespace.RDF.type().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rdflib.namespace.RDF
, or try the search function
.
Example #1
Source File: helpers.py From pySHACL with Apache License 2.0 | 6 votes |
def __init__(self, node, sht_graph, result_node, data_graph, shapes_graph, label=None, status=None): """ :param sht_graph: :type sht_graph: rdflib.Graph :param data_graph: :type data_graph: rdflib.Graph :param shapes_graph: :type shapes_graph: rdflib.Graph :param label: """ self.node = node self.sht_graph = sht_graph self.sht_result = result_node self.data_graph = data_graph self.shapes_graph = shapes_graph self.label = label self.status = status
Example #2
Source File: datatypes.py From arches with GNU Affero General Public License v3.0 | 6 votes |
def validate(self, value, row_number=None, source="", node=None, nodeid=None): errors = [] try: if value == "": value = None if value is not None: decimal.Decimal(value) except Exception: dt = self.datatype_model.datatype errors.append( { "type": "ERROR", "message": "datatype: {0}, value: {1} {2} {3} - {4}. {5}".format( dt, value, source, row_number, "not a properly formatted number", "This data was not saved." ), } ) return errors
Example #3
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_spatial_uri_only(self): g = Graph() dataset = URIRef('http://example.org/datasets/1') g.add((dataset, RDF.type, DCAT.Dataset)) spatial_uri = URIRef('http://geonames/Newark') g.add((dataset, DCT.spatial, spatial_uri)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] extras = self._extras(datasets[0]) eq_(extras['spatial_uri'], 'http://geonames/Newark') assert_true('spatial_text' not in extras) assert_true('spatial' not in extras)
Example #4
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_spatial_literal_only(self): g = Graph() dataset = URIRef('http://example.org/datasets/1') g.add((dataset, RDF.type, DCAT.Dataset)) g.add((dataset, DCT.spatial, Literal('Newark'))) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] extras = self._extras(datasets[0]) eq_(extras['spatial_text'], 'Newark') assert_true('spatial_uri' not in extras) assert_true('spatial' not in extras)
Example #5
Source File: test_euro_dcatap_profile_serialize.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_publisher_org(self): dataset = { 'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6', 'name': 'test-dataset', 'organization': { 'id': '', 'name': 'publisher1', 'title': 'Example Publisher from Org', } } s = RDFSerializer() g = s.g dataset_ref = s.graph_from_dataset(dataset) publisher = self._triple(g, dataset_ref, DCT.publisher, None)[2] assert publisher assert self._triple(g, publisher, RDF.type, FOAF.Organization) assert self._triple(g, publisher, FOAF.name, dataset['organization']['title'])
Example #6
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_spatial_wkt_only(self): g = Graph() dataset = URIRef('http://example.org/datasets/1') g.add((dataset, RDF.type, DCAT.Dataset)) spatial_uri = URIRef('http://geonames/Newark') g.add((dataset, DCT.spatial, spatial_uri)) g.add((spatial_uri, RDF.type, DCT.Location)) g.add((spatial_uri, LOCN.geometry, Literal('POINT (67 89)', datatype=GSP.wktLiteral))) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] extras = self._extras(datasets[0]) # NOTE: geomet returns floats for coordinates on WKT -> GeoJSON eq_(extras['spatial'], '{"type": "Point", "coordinates": [67.0, 89.0]}')
Example #7
Source File: test_euro_dcatap_profile_serialize.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_publisher_no_uri(self): dataset = { 'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6', 'name': 'test-dataset', 'extras': [ {'key': 'publisher_name', 'value': 'Example Publisher'}, ] } extras = self._extras(dataset) s = RDFSerializer() g = s.g dataset_ref = s.graph_from_dataset(dataset) publisher = self._triple(g, dataset_ref, DCT.publisher, None)[2] assert publisher assert_true(isinstance(publisher, BNode)) assert self._triple(g, publisher, RDF.type, FOAF.Organization) assert self._triple(g, publisher, FOAF.name, extras['publisher_name'])
Example #8
Source File: test_euro_dcatap_profile_serialize.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_temporal(self): dataset = { 'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6', 'name': 'test-dataset', 'extras': [ {'key': 'temporal_start', 'value': '2015-06-26T15:21:09.075774'}, {'key': 'temporal_end', 'value': '2015-07-14'}, ] } extras = self._extras(dataset) s = RDFSerializer() g = s.g dataset_ref = s.graph_from_dataset(dataset) temporal = self._triple(g, dataset_ref, DCT.temporal, None)[2] assert temporal assert self._triple(g, temporal, RDF.type, DCT.PeriodOfTime) assert self._triple(g, temporal, SCHEMA.startDate, parse_date(extras['temporal_start']).isoformat(), XSD.dateTime) assert self._triple(g, temporal, SCHEMA.endDate, parse_date(extras['temporal_end']).isoformat(), XSD.dateTime)
Example #9
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_format_normalized(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.mediaType, Literal('text/csv'))) g.add((distribution1_1, DCT['format'], Literal('Comma Separated Values'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] if toolkit.check_ckan_version(min_version='2.3'): eq_(resource['format'], u'CSV') eq_(resource['mimetype'], u'text/csv') else: eq_(resource['format'], u'Comma Separated Values')
Example #10
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_unknown_imt(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.mediaType, Literal('text/unknown-imt'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['format'], u'text/unknown-imt') eq_(resource['mimetype'], u'text/unknown-imt')
Example #11
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_format_only_normalize_false(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCT['format'], Literal('CSV'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['format'], u'CSV') assert 'mimetype' not in resource
Example #12
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_imt_only_normalize_false(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.mediaType, Literal('text/csv'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['format'], u'text/csv') eq_(resource['mimetype'], u'text/csv')
Example #13
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_imt_only(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.mediaType, Literal('text/csv'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] if toolkit.check_ckan_version(min_version='2.3'): eq_(resource['format'], u'CSV') eq_(resource['mimetype'], u'text/csv') else: eq_(resource['format'], u'text/csv')
Example #14
Source File: test_euro_dcatap_profile_serialize.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_graph_from_catalog_dict(self): catalog_dict = { 'title': 'My Catalog', 'description': 'An Open Data Catalog', 'homepage': 'http://example.com', 'language': 'de', } s = RDFSerializer() g = s.g catalog = s.graph_from_catalog(catalog_dict) eq_(unicode(catalog), utils.catalog_uri()) # Basic fields assert self._triple(g, catalog, RDF.type, DCAT.Catalog) assert self._triple(g, catalog, DCT.title, catalog_dict['title']) assert self._triple(g, catalog, DCT.description, catalog_dict['description']) assert self._triple(g, catalog, FOAF.homepage, URIRef(catalog_dict['homepage'])) assert self._triple(g, catalog, DCT.language, catalog_dict['language'])
Example #15
Source File: helpers.py From pySHACL with Apache License 2.0 | 6 votes |
def __init__(self, base, sht_graph, node, includes, entries=None, label=None): """ Manifest constructor :param base: string :type base: the "file://x" location uri of the base manifest graph :param sht_graph: :type sht_graph: rdflib.Graph :param node: The Graph Node of the manifest itself. (unused) :type node: rdflib.term.Identifier :param includes: :type includes: list(Manifest) :param entries: :type entries: list | None :param label: """ self.base = base self.sht_graph = sht_graph self.node = node self.includes = includes self.entries = entries self.label = label
Example #16
Source File: datatypes.py From arches with GNU Affero General Public License v3.0 | 6 votes |
def to_rdf(self, edge_info, edge): g = Graph() def _add_resource(d, p, r, r_type): if r_type is not None: g.add((r, RDF.type, URIRef(r_type))) g.add((d, URIRef(p), r)) if edge_info["range_tile_data"] is not None: res_insts = edge_info["range_tile_data"] if not isinstance(res_insts, list): res_insts = [res_insts] for res_inst in res_insts: rangenode = self.get_rdf_uri(None, res_inst) try: res_inst_obj = models.ResourceInstance.objects.get(pk=res_inst["resourceId"]) r_type = res_inst_obj.graph.node_set.get(istopnode=True).ontologyclass except models.ResourceInstance.DoesNotExist: # This should never happen excpet if trying to export when the # referenced resource hasn't been saved to the database yet r_type = edge.rangenode.ontologyclass _add_resource(edge_info["d_uri"], edge.ontologyproperty, rangenode, r_type) return g
Example #17
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_dataset_license_from_distribution_by_uri(self): # license_id retrieved from the URI of dcat:license object g = Graph() dataset = URIRef("http://example.org/datasets/1") g.add((dataset, RDF.type, DCAT.Dataset)) distribution = URIRef("http://example.org/datasets/1/ds/1") g.add((dataset, DCAT.distribution, distribution)) g.add((distribution, RDF.type, DCAT.Distribution)) g.add((distribution, DCT.license, URIRef("http://www.opendefinition.org/licenses/cc-by"))) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g dataset = [d for d in p.datasets()][0] eq_(dataset['license_id'], 'cc-by')
Example #18
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_dataset_license_from_distribution_by_title(self): # license_id retrieved from dct:title of dcat:license object g = Graph() dataset = URIRef("http://example.org/datasets/1") g.add((dataset, RDF.type, DCAT.Dataset)) distribution = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution, RDF.type, DCAT.Distribution)) g.add((dataset, DCAT.distribution, distribution)) license = BNode() g.add((distribution, DCT.license, license)) g.add((license, DCT.title, Literal("Creative Commons Attribution"))) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g dataset = [d for d in p.datasets()][0] eq_(dataset['license_id'], 'cc-by')
Example #19
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_access_url(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.accessURL, Literal('http://access.url.org'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['url'], u'http://access.url.org') assert 'download_url' not in resource
Example #20
Source File: datatypes.py From arches with GNU Affero General Public License v3.0 | 6 votes |
def validate(self, value, row_number=None, source="", node=None, nodeid=None): errors = [] if value is not None: resourceXresourceIds = self.get_id_list(value) for resourceXresourceId in resourceXresourceIds: resourceid = resourceXresourceId["resourceId"] try: models.ResourceInstance.objects.get(pk=resourceid) except ObjectDoesNotExist: errors.append( { "type": "WARNING", "message": f"The resource id: {resourceid} does not exist in the system. The data for this card will \ be available in the system once resource {resourceid} is loaded.", } ) return errors
Example #21
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_download_url(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.downloadURL, Literal('http://download.url.org'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['url'], u'http://download.url.org') eq_(resource['download_url'], u'http://download.url.org')
Example #22
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_both_access_and_download_url(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCAT.accessURL, Literal('http://access.url.org'))) g.add((distribution1_1, DCAT.downloadURL, Literal('http://download.url.org'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['url'], u'http://access.url.org') eq_(resource['download_url'], u'http://download.url.org')
Example #23
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 6 votes |
def test_distribution_format_format_only(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCT['format'], Literal('CSV'))) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['format'], u'CSV')
Example #24
Source File: datatypes.py From arches with GNU Affero General Public License v3.0 | 6 votes |
def get_rdf_uri(self, node, data, which="r"): if type(data) == list: l = [] for x in data: if x["url"].startswith("/"): l.append(URIRef(archesproject[x["url"][1:]])) else: l.append(URIRef(archesproject[x["url"]])) return l elif data: if data["url"].startswith("/"): return URIRef(archesproject[data["url"][1:]]) else: return URIRef(archesproject[data["url"]]) else: return node
Example #25
Source File: profiles.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
def _datasets(self): ''' Generator that returns all DCAT datasets on the graph Yields rdflib.term.URIRef objects that can be used on graph lookups and queries ''' for dataset in self.g.subjects(RDF.type, DCAT.Dataset): yield dataset
Example #26
Source File: add-properties2turtle.py From dipper with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_property_to_graph(results, graph, property_type, property_list): for row in results: if row in property_list: graph.add((row, RDF['type'], property_type)) return graph
Example #27
Source File: profiles.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
def graph_from_catalog(self, catalog_dict, catalog_ref): g = self.g for prefix, namespace in namespaces.iteritems(): g.bind(prefix, namespace) g.add((catalog_ref, RDF.type, DCAT.Catalog)) # Basic fields items = [ ('title', DCT.title, config.get('ckan.site_title'), Literal), ('description', DCT.description, config.get('ckan.site_description'), Literal), ('homepage', FOAF.homepage, config.get('ckan.site_url'), URIRef), ('language', DCT.language, config.get('ckan.locale_default', 'en'), Literal), ] for item in items: key, predicate, fallback, _type = item if catalog_dict: value = catalog_dict.get(key, fallback) else: value = fallback if value: g.add((catalog_ref, predicate, _type(value))) # Dates modified = self._last_catalog_modification() if modified: self._add_date_triple(catalog_ref, DCT.modified, modified)
Example #28
Source File: add-properties2turtle.py From dipper with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): parser = argparse.ArgumentParser( description='description', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( '--input', '-i', type=str, required=True, help='Location of input file') parser.add_argument( '--output', '-o', type=str, required=True, help='Location of output file') parser.add_argument( '--input_format', '-f', type=str, default="turtle", help='format of source rdf file (turtle, nt, rdf/xml)') parser.add_argument( '--output_format', '-g', type=str, default="turtle", help='format of target rdf file (turtle, nt, rdf/xml)') args = parser.parse_args() property_list = get_properties_from_input(args.input, args.input_format) merged_graph = make_property_graph(property_list, args) # merge graphs merged_graph.parse(args.input, format=args.input_format) merged_graph.serialize(args.output, format=args.output_format)
Example #29
Source File: test_euro_dcatap_profile_parse.py From daf-recipes with GNU General Public License v3.0 | 5 votes |
def test_distribution_format_IMT_field(self): g = Graph() dataset1 = URIRef("http://example.org/datasets/1") g.add((dataset1, RDF.type, DCAT.Dataset)) distribution1_1 = URIRef("http://example.org/datasets/1/ds/1") imt = BNode() g.add((imt, RDF.type, DCT.IMT)) g.add((imt, RDF.value, Literal('text/turtle'))) g.add((imt, RDFS.label, Literal('Turtle'))) g.add((distribution1_1, RDF.type, DCAT.Distribution)) g.add((distribution1_1, DCT['format'], imt)) g.add((dataset1, DCAT.distribution, distribution1_1)) p = RDFParser(profiles=['euro_dcat_ap']) p.g = g datasets = [d for d in p.datasets()] resource = datasets[0]['resources'][0] eq_(resource['format'], u'Turtle') eq_(resource['mimetype'], u'text/turtle')
Example #30
Source File: keybag.py From pyaff4 with Apache License 2.0 | 5 votes |
def load(graph): for kb, p, o in graph.triples((None, RDF.type, rdflib.URIRef("http://aff4.org/Schema#KeyBag"))): wk = graph.value(kb, rdflib.URIRef("http://aff4.org/Schema#wrappedKey"), None) salt = graph.value(kb, rdflib.URIRef("http://aff4.org/Schema#salt"), None) iterations = graph.value(kb, rdflib.URIRef("http://aff4.org/Schema#iterations"), None) keySizeInBytes = graph.value(kb, rdflib.URIRef("http://aff4.org/Schema#keySizeInBytes"), None) return PasswordWrappedKeyBag(salt._value, iterations._value, keySizeInBytes._value, wk._value)