當前位置: 首頁>>代碼示例>>Python>>正文


Python StoragePayload.add_property方法代碼示例

本文整理匯總了Python中rhobot.components.storage.StoragePayload.add_property方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePayload.add_property方法的具體用法?Python StoragePayload.add_property怎麽用?Python StoragePayload.add_property使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rhobot.components.storage.StoragePayload的用法示例。


在下文中一共展示了StoragePayload.add_property方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _find_work_node

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _find_work_node(self, session):
        """
        Find a node to work over.
        :param session:
        :return:
        """

        def _handle_cypher_result(_result):
            """
            Handle the results from the cypher result.  If there as no result found then reject the promise, otherwise
            update the session with the uri of the node, and
            :param _result:
            :return:
            """
            if not _result.results:
                raise Exception("No results to work")

            node_uri = _result.results[0].about

            session["node_uri"] = node_uri

            return session

        payload = StoragePayload()
        payload.add_property(key=NEO4J.cypher, value=self.query)
        promise = self._storage_client.execute_cypher(payload).then(_handle_cypher_result)

        return promise
開發者ID:rerobins,項目名稱:rho_timeline,代碼行數:30,代碼來源:maintainer.py

示例2: test_unpack

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [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)
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:30,代碼來源:test_storage_payload.py

示例3: test_pack_unpacked_payload

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [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)
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:32,代碼來源:test_storage_payload.py

示例4: test_get_node

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def test_get_node(self):

        self.storage_client._store_found('[email protected]/storage')

        payload = StoragePayload()
        payload.about = 'http://www.example.org/instance/01'
        payload.add_type(FOAF.Person)
        payload.add_property(FOAF.name, 'Robert')

        promise = self.storage_client.get_node(payload)

        def handle_result(result):
            self.session['result'] = result

        promise.then(handle_result)

        self.assertTrue(hasattr(promise, 'then'))

        self.send("""
                <iq type="set" to="[email protected]/storage" id="1">
                    <command xmlns="http://jabber.org/protocol/commands"
                        node="get_node"
                        action="execute">
                        <x xmlns="jabber:x:data" type="form">
                            <field var="http://www.w3.org/1999/02/22-rdf-syntax-ns#about" type="text-single">
                                <value>http://www.example.org/instance/01</value>
                            </field>
                            <field var="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" type="list-multi">
                                <value>http://xmlns.com/foaf/0.1/Person</value>
                            </field>
                            <field var="http://xmlns.com/foaf/0.1/name" type="list-multi">
                                <value>Robert</value>
                                <validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:string" />
                            </field>
                        </x>
                    </command>
                </iq>
            """)

        self.assertNotIn('result', self.session)

        self.recv("""
                <iq type='result' from='[email protected]/storage' to='[email protected]/full' id='1'>
                    <command xmlns='http://jabber.org/protocol/commands'
                           sessionid='list:20020923T213616Z-700'
                           node='get_node'
                           status='completed'>
                            %s
                    </command>
                </iq>
            """ % payload.populate_payload())

        time.sleep(0.2)

        self.assertIn('result', self.session)

        result = self.session['result']

        self.assertEqual(result.about, 'http://www.example.org/instance/01')
        self.assertEquals(result.types[0], str(FOAF.Person))
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:62,代碼來源:test_get_node.py

