本文整理汇总了Python中prov.model.ProvBundle类的典型用法代码示例。如果您正苦于以下问题:Python ProvBundle类的具体用法?Python ProvBundle怎么用?Python ProvBundle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProvBundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collections
def collections():
g = ProvBundle()
ex = Namespace('ex', 'http://example.org/')
c1 = g.collection(ex['c1'])
e1 = g.entity('ex:e1')
g.hadMember(c1, e1)
return g
示例2: collections
def collections():
g = ProvBundle()
ex = Namespace("ex", "http://example.org/")
c1 = g.collection(ex["c1"])
e1 = g.entity("ex:e1")
g.hadMember(c1, e1)
return g
示例3: obj_create
def obj_create(self, bundle, request=None, **kwargs):
prov_bundle = ProvBundle()
prov_bundle._decode_JSON_container(bundle.data['content'])
account = PDBundle.create(bundle.data['rec_id'], bundle.data['asserter'], request.user)
account.save_bundle(prov_bundle)
bundle.obj = account
return bundle
示例4: long_literals
def long_literals():
g = ProvBundle()
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
示例5: BundleForm
class BundleForm(Form):
''' Form for creating a Bundle '''
rec_id = forms.CharField(label=('Bundle ID'))
public = forms.BooleanField(label=('Public'), required = False)
submission = forms.FileField(label=('Original File'), required = False)
license = LicenseMultipleChoiceField(License.objects, widget=CheckboxSelectMultiple, required=False)
url = forms.URLField(label='URL to the bundle file:', required=False)
content = forms.CharField(label=('Content (in JSON format)'), widget=Textarea(attrs={'class': 'span7'}), required=False)
def clean(self):
self.bundle = ProvBundle()
''' Try to parse content or download and parse URL - one at least needed'''
if self.cleaned_data['content']:
try:
self.bundle._decode_JSON_container(loads(self.cleaned_data['content']))
except ValueError:
raise forms.ValidationError(u'Wrong syntax in the JSON content.')
elif self.cleaned_data['url']:
try:
source = urlopen(self.cleaned_data['url'], timeout=5)
url_content = source.read()
source.close()
except URLError:
raise forms.ValidationError(u'There was a problem accessing the URL.')
try:
self.bundle._decode_JSON_container(loads(url_content))
except ValueError:
raise forms.ValidationError(u'Wrong syntax in the JSON content at the URL.')
else:
raise forms.ValidationError(u'No content or URL provided.')
return self.cleaned_data
def save(self, owner, commit=True):
if self.errors:
raise ValueError("The %s could not be %s because the data didn't"
" validate." % ('Container', 'created'))
container = Container.create(self.cleaned_data['rec_id'], self.bundle, owner, self.cleaned_data['public'])
save = False
if 'submission' in self.files:
file_sub = self.files['submission']
sub = Submission.objects.create()
sub.content.save(sub.timestamp.strftime('%Y-%m-%d%H-%M-%S')+file_sub._name, file_sub)
container.submission = sub
save = True
for l in self.cleaned_data['license']:
container.license.add(l)
save = True
if save:
container.save()
return container
示例6: decode_json_document
def decode_json_document(content, document):
bundles = dict()
if 'bundle' in content:
bundles = content['bundle']
del content['bundle']
decode_json_container(content, document)
for bundle_id, bundle_content in bundles.items():
bundle = ProvBundle(document=document)
decode_json_container(bundle_content, bundle)
document.add_bundle(bundle, bundle.valid_qualified_name(bundle_id))
示例7: create_bundle_mop_login
def create_bundle_mop_login(user_id, session_key):
'''User id 2 logs into the system'''
bundle_id = 'b:%s/login' % session_key
b = ProvBundle(namespaces=DEFAULT_NAMESPACES)
u = b.agent('mopuser:%d' % user_id)
ag = b.agent('mopuser:%d/%s' % (user_id, session_key))
now = datetime.datetime.now()
a = b.activity('log:%d/login/%s' % (user_id, session_key), now, now, other_attributes=[('prov:type', 'act:MopAccountLogin')])
b.wasAssociatedWith(a, u)
b.wasGeneratedBy(ag, a)
b.specializationOf(ag, u)
return bundle_id, b
示例8: test_add_bundle_document
def test_add_bundle_document(self):
d1 = self.document_1()
d2 = self.document_2()
def sub_test_1():
d1.add_bundle(d2)
self.assertRaises(ProvException, sub_test_1)
ex2_b2 = d2.valid_qualified_name('ex:b2')
d1.add_bundle(d2, 'ex:b2')
self.assertEqual(ex2_b2, first(d1.bundles).identifier)
self.assertNotIn(d2, d1.bundles)
b2 = ProvBundle()
b2.update(d2)
self.assertIn(b2, d1.bundles)
示例9: test_merging_records_json
def test_merging_records_json(self):
test_json = """
{
"entity": {
"e1": [
{"prov:label": "First instance of e1"},
{"prov:label": "Second instance of e1"}
]
},
"activity": {
"a1": [
{"prov:label": "An activity with no time (yet)"},
{"prov:startTime": "2011-11-16T16:05:00"},
{"prov:endTime": "2011-11-16T16:06:00"}
]
}
}"""
g = ProvBundle.from_provjson(test_json)
e1 = g.get_record("e1")
self.assertEqual(
len(e1.get_attribute("prov:label")), 2, "e1 was not merged correctly, expecting two prov:label attributes"
)
a1 = g.get_record("a1")
self.assertIsNotNone(a1.get_startTime(), "a1 was not merged correctly, expecting startTime set.")
self.assertIsNotNone(a1.get_endTime(), "a1 was not merged correctly, expecting startTime set.")
self.assertEqual(
len(a1.get_attribute("prov:label")), 1, "a1 was not merged correctly, expecting one prov:label attribute"
)
示例10: get_document
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 ProvBundle
prov_document = ProvBundle()
prov_document._decode_JSON_container(json.loads(response))
return prov_document
else:
# return the raw response
return response
示例11: setUp
def setUp(self):
logging.debug('Setting up user and checking the URL file...')
self.check_u = User.objects.get_or_create(username='FileTesting')
self.user = self.check_u[0]
self.check_k = ApiKey.objects.get_or_create(user=self.user)
self.key = self.check_k[0]
self.auth = 'ApiKey' + self.user.username + ':' + self.key.key
self.check_u = self.check_u[1]
self.check_k = self.check_k[1]
self.url = 'http://users.ecs.soton.ac.uk/ab9g10/test.json'
source = urlopen(self.url)
url_content = ProvBundle()
url_content._decode_JSON_container(json.loads(source.read()))
source.close()
self.content = PDBundle.create('url_test')
self.content.save_bundle(url_content)
self.content = self.content.get_prov_bundle()
示例12: create_bundle_mop_logout
def create_bundle_mop_logout(user_id, session_key):
bundle_id = 'b:%s/logout' % session_key
b = ProvBundle(namespaces=DEFAULT_NAMESPACES)
b.add_namespace('ns', b.valid_identifier(bundle_id + '/').get_uri())
ag = b.agent('mopuser:%d/%s' % (user_id, session_key))
now = datetime.datetime.now()
a = b.activity('log:%d/login/%s' % (user_id, session_key), now, now, other_attributes=[('prov:type', 'act:MopAccountLogout')])
b.wasInvalidatedBy(ag, a) # This user+session no longer exists after this
return bundle_id, b
示例13: datatypes
def datatypes():
g = ProvBundle()
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)}
multiline = """Line1
Line2
Line3"""
attributes['ex:multi-line'] = multiline
g.entity('ex:e1', attributes)
return g
示例14: create_bundle_mop_register
def create_bundle_mop_register(cron, mop, session_key):
'''An mop user account is created'''
bundle_id = 'b:registration/%d' % mop.id
b = ProvBundle(namespaces=DEFAULT_NAMESPACES)
s = b.agent('cronuser:%d/%s' % (cron.id, session_key))
u = b.agent('mopuser:%d' % mop.id, [('foaf:name', mop.user.username)])
now = datetime.datetime.now()
a = b.activity('log:%d/register' % mop.id, now, now, other_attributes=[('prov:type', 'act:MopAccountRegistration')])
b.wasGeneratedBy(u, a)
b.wasAssociatedWith(a, s)
return bundle_id, b
示例15: create_bundle_cron_register
def create_bundle_cron_register(cron):
'''An cron user account is created'''
bundle_id = 'b:registration/%d' % cron.id
b = ProvBundle(namespaces=DEFAULT_NAMESPACES)
s = b.agent("server:1")
u = b.agent('cronuser:%d' % cron.id, [('foaf:name', cron.user.username)])
now = datetime.datetime.now()
a = b.activity('log:%d/register' % cron.id, now, now, other_attributes=[('prov:type', 'act:CronAccountRegistration')])
b.wasGeneratedBy(u, a)
b.wasAssociatedWith(a, s)
return bundle_id, b