当前位置: 首页>>代码示例>>Python>>正文


Python RDFParser.parse方法代码示例

本文整理汇总了Python中ckanext.dcat.processors.RDFParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python RDFParser.parse方法的具体用法?Python RDFParser.parse怎么用?Python RDFParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ckanext.dcat.processors.RDFParser的用法示例。


在下文中一共展示了RDFParser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dataset_json_ld_1

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_json_ld_1(self):

        contents = self._get_file_contents("catalog_pod.jsonld")

        p = RDFParser(profiles=["euro_dcat_ap"])

        p.parse(contents, _format="json-ld")

        datasets = [d for d in p.datasets()]

        eq_(len(datasets), 1)

        dataset = datasets[0]
        extras = dict((e["key"], e["value"]) for e in dataset["extras"])

        eq_(dataset["title"], "U.S. Widget Manufacturing Statistics")

        eq_(extras["contact_name"], "Jane Doe")
        eq_(extras["contact_email"], "mailto:[email protected]")
        eq_(extras["publisher_name"], "Widget Services")
        eq_(extras["publisher_email"], "[email protected]")

        eq_(len(dataset["resources"]), 4)

        resource = [r for r in dataset["resources"] if r["name"] == "widgets.csv"][0]
        eq_(resource["name"], u"widgets.csv")
        eq_(resource["url"], u"https://data.agency.gov/datasets/widgets-statistics/widgets.csv")
        eq_(resource["download_url"], u"https://data.agency.gov/datasets/widgets-statistics/widgets.csv")
开发者ID:ambagape,项目名称:opendatang-full,代码行数:30,代码来源:test_euro_dcatap_profile_parse.py

示例2: test_dataset_ttl

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_ttl(self):

        dataset = factories.Dataset(
            notes='Test dataset'
        )

        url = url_for('dcat_dataset', _id=dataset['id'], _format='ttl')

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers['Content-Type'], 'text/turtle')

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        dcat_dataset = dcat_datasets[0]

        eq_(dcat_dataset['title'], dataset['title'])
        eq_(dcat_dataset['notes'], dataset['notes'])
开发者ID:PublicaMundi,项目名称:ckanext-dcat,代码行数:31,代码来源:test_controllers.py

示例3: test_catalog_modified_date

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_catalog_modified_date(self):

        dataset1 = factories.Dataset(title='First dataset')
        time.sleep(1)
        dataset2 = factories.Dataset(title='Second dataset')

        url = url_for('dcat_catalog',
                      _format='ttl',
                      modified_since=dataset2['metadata_modified'])

        app = self._get_test_app()

        response = app.get(url)

        content = response.body

        p = RDFParser()

        p.parse(content, _format='turtle')

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        eq_(dcat_datasets[0]['title'], dataset2['title'])
开发者ID:PublicaMundi,项目名称:ckanext-dcat,代码行数:27,代码来源:test_controllers.py

示例4: test_dataset_ttl

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_ttl(self):

        dataset = factories.Dataset(notes="Test dataset")

        url = url_for("dcat_dataset", _id=dataset["id"], _format="ttl")

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers["Content-Type"], "text/turtle")

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format="turtle")

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        dcat_dataset = dcat_datasets[0]

        eq_(dcat_dataset["title"], dataset["title"])
        eq_(dcat_dataset["notes"], dataset["notes"])
开发者ID:sciamlab,项目名称:ckanext-dcat,代码行数:29,代码来源:test_controllers.py

示例5: test_catalog_xml_rdf

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_catalog_xml_rdf(self):

        contents = self._get_file_contents("catalog.rdf")

        p = RDFParser(profiles=["euro_dcat_ap"])

        p.parse(contents)

        datasets = [d for d in p.datasets()]

        eq_(len(datasets), 2)

        dataset = datasets[0] if datasets[0]["title"] == "Example dataset 1" else datasets[1]

        eq_(dataset["title"], "Example dataset 1")
        eq_(len(dataset["resources"]), 3)
        eq_(len(dataset["tags"]), 2)
开发者ID:ambagape,项目名称:opendatang-full,代码行数:19,代码来源:test_euro_dcatap_profile_parse.py

