当前位置: 首页>>代码示例>>Python>>正文


Python BlockingConnection.process_data_events方法代码示例

本文整理汇总了Python中pika.BlockingConnection.process_data_events方法的典型用法代码示例。如果您正苦于以下问题:Python BlockingConnection.process_data_events方法的具体用法?Python BlockingConnection.process_data_events怎么用?Python BlockingConnection.process_data_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pika.BlockingConnection的用法示例。


在下文中一共展示了BlockingConnection.process_data_events方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_step

# 需要导入模块: from pika import BlockingConnection [as 别名]
# 或者: from pika.BlockingConnection import process_data_events [as 别名]
    def process_step(self, form):
        if self.steps.current == '0':
            text_type = form.data['0-text_type']
            text = form.data['0-text']

            # Prepare message
            uima_response = {}
            uima_response['response'] = None
            uima_corr_id = str(uuid.uuid4())
            uima_body = json.dumps({'text': text, 'mode': text_type, })

            def uima_on_response(channel, method, props, body):
                if uima_corr_id == props.correlation_id:
                     uima_response['response'] = body

            # Call UIMA
            uima_connection = BlockingConnection(ConnectionParameters(host=RABBITMQ_SERVER))
            uima_channel = uima_connection.channel()
            uima_result = uima_channel.queue_declare(exclusive=True)
            uima_callback_queue = uima_result.method.queue
            uima_channel.basic_consume(uima_on_response, no_ack=True, queue=uima_callback_queue)
            uima_channel.basic_publish(exchange='',
                                       routing_key='uima_plain_worker',
                                       properties=BasicProperties(reply_to=uima_callback_queue,
                                                                  content_type='application/json',
                                                                  correlation_id=uima_corr_id, ),
                                       body=uima_body)

            while uima_response['response'] is None:
                uima_connection.process_data_events()

            # Transform result into HTML
            result = uima_response['response']
            result = xmlmap.load_xmlobject_from_string(result, xmlclass=RocheTEI)
            result = result.body.xsl_transform(xsl=XSL_TRANSFORM_1).serialize()
            self.uima_result = result

        return self.get_form_step_data(form)
开发者ID:beijingren,项目名称:roche-website,代码行数:40,代码来源:forms.py

示例2: annotate_text

# 需要导入模块: from pika import BlockingConnection [as 别名]
# 或者: from pika.BlockingConnection import process_data_events [as 别名]
def annotate_text(request, text, function, lemma, juan=-1):
    """
    Annotate a single text. Run UIMA through a remote procedure call.
    """
    from .models import Annotation

    collection_path = None

    #
    # Find the collection path this text belongs to
    #
    os.chdir('/docker/dublin-store/')
    for (dirpath, dirnames, filenames) in os.walk(u'浙江大學圖書館'):
        if dirpath.endswith(unicode(text)):
            collection_path = '/docker/dublin-store/' + dirpath
            break

    #
    # RPC UIMA worker
    #
    uima_response = {}
    uima_response['response'] = None
    uima_corr_id = str(uuid.uuid4())
    uima_body = json.dumps({'text': text,
                            'function': function,
                            'collection_path': collection_path,
                            'juan': juan,
                            'lemma': lemma})

    def uima_on_response(channel, method, props, body):
        if uima_corr_id == props.correlation_id:
            uima_response['response'] = body

    uima_connection = BlockingConnection(ConnectionParameters(host=RABBITMQ_SERVER))
    uima_channel = uima_connection.channel()
    uima_result = uima_channel.queue_declare(exclusive=True)
    uima_callback_queue = uima_result.method.queue
    uima_channel.basic_consume(uima_on_response, no_ack=True, queue=uima_callback_queue)
    uima_channel.basic_publish(exchange='',
                               routing_key='uima_worker',
                               properties=BasicProperties(reply_to=uima_callback_queue,
                                                          content_type='application/json',
                                                          correlation_id=uima_corr_id, ),
                               body=uima_body)

    while uima_response['response'] is None:
        uima_connection.process_data_events()

    response = uima_response['response']
    if response == 'ERROR':
        pass

    # Invalidate page?
    # TODO

    annotation = Annotation()
    annotation.tei_tag = function
    annotation.lemma = lemma
    annotation.ip = request.META['REMOTE_ADDR']
    annotation.save()

    return HttpResponse(response)
开发者ID:beijingren,项目名称:roche-website,代码行数:64,代码来源:views.py


注:本文中的pika.BlockingConnection.process_data_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。