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


Python ProvDocument.deserialize方法代码示例

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


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

示例1: read

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
def read(source, format=None):
    """
    Convenience function returning a ProvDocument instance.

    It does a lazy format detection by simply using try/except for all known
    formats. The deserializers should fail fairly early when data of the
    wrong type is passed to them thus the try/except is likely cheap. One
    could of course also do some more advanced format auto-detection but I am
    not sure that is necessary.

    The downside is that no proper error messages will be produced, use the
    format parameter to get the actual traceback.
    """
    # Lazy imports to not globber the namespace.
    from prov.model import ProvDocument

    from prov.serializers import Registry
    Registry.load_serializers()
    serializers = Registry.serializers.keys()

    if format:
        return ProvDocument.deserialize(source=source, format=format.lower())

    for format in serializers:
        try:
            return ProvDocument.deserialize(source=source, format=format)
        except:
            pass
    else:
        raise TypeError("Could not read from the source. To get a proper "
                        "error message, specify the format with the 'format' "
                        "parameter.")
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:34,代码来源:__init__.py

示例2: get_provdoc

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
def get_provdoc(format,infile):
    if format == "json":
       return ProvDocument.deserialize(infile)
    elif format == "xml":
       return ProvDocument.deserialize(infile,format='xml')
    else:
       print "Error: unsupported format (xml and json are supported"
开发者ID:stephank16,项目名称:enes_graph_use_case,代码行数:9,代码来源:provio.py

示例3: setUp

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
 def setUp(self):
     self.json_path = os.path.dirname(os.path.abspath(__file__)) + '/json/'
     filenames = os.listdir(self.json_path)
     self.fails = []
     for filename in filenames:
         if filename.endswith('.json'):
             with open(self.json_path + filename) as json_file:
                 try:
                     g1 = ProvDocument.deserialize(json_file)
                     json_str = g1.serialize(indent=4)
                     g2 = ProvDocument.deserialize(content=json_str)
                     self.assertEqual(g1, g2, 'Round-trip JSON encoding/decoding failed:  %s.' % filename)
                 except:
                     self.fails.append(filename)
开发者ID:HumanBrainProject,项目名称:prov,代码行数:16,代码来源:testModel.py

示例4: test_loading_all_json

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def test_loading_all_json(self):
        # self.assertFalse(fails, 'Failed to load/round-trip %d JSON files (%s)' % (len(fails), ', '.join(fails)))

        # Code for debugging the failed tests
        for filename in self.fails:
            # Reload the failed files
            filepath = self.json_path + filename
#             os.rename(json_path + filename, json_path + filename + '-fail')
            with open(filepath) as json_file:
                logger.info("Loading %s...", filepath)
                g1 = ProvDocument.deserialize(json_file)
                json_str = g1.serialize(indent=4)
                g2 = ProvDocument.deserialize(content=json_str)
                self.assertEqual(g1, g2, 'Round-trip JSON encoding/decoding failed:  %s.' % filename)
开发者ID:krischer,项目名称:prov,代码行数:16,代码来源:test_model.py

示例5: main

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
def main(auth_json_path, full_provenance=False):
    with open(auth_json_path, 'r') as f:
        auth_json = json.load(f)
        api_token = auth_json['services']['cityofbostondataportal']['token']
        username = 'mjclawar_rarshad'#auth_json['services']['cityofbostondataportal']['username']
        mongo_pass = 'mjclawar_rarshad' #auth_json['services']['cityofbostondataportal']['username']

    database_helper = database_helpers.DatabaseHelper(username=username, password=mongo_pass)
    bdp_api = bdp_query.BDPQuery(api_token=api_token)

    if full_provenance:
        with open(plan_json, 'w') as f:
            f.write(json.dumps({}))

    setup_crime_incidents(database_helper, bdp_api, full_provenance=full_provenance)
    setup_property_assessment(database_helper, bdp_api, full_provenance=full_provenance)
    setup_boston_public_schools(database_helper, bdp_api, full_provenance=full_provenance)
    setup_hospital_locations(database_helper, bdp_api, full_provenance=full_provenance)
    setup_crime_centroids(database_helper, full_provenance=full_provenance)
    setup_hospital_distances(database_helper, full_provenance=full_provenance)
    setup_crime_knn(database_helper, full_provenance=full_provenance)
    setup_home_value_model(database_helper, full_provenance=full_provenance)
    setup_hospital_scatter(database_helper, full_provenance=full_provenance)
    setup_school_distances(database_helper, full_provenance=full_provenance)
    setup_school_scatter(database_helper, full_provenance=full_provenance)

    if full_provenance:
        with open(plan_json, 'r') as f:
            prov_doc = ProvDocument.deserialize(f)
            dot = prov_to_dot(prov_doc)
            dot.write_svg(prov_svg)