示例6: test_parse_data_different_format

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_parse_data_different_format(self):

        data = '''
        @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
        @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

        <http://example.org> a rdfs:SomeClass ;
            rdfs:label "Some label" .
        '''

        p = RDFParser()

        eq_(len(p.g), 0)

        p.parse(data, _format='n3')

        eq_(len(p.g), 2)
开发者ID:AQUACROSS,项目名称:ckanext-dcat,代码行数:19,代码来源:test_base_parser.py

示例7: test_parse_without_pagination

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_parse_without_pagination(self):

        data = '''<?xml version="1.0" encoding="utf-8" ?>
        <rdf:RDF
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
        <rdfs:SomeClass rdf:about="http://example.org">
            <rdfs:label>Some label</rdfs:label>
        </rdfs:SomeClass>
        </rdf:RDF>
        '''

        p = RDFParser()

        p.parse(data)

        eq_(p.next_page(), None)
开发者ID:AQUACROSS,项目名称:ckanext-dcat,代码行数:19,代码来源:test_base_parser.py

示例8: test_catalog_xml_rdf

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_catalog_xml_rdf(self):

        contents = self._get_file_contents('catalog.rdf')

        p = RDFParser(profiles=['euro_dcat_ap'])

        p.parse(contents)

        datasets = [d for d in p.datasets()]

        eq_(len(datasets), 2)

        dataset = (datasets[0] if datasets[0]['title'] == 'Example dataset 1'
                   else datasets[1])

        eq_(dataset['title'], 'Example dataset 1')
        eq_(len(dataset['resources']), 3)
        eq_(len(dataset['tags']), 2)
开发者ID:pduchesne,项目名称:ckanext-dcat,代码行数:20,代码来源:test_euro_dcatap_profile_parse.py

示例9: parse_chunk

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def parse_chunk(self, harvest_job, content, rdf_format, guids_in_source, object_ids):
        # TODO: store content?
        for harvester in p.PluginImplementations(IDCATRDFHarvester):
            content, after_download_errors = harvester.after_download(content, harvest_job)

            for error_msg in after_download_errors:
                self._save_gather_error(error_msg, harvest_job)

        if not content:
            return False

        # TODO: profiles conf
        parser = RDFParser()

        try:
            parser.parse(content, _format=rdf_format)
        except RDFParserException, e:
            self._save_gather_error('Error parsing the RDF file: {0}'.format(e), harvest_job)
            return False
开发者ID:pduchesne,项目名称:ckanext-dcat,代码行数:21,代码来源:rdf.py

示例10: test_dataset_show_without_format

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_show_without_format(self):
        dataset = factories.Dataset(
            notes='Test dataset'
        )

        content = helpers.call_action('dcat_dataset_show', id=dataset['id'])

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content)

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 1)

        dcat_dataset = dcat_datasets[0]

        eq_(dcat_dataset['title'], dataset['title'])
        eq_(dcat_dataset['notes'], dataset['notes'])
开发者ID:ckan,项目名称:ckanext-dcat,代码行数:22,代码来源:test_logic.py

示例11: test_dataset_turtle_1

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_turtle_1(self):

        contents = self._get_file_contents('dataset_deri.ttl')

        p = RDFParser(profiles=['euro_dcat_ap'])

        p.parse(contents, _format='n3')

        datasets = [d for d in p.datasets()]

        eq_(len(datasets), 1)

        dataset = datasets[0]

        eq_(dataset['title'], 'Abandoned Vehicles')
        eq_(len(dataset['resources']), 1)

        resource = dataset['resources'][0]
        eq_(resource['name'], u'CSV distribution of: Abandoned Vehicles')
        eq_(resource['url'], u'http://data.london.gov.uk/datafiles/environment/abandoned-vehicles-borough.csv')
        eq_(resource['uri'], u'http://data.london.gov.uk/dataset/Abandoned_Vehicles/csv')
开发者ID:pduchesne,项目名称:ckanext-dcat,代码行数:23,代码来源:test_euro_dcatap_profile_parse.py

