本文整理匯總了Python中rhobot.components.storage.StoragePayload.add_reference方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.add_reference方法的具體用法?Python StoragePayload.add_reference怎麽用?Python StoragePayload.add_reference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rhobot.components.storage.StoragePayload
的用法示例。
在下文中一共展示了StoragePayload.add_reference方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pack_unpacked_payload
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def test_pack_unpacked_payload(self):
form = Form()
payload = StoragePayload(form)
about = "urn:rho:identified_by:asdf"
see_also = "urn:rho.value"
mbox = "mailto:[email protected]"
create_if_missing = True
payload.about = about
payload.add_type(FOAF.Person)
payload.add_property(RDFS.seeAlso, see_also)
payload.add_reference(FOAF.mbox, mbox)
payload.add_flag(FindFlags.CREATE_IF_MISSING, create_if_missing)
content = payload.populate_payload()
second_payload = StoragePayload(content)
second_content = second_payload.populate_payload()
self.assertIsNotNone(second_content)
self.assertEqual(second_content.get_fields()[str(RDF.about)].get_value(), about)
self.assertEqual(second_content.get_fields()[str(RDFS.seeAlso)].get_value(), [see_also])
self.assertEqual(second_content.get_fields()[str(FOAF.mbox)].get_value(), [mbox])
self.assertEqual(second_content.get_fields()[FindFlags.CREATE_IF_MISSING.var].get_value(), create_if_missing)
示例2: test_unpack
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def test_unpack(self):
form = Form()
payload = StoragePayload(form)
about = "urn:rho:identified_by:asdf"
see_also = "urn:rho.value"
mbox = "mailto:[email protected]"
create_if_missing = True
payload.about = about
payload.add_type(FOAF.Person)
payload.add_property(RDFS.seeAlso, see_also)
payload.add_reference(FOAF.mbox, mbox)
payload.add_flag(FindFlags.CREATE_IF_MISSING, create_if_missing)
content = payload.populate_payload()
second_payload = StoragePayload(content)
self.assertEqual(second_payload.about, about)
self.assertIn(str(FOAF.Person), second_payload.types)
self.assertEqual(second_payload.properties[str(RDFS.seeAlso)], [see_also])
self.assertEqual(second_payload.references[str(FOAF.mbox)], [mbox])
self.assertEqual(FindFlags.CREATE_IF_MISSING.fetch_from(second_payload.flags), create_if_missing)
示例3: convert_rdf_json_to_storage
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def convert_rdf_json_to_storage(
definition, store_types=True, store_properties=True, store_bnodes=True, bnode_mappings=None
):
"""
Convert RDF JSON values into a storage payload.
:param definition: dictionary containing the json data.
:param store_types: should store the type values of the definition.
:param store_properties: should store the property values of the definition.
:param store_bnodes: should store the bnodes of the definition.
:param bnode_mappings: dictionary containing a translation key for the bnodes.
:return: newly created storage payload object.
"""
if not bnode_mappings:
bnode_mappings = {}
result = StoragePayload()
for node_uri, values in definition.iteritems():
if node_uri == str(RDF.type):
if store_types:
for value in values:
result.add_type(value["value"])
else:
for value in values:
if store_properties and value["type"] == "literal":
result.add_property(node_uri, value["value"])
elif store_bnodes and value["type"] == "bnode":
if value["value"] in bnode_mappings:
result.add_reference(node_uri, bnode_mappings[value["value"]])
else:
logger.error("Couldn't find bnode mapping for: %s" % value["value"])
return result
示例4: _create_event
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def _create_event(self, session, form_payload):
"""
Convert the form payload into a storage payload for creating a new event.
:param session:
:param form_payload:
:return:
"""
create_event_payload = StoragePayload()
create_event_payload.add_type(EVENT.Event)
create_event_payload.add_reference(key=EVENT.agent, value=session['owner'])
create_event_payload.add_reference(key=DCTERMS.creator, value=self._representation_manager.representation_uri)
if 'title' in form_payload.get_values():
create_event_payload.add_property(key=DC.title, value=form_payload.get_values()['title'])
if 'description' in form_payload.get_values():
create_event_payload.add_property(key=DC.description, value=form_payload.get_values()['description'])
if session['location']:
create_event_payload.add_reference(key=EVENT.place, value=session['location'])
if session['interval']:
create_event_payload.add_reference(key=EVENT.time, value=session['interval'])
promise = self._storage_client.create_node(create_event_payload)
return promise
示例5: _handle_create_and_update_session
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def _handle_create_and_update_session(_result):
timeline = _result.results[0].about
update_payload = StoragePayload()
update_payload.about = timeline_map.about
update_payload.add_reference(TIMELINE.rangeTimeLine, timeline)
# Publish the create event
self._rdf_publish.publish_all_results(_result, created=True)
_promise = self._storage_client.update_node(update_payload)
_promise = _promise.then(
self._scheduler.generate_promise_handler(self._rdf_publish.publish_all_results, created=False)
)
_promise = _promise.then(lambda s: timeline)
return _promise
示例6: _update_interval
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def _update_interval(self, session):
"""
Now that the timeline stuff has been found, update the interval as well.
:param session:
:return:
"""
def return_session(result):
self._rdf_publish.publish_all_results(result, created=False)
return session
update_payload = StoragePayload()
update_payload.about = session["node"].about
update_payload.add_reference(TIMELINE.timeline, session["timelines"])
update_payload.add_flag(UpdateFlags.REPLACE_DEFINED, True)
return self._storage_client.update_node(update_payload).then(return_session)
示例7: command_start
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def command_start(self, iq, initial_session):
"""
Starting point for creating a new node.
:param iq:
:param initial_session:
:return:
"""
if not initial_session['payload']:
initial_session['notes'] = [('error', 'Cannot execute without a payload')]
else:
logger.info('Get Node iq: %s' % iq)
logger.info('Initial_session: %s' % initial_session)
payload = StoragePayload(initial_session['payload'])
logger.debug('about: %s' % payload.about)
node = self._command_handler.get_node(payload.about, create=False)
if node:
result_payload = StoragePayload()
result_payload.about = node.uri
# Get the types into place.
for label in node.labels:
result_payload.add_type(label)
# Gather up all of the references
for relationship in node.match_outgoing():
result_payload.add_reference(relationship.type, relationship.end_node.uri)
# Gather up all of the properties
for key, value in node.properties.iteritems():
if isinstance(value, list):
for val in value:
result_payload.add_property(key, val)
else:
result_payload.add_property(key, value)
initial_session['payload'] = result_payload.populate_payload()
return initial_session
示例8: update_venue_details
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def update_venue_details(venue):
# No point in continuing this exercise if certain requirements are not resolved.
if not venue:
raise RuntimeError('Venue identifier is not defined')
if not self._foursquare_client:
raise RuntimeError('Foursquare client is not defined')
# Finished checking requirements, fetch the details and update.
logger.debug('Looking up venue: %s' % venue)
venue_details = self._foursquare_client.venues(venue)
# Translate the venue details into a rdf storage payload for sending to update.
if 'venue' in venue_details:
storage_payload = StoragePayload()
foursquare_to_storage(venue_details['venue'], storage_payload)
storage_payload.about = node_uri
storage_payload.add_reference(DCTERMS.creator, self._representation_manager.representation_uri)
return self._storage_client.update_node(storage_payload)
示例9: _get_range_timeline
# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_reference [as 別名]
def _get_range_timeline(self, timeline_map):
"""
Get or create the range timeline for the origin map that was previously found.
:param timeline_map: the timeline map.
:return:
"""
time_lines = timeline_map.references.get(str(TIMELINE.rangeTimeLine), None)
if time_lines:
return time_lines[0]
def _handle_create_and_update_session(_result):
timeline = _result.results[0].about
update_payload = StoragePayload()
update_payload.about = timeline_map.about
update_payload.add_reference(TIMELINE.rangeTimeLine, timeline)
# Publish the create event
self._rdf_publish.publish_all_results(_result, created=True)
_promise = self._storage_client.update_node(update_payload)
_promise = _promise.then(
self._scheduler.generate_promise_handler(self._rdf_publish.publish_all_results, created=False)
)
_promise = _promise.then(lambda s: timeline)
return _promise
# otherwise it needs to be created and then return.
create_payload = StoragePayload()
create_payload.add_type(TIMELINE.RelativeTimeLine)
create_payload.add_reference(DCTERMS.creator, self._representation_manager.representation_uri)
promise = self._storage_client.create_node(create_payload).then(_handle_create_and_update_session)
return promise