开发者ID:Data-Mechanics,项目名称:course-2016-spr-proj,代码行数:33,代码来源:setup.py

示例6: primer

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
def primer():
        a  = ProvDocument()
        script_path = os.path.dirname(os.path.abspath( __file__ )) #
        with open(str(script_path) + "/output.json") as json_file:
                line = json_file.readline()
                a =  a.deserialize(content=line)
        return a
开发者ID:gedare,项目名称:raspberry_prov,代码行数:9,代码来源:tester.py

示例7: prov

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
 def prov(self, format='json', filename=None):
     if self.prov_url is None:
         raise APIException('no provenance information found')
     response = self.adama.utils.request(self.prov_url, format=format)
     if format in ('json', 'sources'):
         return response.json()
     elif format == 'prov-n':
         return response.text
     elif format == 'prov':
         return ProvDocument.deserialize(
             content=json.dumps(response.json()))
     elif format == 'png':
         return png(response.content, filename)
开发者ID:johnfonner,项目名称:jupyterhub_images,代码行数:15,代码来源:adamalib.py

示例8: get_bundle

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def get_bundle(self, document_id, bundle_id, prov_format=ProvDocument):
        if prov_format == ProvDocument:
            extension = 'json'
        else:
            extension = prov_format

        r = self._request('get', "/documents/%i/bundles/%i.%s" % (document_id, bundle_id, extension),
                          headers=self.headers)

        if prov_format == ProvDocument:
            return ProvDocument.deserialize(content=r.content)
        else:
            return r.content
开发者ID:millar,项目名称:provstore-api,代码行数:15,代码来源:api.py

示例9: testAllExamples

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
 def testAllExamples(self):
     num_graphs = len(examples.tests)
     logger.info('PROV-JSON round-trip testing %d example provenance graphs', num_graphs)
     counter = 0
     for name, graph in examples.tests:
         counter += 1
         logger.info('%d. Testing the %s example', counter, name)
         g1 = graph()
         logger.debug('Original graph in PROV-N\n%s', g1.get_provn())
         # json_str = g1.get_provjson(indent=4)
         json_str = g1.serialize(indent=4)
         logger.debug('Original graph in PROV-JSON\n%s', json_str)
         g2 = ProvDocument.deserialize(content=json_str)
         logger.debug('Graph decoded from PROV-JSON\n%s', g2.get_provn())
         self.assertEqual(g1, g2, 'Round-trip JSON encoding/decoding failed:  %s.' % name)
开发者ID:HumanBrainProject,项目名称:prov,代码行数:17,代码来源:testModel.py

示例10: get_document

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def get_document(self, doc_id, format=None, flattened=False, view=None):
        """Returns a ProvBundle object of the document with the ID provided or raises ApiNotFoundError"""

        extension = format if format is not None else 'json'
        view = "/views/%s" % view if view in ['data', 'process', 'responsibility'] else ""
        url = "documents/%d%s%s.%s" % (doc_id, "/flattened" if flattened else "", view, extension)
        response = self.request(url, raw=True)

        if format is None:
            # Try to decode it as a ProvDocument
            result = ProvDocument.deserialize(content=response)
        else:
            # return the raw response
            result = response
        return result
开发者ID:rollend,项目名称:PROVTutorial,代码行数:17,代码来源:wrapper.py