示例12: test_parse_pagination_last_page

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_parse_pagination_last_page(self):

        data = '''<?xml version="1.0" encoding="utf-8" ?>
        <rdf:RDF
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:hydra="http://www.w3.org/ns/hydra/core#">
         <hydra:PagedCollection rdf:about="http://example.com/catalog.xml?page=3">
            <hydra:totalItems rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">245</hydra:totalItems>
            <hydra:lastPage>http://example.com/catalog.xml?page=3</hydra:lastPage>
            <hydra:itemsPerPage rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">100</hydra:itemsPerPage>
            <hydra:firstPage>http://example.com/catalog.xml?page=1</hydra:firstPage>
            <hydra:previousPage>http://example.com/catalog.xml?page=2</hydra:previousPage>
        </hydra:PagedCollection>
        </rdf:RDF>
        '''

        p = RDFParser()

        p.parse(data)

        eq_(p.next_page(), None)
开发者ID:AQUACROSS,项目名称:ckanext-dcat,代码行数:24,代码来源:test_base_parser.py

示例13: gather_stage

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def gather_stage(self, harvest_job):

        log.debug('In DCATRDFHarvester gather_stage')

        # Get file contents
        url = harvest_job.source.url

        for harvester in p.PluginImplementations(IDCATRDFHarvester):
            url, before_download_errors = harvester.before_download(url, harvest_job)

            for error_msg in before_download_errors:
                self._save_gather_error(error_msg, harvest_job)

            if not url:
                return False

        rdf_format = None
        if harvest_job.source.config:
            rdf_format = json.loads(harvest_job.source.config).get("rdf_format")
        content, rdf_format = self._get_content_and_type(url, harvest_job, 1, content_type=rdf_format)

        # TODO: store content?
        for harvester in p.PluginImplementations(IDCATRDFHarvester):
            content, after_download_errors = harvester.after_download(content, harvest_job)

            for error_msg in after_download_errors:
                self._save_gather_error(error_msg, harvest_job)

        if not content:
            return False

        # TODO: profiles conf
        parser = RDFParser()

        try:
            parser.parse(content, _format=rdf_format)
        except RDFParserException, e:
            self._save_gather_error('Error parsing the RDF file: {0}'.format(e), harvest_job)
            return False
开发者ID:memaldi,项目名称:ckanext-dcat,代码行数:41,代码来源:rdf.py

示例14: test_catalog_ttl

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_catalog_ttl(self):

        for i in xrange(4):
            factories.Dataset()

        url = url_for("dcat_catalog", _format="ttl")

        app = self._get_test_app()

        response = app.get(url)

        eq_(response.headers["Content-Type"], "text/turtle")

        content = response.body

        # Parse the contents to check it's an actual serialization
        p = RDFParser()

        p.parse(content, _format="turtle")

        dcat_datasets = [d for d in p.datasets()]

        eq_(len(dcat_datasets), 4)
开发者ID:sciamlab,项目名称:ckanext-dcat,代码行数:25,代码来源:test_controllers.py

示例15: test_dataset_compatibility_mode

# 需要导入模块: from ckanext.dcat.processors import RDFParser [as 别名]
# 或者: from ckanext.dcat.processors.RDFParser import parse [as 别名]
    def test_dataset_compatibility_mode(self):

        contents = self._get_file_contents("dataset.rdf")

        p = RDFParser(profiles=["euro_dcat_ap"], compatibility_mode=True)

        p.parse(contents)

        datasets = [d for d in p.datasets()]

        eq_(len(datasets), 1)

        dataset = datasets[0]

        def _get_extra_value(key):
            v = [extra["value"] for extra in dataset["extras"] if extra["key"] == key]
            return v[0] if v else None

        eq_(_get_extra_value("dcat_issued"), u"2012-05-10")
        eq_(_get_extra_value("dcat_modified"), u"2012-05-10T21:04:00")
        eq_(_get_extra_value("dcat_publisher_name"), "Publishing Organization for dataset 1")
        eq_(_get_extra_value("dcat_publisher_email"), "[email protected]")
        eq_(_get_extra_value("language"), "ca,en,es")
开发者ID:ambagape,项目名称:opendatang-full,代码行数:25,代码来源:test_euro_dcatap_profile_parse.py


注:本文中的ckanext.dcat.processors.RDFParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。