本文整理汇总了Python中ckanext.dcat.processors.RDFParser.g方法的典型用法代码示例。如果您正苦于以下问题:Python RDFParser.g方法的具体用法?Python RDFParser.g怎么用?Python RDFParser.g使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckanext.dcat.processors.RDFParser
的用法示例。
在下文中一共展示了RDFParser.g方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_distribution_format_format_normalized
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
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')
示例2: test_spatial_one_dct_spatial_instance_no_uri
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_spatial_one_dct_spatial_instance_no_uri(self):
g = Graph()
dataset = URIRef('http://example.org/datasets/1')
g.add((dataset, RDF.type, DCAT.Dataset))
location_ref = BNode()
g.add((dataset, DCT.spatial, location_ref))
g.add((location_ref, RDF.type, DCT.Location))
g.add((location_ref,
LOCN.geometry,
Literal('{"type": "Point", "coordinates": [23, 45]}', datatype=GEOJSON_IMT)))
g.add((location_ref, SKOS.prefLabel, Literal('Newark')))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
datasets = [d for d in p.datasets()]
extras = self._extras(datasets[0])
assert_true('spatial_uri' not in extras)
eq_(extras['spatial_text'], 'Newark')
eq_(extras['spatial'], '{"type": "Point", "coordinates": [23, 45]}')
示例3: test_distribution_format_IMT_field
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
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')
示例4: test_spatial_both_geojson_and_wkt
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_spatial_both_geojson_and_wkt(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('{"type": "Point", "coordinates": [23, 45]}', datatype=GEOJSON_IMT)))
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])
eq_(extras['spatial'], '{"type": "Point", "coordinates": [23, 45]}')
示例5: test_datasets_none_found
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_datasets_none_found(self):
p = RDFParser()
p.g = Graph()
eq_(len([d for d in p.datasets()]), 0)
示例6: test__datasets
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test__datasets(self):
p = RDFParser()
p.g = _default_graph()
eq_(len([d for d in p._datasets()]), 3)
示例7: test_spatial_wrong_geometries
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_spatial_wrong_geometries(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('Not GeoJSON', datatype=GEOJSON_IMT)))
g.add((spatial_uri,
LOCN.geometry,
Literal('Not WKT', datatype=GSP.wktLiteral)))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
datasets = [d for d in p.datasets()]
extras = self._extras(datasets[0])
assert_true('spatial' not in extras)
示例8: test_spatial_multiple_dct_spatial_instances
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_spatial_multiple_dct_spatial_instances(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))
location_ref = BNode()
g.add((location_ref, RDF.type, DCT.Location))
g.add((dataset, DCT.spatial, location_ref))
g.add(
(location_ref, LOCN.geometry, Literal('{"type": "Point", "coordinates": [23, 45]}', datatype=GEOJSON_IMT))
)
location_ref = BNode()
g.add((location_ref, RDF.type, DCT.Location))
g.add((dataset, DCT.spatial, location_ref))
g.add((location_ref, SKOS.prefLabel, 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_uri"], "http://geonames/Newark")
eq_(extras["spatial_text"], "Newark")
eq_(extras["spatial"], '{"type": "Point", "coordinates": [23, 45]}')
示例9: test_parse_subcatalog
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_parse_subcatalog(self):
publisher = {'name': 'Publisher',
'email': '[email protected]',
'type': 'Publisher',
'uri': 'http://pub.lish.er'}
dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'title': 'test dataset',
'extras': [
{'key': 'source_catalog_title', 'value': 'Subcatalog example'},
{'key': 'source_catalog_homepage', 'value': 'http://subcatalog.example'},
{'key': 'source_catalog_description', 'value': 'Subcatalog example description'},
{'key': 'source_catalog_language', 'value': 'http://publications.europa.eu/resource/authority/language/ITA'},
{'key': 'source_catalog_modified', 'value': '2000-01-01'},
{'key': 'source_catalog_publisher', 'value': json.dumps(publisher)}
]
}
catalog_dict = {
'title': 'My Catalog',
'description': 'An Open Data Catalog',
'homepage': 'http://example.com',
'language': 'de',
}
s = RDFSerializer()
s.serialize_catalog(catalog_dict, dataset_dicts=[dataset])
g = s.g
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
# at least one subcatalog with hasPart
subcatalogs = list(p.g.objects(None, DCT.hasPart))
assert_true(subcatalogs)
# at least one dataset in subcatalogs
subdatasets = []
for subcatalog in subcatalogs:
datasets = p.g.objects(subcatalog, DCAT.dataset)
for dataset in datasets:
subdatasets.append((dataset,subcatalog,))
assert_true(subdatasets)
datasets = dict([(d['title'], d) for d in p.datasets()])
for subdataset, subcatalog in subdatasets:
title = unicode(list(p.g.objects(subdataset, DCT.title))[0])
dataset = datasets[title]
has_subcat = False
for ex in dataset['extras']:
exval = ex['value']
exkey = ex['key']
if exkey == 'source_catalog_homepage':
has_subcat = True
eq_(exval, unicode(subcatalog))
# check if we had subcatalog in extras
assert_true(has_subcat)
示例10: test_profiles_are_called_on_datasets
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_profiles_are_called_on_datasets(self):
p = RDFParser()
p._profiles = [MockRDFProfile1, MockRDFProfile2]
p.g = _default_graph()
for dataset in p.datasets():
assert dataset['profile_1']
assert dataset['profile_2']
示例11: test_tags_with_commas
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_tags_with_commas(self):
g = Graph()
dataset = URIRef('http://example.org/datasets/1')
g.add((dataset, RDF.type, DCAT.Dataset))
g.add((dataset, DCAT.keyword, Literal('Tree, forest, shrub')))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
datasets = [d for d in p.datasets()]
eq_(len(datasets[0]['tags']), 3)
示例12: test_datasets
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_datasets(self):
p = RDFParser()
p.g = _default_graph()
datasets = []
for dataset in p.datasets():
assert 'title' in dataset
datasets.append(dataset)
eq_(len(datasets), 3)
示例13: test_tags_with_commas_clean_tags_on
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_tags_with_commas_clean_tags_on(self):
g = Graph()
dataset = URIRef('http://example.org/datasets/1')
g.add((dataset, RDF.type, DCAT.Dataset))
g.add((dataset, DCAT.keyword, Literal(self.INVALID_TAG)))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
datasets = [d for d in p.datasets()]
assert_true(self.VALID_TAG in datasets[0]['tags'])
assert_true(self.INVALID_TAG not in datasets[0]['tags'])
示例14: test_tags_with_commas_clean_tags_off
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_tags_with_commas_clean_tags_off(self):
g = Graph()
dataset = URIRef('http://example.org/datasets/1')
g.add((dataset, RDF.type, DCAT.Dataset))
g.add((dataset, DCAT.keyword, Literal(self.INVALID_TAG)))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
# when config flag is set to false, bad tags can happen
datasets = [d for d in p.datasets()]
assert_true(self.VALID_TAG not in datasets[0]['tags'])
assert_true({'name': self.INVALID_TAG} in datasets[0]['tags'])
示例15: test_dataset_version_adms
# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import g [as 别名]
def test_dataset_version_adms(self):
g = Graph()
dataset1 = URIRef("http://example.org/datasets/1")
g.add((dataset1, RDF.type, DCAT.Dataset))
g.add((dataset1, ADMS.version, Literal('2.3a')))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
dataset = [d for d in p.datasets()][0]
eq_(dataset['version'], u'2.3a')