示例11: test_unifying

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
 def test_unifying(self):
     # This is a very trivial test just to exercise the unified() function
     # TODO: Create a proper unification test
     json_path = os.path.dirname(os.path.abspath(__file__)) + '/unification/'
     filenames = os.listdir(json_path)
     for filename in filenames:
         if not filename.endswith('.json'):
             continue
         filepath = json_path + filename
         with open(filepath) as json_file:
             logger.info('Testing unifying: %s', filename)
             logger.debug("Loading %s...", filepath)
             document = ProvDocument.deserialize(json_file)
             flattened = document.flattened()
             unified = flattened.unified()
             self.assertLess(len(unified.get_records()), len(flattened.get_records()))
开发者ID:HumanBrainProject,项目名称:prov,代码行数:18,代码来源:testModel.py

示例12: test_decoding_unicode_value

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def test_decoding_unicode_value(self):
        unicode_char = u'\u2019'
        json_content = u'''{
    "prefix": {
        "ex": "http://www.example.org"
    },
    "entity": {
        "ex:unicode_char": {
            "prov:label": "%s"
        }
    }
}''' % unicode_char

        prov_doc = ProvDocument.deserialize(content=json_content, format='json')
        e1 = prov_doc.get_record('ex:unicode_char')[0]
        self.assertIn(unicode_char, e1.get_attribute('prov:label'))
开发者ID:krischer,项目名称:prov,代码行数:18,代码来源:test_json.py

示例13: test_decoding_unicode_value

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def test_decoding_unicode_value(self):
        unicode_char = u'\u2019'
        rdf_content = u'''
@prefix ex: <http://www.example.org/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

    ex:unicode_char a prov:Entity ;
        rdfs:label "%s"^^xsd:string .
''' % unicode_char
        prov_doc = ProvDocument.deserialize(content=rdf_content,
                                            format='rdf', rdf_format='turtle')
        e1 = prov_doc.get_record('ex:unicode_char')[0]
        self.assertIn(unicode_char, e1.get_attribute('prov:label'))
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:19,代码来源:test_rdf.py

示例14: assertRoundTripEquivalence

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def assertRoundTripEquivalence(self, prov_doc, msg=None):
        if self.FORMAT is None:
            # This is a dummy test, just return
            return

        with io.BytesIO() as stream:
            prov_doc.serialize(destination=stream, format=self.FORMAT, indent=4)
            stream.seek(0, 0)

            prov_doc_new = ProvDocument.deserialize(source=stream, format=self.FORMAT)
            stream.seek(0, 0)
            # Assume UTF-8 encoding which is forced by the particular
            # PROV XML implementation and should also work for the PROV
            # JSON implementation.
            msg_extra = "'%s' serialization content:\n%s" % (self.FORMAT, stream.read().decode("utf-8"))
            msg = "\n".join((msg, msg_extra)) if msg else msg_extra
            self.assertEqual(prov_doc, prov_doc_new, msg)
开发者ID:ignatenkobrain,项目名称:prov,代码行数:19,代码来源:utility.py

示例15: __init__

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import deserialize [as 别名]
    def __init__(self, database_helper, full_provenance=False):
        """
        Initializes the provenance for the mjclawar_rarshad project

        Parameters
        ----------
        database_helper: DatabaseHelper
        full_provenance: bool

        Returns
        -------
        """
        assert isinstance(database_helper, DatabaseHelper)

        self.database_helper = database_helper
        if full_provenance:
            self.prov_doc = ProvDocument.deserialize(dir_info.plan_json)
        else:
            self.prov_doc = ProvDocument()
        self.prov_doc.add_namespace(mcras.BDP_NAMESPACE.name, mcras.BDP_NAMESPACE.link)
        self.prov_doc.add_namespace(mcras.ALG_NAMESPACE.name, mcras.ALG_NAMESPACE.link)
        self.prov_doc.add_namespace(mcras.DAT_NAMESPACE.name, mcras.DAT_NAMESPACE.link)
        self.prov_doc.add_namespace(mcras.LOG_NAMESPACE.name, mcras.LOG_NAMESPACE.link)
        self.prov_doc.add_namespace(mcras.ONT_NAMESPACE.name, mcras.ONT_NAMESPACE.link)
开发者ID:B1ueSky,项目名称:course-2016-spr-proj-two,代码行数:26,代码来源:provenance.py


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