本文整理汇总了Python中prov.model.ProvDocument.add_namespace方法的典型用法代码示例。如果您正苦于以下问题:Python ProvDocument.add_namespace方法的具体用法?Python ProvDocument.add_namespace怎么用?Python ProvDocument.add_namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prov.model.ProvDocument
的用法示例。
在下文中一共展示了ProvDocument.add_namespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_namespace_inheritance
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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.assertRoundTripEquivalence(prov_doc)
示例2: deriveDependency
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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
示例3: document_with_n_bundles_having_default_namespace
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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
示例4: test_xsd_qnames
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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)
示例5: long_literals
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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
示例6: job2prov
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def job2prov(job):
"""
Create ProvDocument based on job description
:param job: UWS job
:return: ProvDocument
"""
# job.jdl.content = {
# 'description': description,
# 'parameters': parameters,
# 'results': results,
# 'executionduration': execdur,
# 'quote': quote
# }
# parameters[pname] = {
# 'type': p.get('type'),
# 'required': p.get('required'),
# 'default': p.get('default'),
# 'description': list(p)[0].text,
# }
# results[r.get('value')] = {
# 'mediaType': r.get('mediaType'),
# 'default': r.get('default'),
# 'description': list(r)[0].text,
# }
pdoc = ProvDocument()
# Declaring namespaces for various prefixes used in the example
pdoc.add_namespace('prov', 'http://www.w3.org/ns/prov#')
pdoc.add_namespace('voprov', 'http://www.ivoa.net/ns/voprov#')
pdoc.add_namespace('cta', 'http://www.cta-observatory.org#')
pdoc.add_namespace('uwsdata', 'https://voparis-uws-test.obspm.fr/rest/' + job.jobname + '/' + job.jobid + '/')
pdoc.add_namespace('ctajobs', 'http://www.cta-observatory.org#')
# Adding an activity
ctbin = pdoc.activity('ctajobs:' + job.jobname, job.start_time, job.end_time)
# TODO: add job description, version, url, ...
# Agent
pdoc.agent('cta:consortium', other_attributes={'prov:type': "Organization"})
pdoc.wasAssociatedWith(ctbin, 'cta:consortium')
# Entities, in and out with relations
e_in = []
for pname, pdict in job.jdl.content['parameters'].iteritems():
#if pname.startswith('in'):
if any(x in pdict['type'] for x in ['file', 'xs:anyURI']):
e_in.append(pdoc.entity('uwsdata:parameters/' + pname))
# TODO: use publisher_did? add prov attributes, add voprov attributes?
ctbin.used(e_in[-1])
e_out = []
for rname, rdict in job.jdl.content['results'].iteritems():
e_out.append(pdoc.entity('uwsdata:results/' + rname))
# TODO: use publisher_did? add prov attributes, add voprov attributes?
e_out[-1].wasGeneratedBy(ctbin)
for e in e_in:
e_out[-1].wasDerivedFrom(e)
return pdoc
示例7: test_xsd_qnames
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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)
示例8: generateProvlet
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def generateProvlet(self, aDO, aRO):
# create provlet
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)
ag1 = d1.agent(DTns + str(aDO.id))
d1.wasAttributedTo(e1, ag1)
# update global graph
e1 = pGlobal.entity(DTns + aRO.id)
ag1 = pGlobal.agent(DTns + str(aDO.id))
pGlobal.wasAttributedTo(e1, ag1)
# self.notify(d1)
return d1
示例9: datatypes
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def datatypes():
g = ProvDocument()
ex = Namespace('ex', 'http://example.org/')
g.add_namespace(ex)
attributes = {'ex:int': 100,
'ex:float': 100.123456,
'ex:long': 123456789000,
'ex:bool': True,
'ex:str': 'Some string',
'ex:unicode': u'Some unicode string with accents: Huỳnh Trung Đông',
'ex:timedate': datetime.datetime(2012, 12, 12, 14, 7, 48),
'ex:intstr': Literal("PROV Internationalized string", PROV["InternationalizedString"], "en"),
}
multiline = """Line1
Line2
Line3"""
attributes['ex:multi-line'] = multiline
g.entity('ex:e1', attributes)
return g
示例10: __init__
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
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)
示例11: bundles2
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def bundles2():
# https://github.com/lucmoreau/ProvToolbox/blob/master/prov-n/src/test/resources/prov/bundles2.provn
#===========================================================================
# document
g = ProvDocument()
# prefix ex <http://example.org/example/>
g.add_namespace("ex", "http://www.example.com/")
# prefix alice <http://example.org/alice/>
# prefix bob <http://example.org/bob/>
g.add_namespace('alice', 'http://example.org/alice/')
g.add_namespace('bob', 'http://example.org/bob/')
# entity(bob:bundle4, [prov:type='prov:Bundle'])
# wasGeneratedBy(bob:bundle4, -, 2012-05-24T10:30:00)
# agent(ex:Bob)
# wasAttributedTo(bob:bundle4, ex:Bob)
g.entity('bob:bundle4', {'prov:type': PROV['Bundle']})
g.wasGeneratedBy('bob:bundle4', time='2012-05-24T10:30:00')
g.agent('ex:Bob')
g.wasAttributedTo('bob:bundle4', 'ex:Bob')
# entity(alice:bundle5, [ prov:type='prov:Bundle' ])
# wasGeneratedBy(alice:bundle5, -, 2012-05-25T11:15:00)
# agent(ex:Alice)
# wasAttributedTo(alice:bundle5, ex:Alice)
g.entity('alice:bundle5', {'prov:type': PROV['Bundle']})
g.wasGeneratedBy('alice:bundle5', time='2012-05-25T11:15:00')
g.agent('ex:Alice')
g.wasAttributedTo('alice:bundle5', 'ex:Alice')
# bundle bob:bundle4
# entity(ex:report1, [ prov:type="report", ex:version=1 ])
# wasGeneratedBy(ex:report1, -, 2012-05-24T10:00:01)
# endBundle
b4 = g.bundle('bob:bundle4')
b4.entity('ex:report1', {'prov:type': "report", 'ex:version': 1})
b4.wasGeneratedBy('ex:report1', time='2012-05-24T10:00:01')
# bundle alice:bundle5
# entity(ex:report1bis)
# mentionOf(ex:report1bis, ex:report1, bob:bundle4)
# entity(ex:report2, [ prov:type="report", ex:version=2 ])
# wasGeneratedBy(ex:report2, -, 2012-05-25T11:00:01)
# wasDerivedFrom(ex:report2, ex:report1bis)
# endBundle
b5 = g.bundle('alice:bundle5')
b5.entity('ex:report1bis')
b5.mentionOf('ex:report1bis', 'ex:report1', 'bob:bundle4')
b5.entity('ex:report2', [('prov:type', "report"), ('ex:version', 2)])
b5.wasGeneratedBy('ex:report2', time='2012-05-25T11:00:01')
b5.wasDerivedFrom('ex:report2', 'ex:report1bis')
# endDocument
return g
示例12: bundles1
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def bundles1():
# https://github.com/lucmoreau/ProvToolbox/blob/master/prov-n/src/test/resources/prov/bundles1.provn
#===============================================================================
# document
g = ProvDocument()
# prefix ex <http://example.org/example/>
EX = Namespace("ex", "http://www.example.com/")
g.add_namespace(EX)
# prefix alice <http://example.org/alice/>
# prefix bob <http://example.org/bob/>
g.add_namespace('alice', 'http://example.org/alice/')
g.add_namespace('bob', 'http://example.org/bob/')
# entity(bob:bundle1, [prov:type='prov:Bundle'])
g.entity('bob:bundle1', {'prov:type': PROV['Bundle']})
# wasGeneratedBy(bob:bundle1, -, 2012-05-24T10:30:00)
g.wasGeneratedBy('bob:bundle1', time='2012-05-24T10:30:00')
# agent(ex:Bob)
g.agent('ex:Bob')
# wasAttributedTo(bob:bundle1, ex:Bob)
g.wasAttributedTo('bob:bundle1', 'ex:Bob')
# entity(alice:bundle2, [ prov:type='prov:Bundle' ])
g.entity('alice:bundle2', {'prov:type': PROV['Bundle']})
# wasGeneratedBy(alice:bundle2, -, 2012-05-25T11:15:00)
g.wasGeneratedBy('alice:bundle2', time='2012-05-25T11:15:00')
# agent(ex:Alice)
g.agent('ex:Alice')
# wasAttributedTo(alice:bundle2, ex:Alice)
g.wasAttributedTo('alice:bundle2', 'ex:Alice')
# bundle bob:bundle1
b1 = g.bundle('bob:bundle1')
# entity(ex:report1, [ prov:type="report", ex:version=1 ])
b1.entity('ex:report1', {'prov:type': "report", 'ex:version': 1})
# wasGeneratedBy(ex:report1, -, 2012-05-24T10:00:01)
b1.wasGeneratedBy('ex:report1', time='2012-05-24T10:00:01')
# endBundle
# bundle alice:bundle2
b2 = g.bundle('alice:bundle2')
# entity(ex:report1)
b2.entity('ex:report1')
# entity(ex:report2, [ prov:type="report", ex:version=2 ])
b2.entity('ex:report2', {'prov:type': "report", 'ex:version': 2})
# wasGeneratedBy(ex:report2, -, 2012-05-25T11:00:01)
b2.wasGeneratedBy('ex:report2', time='2012-05-25T11:00:01')
# wasDerivedFrom(ex:report2, ex:report1)
b2.wasDerivedFrom('ex:report2', 'ex:report1')
# endBundle
# endDocument
return g
示例13: w3c_publication_1
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def w3c_publication_1():
# https://github.com/lucmoreau/ProvToolbox/blob/master/asn/src/test/resources/prov/w3c-publication1.prov-asn
#===========================================================================
# bundle
#
# prefix ex <http://example.org/>
#
# prefix w3 <http://www.w3.org/>
# prefix tr <http://www.w3.org/TR/2011/>
# prefix process <http://www.w3.org/2005/10/Process-20051014/tr.html#>
# prefix email <https://lists.w3.org/Archives/Member/w3c-archive/>
# prefix chairs <https://lists.w3.org/Archives/Member/chairs/>
# prefix trans <http://www.w3.org/2005/08/01-transitions.html#>
# prefix rec54 <http://www.w3.org/2001/02pd/rec54#>
#
#
# entity(tr:WD-prov-dm-20111018, [ prov:type='rec54:WD' ])
# entity(tr:WD-prov-dm-20111215, [ prov:type='rec54:WD' ])
# entity(process:rec-advance, [ prov:type='prov:Plan' ])
#
#
# entity(chairs:2011OctDec/0004, [ prov:type='trans:transreq' ])
# entity(email:2011Oct/0141, [ prov:type='trans:pubreq' ])
# entity(email:2011Dec/0111, [ prov:type='trans:pubreq' ])
#
#
# wasDerivedFrom(tr:WD-prov-dm-20111215, tr:WD-prov-dm-20111018)
#
#
# activity(ex:act1,-,-,[prov:type="publish"])
# activity(ex:act2,-,-,[prov:type="publish"])
#
# wasGeneratedBy(tr:WD-prov-dm-20111018, ex:act1, -)
# wasGeneratedBy(tr:WD-prov-dm-20111215, ex:act2, -)
#
# used(ex:act1, chairs:2011OctDec/0004, -)
# used(ex:act1, email:2011Oct/0141, -)
# used(ex:act2, email:2011Dec/0111, -)
#
# agent(w3:Consortium, [ prov:type='prov:Organization' ])
#
# wasAssociatedWith(ex:act1, w3:Consortium, process:rec-advance)
# wasAssociatedWith(ex:act2, w3:Consortium, process:rec-advance)
#
# endBundle
#===========================================================================
g = ProvDocument()
g.add_namespace('ex', 'http://example.org/')
g.add_namespace('w3', 'http://www.w3.org/')
g.add_namespace('tr', 'http://www.w3.org/TR/2011/')
g.add_namespace('process', 'http://www.w3.org/2005/10/Process-20051014/tr.html#')
g.add_namespace('email', 'https://lists.w3.org/Archives/Member/w3c-archive/')
g.add_namespace('chairs', 'https://lists.w3.org/Archives/Member/chairs/')
g.add_namespace('trans', 'http://www.w3.org/2005/08/01-transitions.html#')
g.add_namespace('rec54', 'http://www.w3.org/2001/02pd/rec54#')
g.entity('tr:WD-prov-dm-20111018', {'prov:type': 'rec54:WD'})
g.entity('tr:WD-prov-dm-20111215', {'prov:type': 'rec54:WD'})
g.entity('process:rec-advance', {'prov:type': 'prov:Plan'})
g.entity('chairs:2011OctDec/0004', {'prov:type': 'trans:transreq'})
g.entity('email:2011Oct/0141', {'prov:type': 'trans:pubreq'})
g.entity('email:2011Dec/0111', {'prov:type': 'trans:pubreq'})
g.wasDerivedFrom('tr:WD-prov-dm-20111215', 'tr:WD-prov-dm-20111018')
g.activity('ex:act1', other_attributes={'prov:type': "publish"})
g.activity('ex:act2', other_attributes={'prov:type': "publish"})
g.wasGeneratedBy('tr:WD-prov-dm-20111018', 'ex:act1')
g.wasGeneratedBy('tr:WD-prov-dm-20111215', 'ex:act2')
g.used('ex:act1', 'chairs:2011OctDec/0004')
g.used('ex:act1', 'email:2011Oct/0141')
g.used('ex:act2', 'email:2011Dec/0111')
g.agent('w3:Consortium', other_attributes={'prov:type': "Organization"})
g.wasAssociatedWith('ex:act1', 'w3:Consortium', 'process:rec-advance')
g.wasAssociatedWith('ex:act2', 'w3:Consortium', 'process:rec-advance')
return g
示例14: toW3Cprov
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def toW3Cprov(ling,bundl,format='w3c-prov-xml'):
g = ProvDocument()
vc = Namespace("knmi", "http://knmi.nl") # namespaces do not need to be explicitly added to a document
con = Namespace("dfp", "http://dispel4py.org")
g.add_namespace("dcterms", "http://purl.org/dc/terms/")
'specify bundle'
bundle=None
for trace in bundl:
'specifing user'
ag=g.agent(vc[trace["username"]],other_attributes={"dcterms:author":trace["username"]}) # first time the ex namespace was used, it is added to the document automatically
if trace['type']=='workflow_run':
trace.update({'runId':trace['_id']})
bundle=g.bundle(vc[trace["runId"]])
bundle.actedOnBehalfOf(vc[trace["runId"]], vc[trace["username"]])
dic={}
i=0
for key in trace:
if key != "input":
if ':' in key:
dic.update({key: trace[key]})
else:
dic.update({vc[key]: trace[key]})
dic.update({'prov:type': PROV['Bundle']})
g.entity(vc[trace["runId"]], dic)
dic={}
i=0
if type(trace['input'])!=list:
trace['input']=[trace['input']]
for y in trace['input']:
for key in y:
if ':' in key:
dic.update({key: y[key]})
else:
dic.update({vc[key]: y[key]})
dic.update({'prov:type': 'worklfow_input'})
bundle.entity(vc[trace["_id"]+"_"+str(i)], dic)
bundle.used(vc[trace["_id"]], vc[trace["_id"]+"_"+str(i)], identifier=vc["used_"+trace["_id"]+"_"+str(i)])
i=i+1
'specify lineage'
for trace in ling:
#pprint(trace)
try:
bundle=g.bundle(vc[trace["runId"]])
bundle.wasAttributedTo(vc[trace["runId"]], vc["ag_"+trace["username"]],identifier=vc["attr_"+trace["runId"]])
except:
pass
'specifing creator of the activity (to be collected from the registy)'
if 'creator' in trace:
bundle.agent(vc["ag_"+trace["creator"]],other_attributes={"dcterms:creator":trace["creator"]}) # first time the ex namespace was used, it is added to the document automatically
bundle.wasAssociatedWith('process_'+trace["iterationId"],vc["ag_"+trace["creator"]])
bundle.wasAttributedTo(vc[trace["runId"]], vc["ag_"+trace["creator"]])
'adding activity information for lineage'
dic={}
for key in trace:
if type(trace[key])!=list:
if ':' in key:
dic.update({key: trace[key]})
else:
if key=='location':
dic.update({"prov:location": trace[key]})
else:
dic.update({vc[key]: trace[key]})
bundle.activity(vc["process_"+trace["iterationId"]], trace["startTime"], trace["endTime"], dic.update({'prov:type': trace["name"]}))
'adding parameters to the document as input entities'
dic={}
for x in trace["parameters"]:
#print x
if ':' in x["key"]:
dic.update({x["key"]: x["val"]})
else:
dic.update({vc[x["key"]]: x["val"]})
dic.update({'prov:type':'parameters'})
bundle.entity(vc["parameters_"+trace["instanceId"]], dic)
bundle.used(vc['process_'+trace["iterationId"]], vc["parameters_"+trace["instanceId"]], identifier=vc["used_"+trace["iterationId"]])
'adding input dependencies to the document as input entities'
dic={}
#.........这里部分代码省略.........
示例15: document_1
# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import add_namespace [as 别名]
def document_1(self):
d1 = ProvDocument()
ns_ex = d1.add_namespace('ex', EX_URI)
d1.entity(ns_ex['e1'])
return d1