示例5: convert_rdf_json_to_storage

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [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
開發者ID:rerobins,項目名稱:rho_erudite,代碼行數:36,代碼來源:utilities.py

示例6: _create_event

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [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
開發者ID:rerobins,項目名稱:rho_journal_bot,代碼行數:30,代碼來源:create_event.py

示例7: _create_payload

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _create_payload(self):

        update_payload = StoragePayload()
        update_payload.add_type(FOAF.Agent, RDFS.Resource)
        update_payload.add_property(RDFS.seeAlso, self.xmpp.get_uri())
        update_payload.add_property(FOAF.name, self.xmpp.name)

        return update_payload
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:10,代碼來源:representation_manager.py

示例8: test_execute_cypher

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def test_execute_cypher(self):

        self.storage_client._store_found('[email protected]/storage')

        payload = StoragePayload()
        payload.add_property(NEO4J.cypher, 'Match (n) RETURN n LIMIT 25')

        promise = self.storage_client.execute_cypher(payload)

        def handle_result(result):
            self.session['result'] = result

        promise.then(handle_result)

        self.assertTrue(hasattr(promise, 'then'))

        self.send("""
                <iq type="set" to="[email protected]/storage" id="1">
                    <command xmlns="http://jabber.org/protocol/commands"
                        node="cypher"
                        action="execute">
                        <x xmlns="jabber:x:data" type="form">
                            <field var="http://www.neo4j.com/terms/#cypher" type="list-multi">
                                <value>Match (n) RETURN n LIMIT 25</value>
                                <validate xmlns="http://jabber.org/protocol/xdata-validate" datatype="xs:string" />
                            </field>
                        </x>
                    </command>
                </iq>
            """)

        self.assertNotIn('result', self.session)

        result_payload = ResultCollectionPayload()
        result_payload.append(ResultPayload(about='http://www.example.org/instance/01',
                                            types=[FOAF.Person]))

        self.recv("""
                <iq type='result' from='[email protected]/storage' to='[email protected]/full' id='1'>
                    <command xmlns='http://jabber.org/protocol/commands'
                           sessionid='list:20020923T213616Z-700'
                           node='cypher'
                           status='completed'>
                            %s
                    </command>
                </iq>
            """ % result_payload.populate_payload())

        time.sleep(0.2)

        self.assertIn('result', self.session)

        result = self.session['result']

        self.assertEqual(1, len(result.results))

        self.assertEqual(result.results[0].about, 'http://www.example.org/instance/01')
        self.assertEquals(result.results[0].types[0], str(FOAF.Person))
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:60,代碼來源:test_execute_cypher.py

示例9: _start

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _start(self, event):
        payload = StoragePayload()
        payload.add_type(FOAF.Agent, RDFS.Resource)
        payload.add_property(RDFS.seeAlso, self.xmpp.get_uri())

        promise = self._storage_client.find_nodes(payload)

        node_found_promise = promise.then(self._node_found)

        node_found_promise.then(self._update_node, self._create_node)
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:12,代碼來源:representation_manager.py

示例10: test_request_data_with_payload

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def test_request_data_with_payload(self):

        foursquare_uri = 'foursquare://venues/4be0b4f0652b0f475f607311'

        storage_payload = StoragePayload()

        storage_payload.add_type(WGS_84.SpatialThing)
        storage_payload.add_property(RDFS.seeAlso, foursquare_uri)

        result = get_foursquare_venue(storage_payload)

        self.assertEqual(result, foursquare_uri.split('/')[-1])
開發者ID:rerobins,項目名稱:rho_foursquare_bot,代碼行數:14,代碼來源:test_utilities.py

示例11: _find_work_node

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _find_work_node(self, session):
        """
        Find node to do work over.
        :return:
        """
        logger.debug('Executing query: %s' % self.query)

        payload = StoragePayload()
        payload.add_property(key=NEO4J.cypher, value=self.query)
        promise = self._storage_client.execute_cypher(payload).then(
            self._scheduler.generate_promise_handler(self._handle_results, session))

        return promise
開發者ID:rerobins,項目名稱:rho_foursquare_bot,代碼行數:15,代碼來源:maintainer.py

示例12: _process_lookup_result

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _process_lookup_result(self, result, payload):
        """
        This will split the promise chain in two.  If the result returns a value, then the promise will drop off.  If
        the result doesn't exist, then do an rdf publish and return the result of that.
        :param result: the result of the get_command.
        :param payload: the payload that was used to look up the data.
        :return: a value or a promise that will return the value.
        """
        if result.about:
            return result.about

        location_request = StoragePayload()
        location_request.add_type(*payload.types)
        location_request.add_property(RDFS.seeAlso, payload.about)

        promise = self._rdf_publish.send_out_request(location_request)
        promise.then(self._lookup_handler)

        return promise
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:21,代碼來源:get_or_lookup.py

示例13: command_start

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [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
開發者ID:rerobins,項目名稱:rho_neo_backend,代碼行數:44,代碼來源:get_node.py

示例14: _update_node

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def _update_node(self, node_identifier, start_time, end_time):
        """
        Update the node and schedule the publishing of the update method.
        :param start_time:
        :param end_time:
        :return:
        """
        payload = StoragePayload()
        payload.about = node_identifier
        payload.add_type(TIMELINE.Interval)
        if start_time:
            payload.add_property(TIMELINE.start, start_time)

        if end_time:
            payload.add_property(TIMELINE.end, end_time)

        promise = self._storage_client.update_node(payload)

        promise.then(self._scheduler.generate_promise_handler(self._rdf_publish.publish_all_results, created=False))

        return promise.then(self._handle_result)
開發者ID:rerobins,項目名稱:rho_move_bot,代碼行數:23,代碼來源:interval_handler.py

示例15: test_no_storage_defined

# 需要導入模塊: from rhobot.components.storage import StoragePayload [as 別名]
# 或者: from rhobot.components.storage.StoragePayload import add_property [as 別名]
    def test_no_storage_defined(self):

        payload = StoragePayload()
        payload.add_property(NEO4J.cypher, 'Match (n) RETURN n LIMIT 25')

        promise = self.storage_client.execute_cypher(payload)

        def handle_result(result):
            self.session['result'] = result

        def handle_error(result):
            self.session['error'] = result

        promise.then(handle_result, handle_error)

        self.assertTrue(hasattr(promise, 'then'))

        time.sleep(0.2)

        self.assertNotIn('result', self.session)
        self.assertIn('error', self.session)
開發者ID:rerobins,項目名稱:rhobot_framework,代碼行數:23,代碼來源:test_execute_cypher.py


注:本文中的rhobot.components.storage.StoragePayload.add_property方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。