本文整理汇总了Python中prov.model.ProvDocument类的典型用法代码示例。如果您正苦于以下问题:Python ProvDocument类的具体用法?Python ProvDocument怎么用?Python ProvDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProvDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deriveDependency
def deriveDependency(self, aDO, aRO, derivedList):
d1 = ProvDocument() # d1 is now an empty provenance document
d1.add_namespace("dt", "http://cs.ncl.ac.uk/dtsim/")
e1 = d1.entity(DTns + aRO.id) # deriving
ag1 = d1.agent(DTns + str(aDO.id))
for der in derivedList:
# create provlet
e2 = d1.entity(DTns + der.id) # derived
d1.wasAttributedTo(e2, ag1)
d1.wasDerivedFrom(e2, e1)
# update upstream pointer
der.upstream = [(aRO, None)] # aRO is upstream from aRO with no activity
# update downstream
aRO.downstream.append((der, None)) # aR1 is downstream from aR1 with no activity
# update global graph
e1 = pGlobal.entity(DTns + aRO.id) # deriving
ag1 = pGlobal.agent(DTns + str(aDO.id))
pGlobal.wasAttributedTo(e2, ag1)
for der in derivedList:
e2 = pGlobal.entity(DTns + der.id) # derived
pGlobal.wasDerivedFrom(e2, e1)
# trigger credit recomputation
for der in derivedList:
# aRO needs its credit updated with aRO1.credit
aCreditManager.addDerivationCredit(aRO, der.currentTotalCredit)
# self.notify(d1)
return d1
示例2: get_provdoc
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"
示例3: test_default_namespace_inheritance
def test_default_namespace_inheritance(self):
prov_doc = ProvDocument()
prov_doc.set_default_namespace('http://www.example.org/')
bundle = prov_doc.bundle('bundle')
e1 = bundle.entity('e1')
self.assertIsNotNone(e1.identifier, "e1's identifier is None!")
self.assertRoundTripEquivalence(prov_doc)
示例4: test_namespace_inheritance
def test_namespace_inheritance(self):
prov_doc = ProvDocument()
prov_doc.add_namespace('ex', 'http://www.example.org/')
bundle = prov_doc.bundle('ex:bundle')
e1 = bundle.entity('ex:e1')
self.assertIsNotNone(e1.identifier, "e1's identifier is None!")
self.do_tests(prov_doc)
示例5: primer
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
示例6: read
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.")
示例7: collections
def collections():
g = ProvDocument()
ex = Namespace('ex', 'http://example.org/')
c1 = g.collection(ex['c1'])
e1 = g.entity('ex:e1')
g.hadMember(c1, e1)
return g
示例8: test_xsd_qnames
def test_xsd_qnames(self):
prov_doc = ProvDocument()
ex = Namespace('ex', 'http://www.example.org')
prov_doc.add_namespace(ex)
an_xsd_qname = XSDQName(ex['a_value'])
prov_doc.entity('ex:e1', {'prov:value': an_xsd_qname})
self.assertPROVJSONRoundTripEquivalence(prov_doc)
示例9: document_with_n_bundles_having_default_namespace
def document_with_n_bundles_having_default_namespace(n):
prov_doc = ProvDocument()
prov_doc.add_namespace('ex', 'http://www.example.org/')
for i in range(n):
x = str(i + 1)
bundle = prov_doc.bundle('ex:bundle/' + x)
bundle.set_default_namespace('http://www.example.org/default/' + x)
bundle.entity('e')
return prov_doc
示例10: long_literals
def long_literals():
g = ProvDocument()
long_uri = "http://Lorem.ipsum/dolor/sit/amet/consectetur/adipiscing/elit/Quisque/vel/sollicitudin/felis/nec/venenatis/massa/Aenean/lectus/arcu/sagittis/sit/amet/nisl/nec/varius/eleifend/sem/In/hac/habitasse/platea/dictumst/Aliquam/eget/fermentum/enim/Curabitur/auctor/elit/non/ipsum/interdum/at/orci/aliquam/"
ex = Namespace('ex', long_uri)
g.add_namespace(ex)
g.entity('ex:e1', {'prov:label': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pellentesque luctus nulla vel ullamcorper. Donec sit amet ligula sit amet lorem pretium rhoncus vel vel lorem. Sed at consequat metus, eget eleifend massa. Fusce a facilisis turpis. Lorem volutpat.'})
return g
示例11: setUp
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)
示例12: test_xsd_qnames
def test_xsd_qnames(self):
prov_doc = ProvDocument()
ex = Namespace('ex', 'http://www.example.org/')
prov_doc.add_namespace(ex)
ex1 = Namespace('ex1', 'http://www.example1.org/') # ex1 is not added to the document
an_xsd_qname = XSDQName(ex['a_value'])
another_xsd_qname = XSDQName(ex1['another_value'])
e1 = prov_doc.entity('ex:e1', {'prov:value': an_xsd_qname, 'prov:type': another_xsd_qname})
for _, attr_value in e1.attributes:
self.assertIsInstance(attr_value, XSDQName)
self.assertRoundTripEquivalence(prov_doc)
示例13: test_loading_all_json
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)
示例14: __init__
class ProjectProvenance:
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)
def write_provenance_json(self):
self.prov_doc.serialize(dir_info.plan_json)
示例15: test_bundle_update_simple
def test_bundle_update_simple(self):
doc = ProvDocument()
doc.set_default_namespace(EX_URI)
b1 = doc.bundle('b1')
b1.entity('e')
b2 = doc.bundle('b2')
b2.entity('e')
self.assertRaises(ProvException, lambda: b1.update(1))
self.assertRaises(ProvException, lambda: b1.update(doc))
b1.update(b2)
self.assertEqual(len(b1.get_records()), 2)