コード例 #1
0
def run():
    serv = ServiceClient(nlp_service, 'CabochaNlpProcsStub', 'localhost', 50051)
    # Insert example metadata
    metadata = [('ip', '127.0.0.1')]
    response = serv.Tokenizer(
        nlp_messages.NlText(text="お皿を二枚ください。"),
        metadata=metadata
    )
    if response:
        print("response:")
        tokens=tokenize_msg("お皿を二枚ください。", response)
        for t in tokens:
            print(t.text, t.offset)
コード例 #2
0
def run():
    users = ServiceClient(users_service, 'UsersStub', 'localhost', 50051)
    # Insert example metadata
    metadata = [('ip', '127.0.0.1')]
    response = users.CreateUser(
        users_messages.CreateUserRequest(username='******'), metadata=metadata)
    if response:
        print("User created:", response.user.username)
    request = users_messages.GetUsersRequest(user=[
        users_messages.User(username="******", user_id=1),
        users_messages.User(username="******", user_id=1)
    ])
    response = users.GetUsers(request)
    for resp in response:
        print(resp)
コード例 #3
0
ファイル: hanlp_client.py プロジェクト: CoderOverflow/stack
class HanlpClient(object):
    def __init__(self, host='localhost', port=10052):
        logger.info("connect to hanlp provider %s %d ..."%(host, port))
        self.client=ServiceClient(nlp_service, 'NlpProcsStub', host, port)

    def get_deps(self, text):
        request = nlp_messages.NlTexts(texts=[nlp_messages.NlText(text=text)])
        response = self.client.GetDependencyGraph(request)
        return response

    def disp_deps(self, text):
        """
        $ python -m sagas.bots.hanlp_client disp_deps '苹果电脑可以运行开源阿尔法狗代码吗'
        :param text:
        :return:
        """
        response=self.get_deps(text)
        print('✔', response.summary)

        if 'zh_SBV|text' in response.coreGraph:
            print('♟ sbv', response.coreGraph['zh_SBV|text'])
        if 'zh_VOB|head' in response.coreGraph:
            print('\t► vob.head', response.coreGraph['zh_VOB|head'])
        if 'zh_VOB|text' in response.coreGraph:
            print('\t\t✜ vob', response.coreGraph['zh_VOB|text'])

        for k,v in response.coreGraph.items():
            print(k,v)

    def put_deps(self, sents, props):
        response = self.get_deps(sents)
        for k, v in response.coreGraph.items():
            props[k]=v

    def extract(self, text):
        request = nlp_messages.NlTokenizerRequest(text=nlp_messages.NlText(text=text))
        response = self.client.EntityExtractor(request)
        return response
コード例 #4
0
ファイル: cabocha_utils.py プロジェクト: CoderOverflow/stack
    def create_client(cls, component_conf):
        try:
            rpc_host = component_conf.get("host")
            rpc_port = component_conf.get("port")

            # if no model is specified, we fall back to the language string
            # if not spacy_model_name:
            logger.info("Trying to connect cabocha rpc with "
                        "address '{}:{}'".format(rpc_host, rpc_port))

            client = ServiceClient(nlp_service, 'CabochaNlpProcsStub', rpc_host, int(rpc_port))
            return client
        except ValueError as e:  # pragma: no cover
            raise Exception("cabocha init error. {}".format(e))
コード例 #5
0
def users_get():
    app.config['users'] = ServiceClient(users_service, 'UsersStub', 'users',
                                        50051)
    request = users_messages.GetUsersRequest(user=[
        users_messages.User(username="******", user_id=1),
        users_messages.User(username="******", user_id=1)
    ])

    def get_user():
        response = app.config['users'].GetUsers(request)
        for resp in response:
            yield MessageToJson(resp)

    return Response(get_user(), content_type='application/json')
コード例 #6
0
ファイル: action_broker.py プロジェクト: CoderOverflow/stack
class HanlpDelegator(object):
    def __init__(self):
        self.client = ServiceClient(nlp_service, 'NlpProcsStub', 'localhost',
                                    10052)

    async def handle(self, req: BlueInteract):
        cnt = BotMessage()
        cnt.ParseFromString(req.body)
        result = self.extract(cnt.message)
        response = result.SerializeToString()
        return response

    def tokenize(self, text):
        request = nlp_messages.NlTokenizerRequest(text=nlp_messages.NlText(
            text=text))
        response = self.client.Tokenizer(request)
        return response

    def extract(self, text):
        request = nlp_messages.NlTokenizerRequest(text=nlp_messages.NlText(
            text=text))
        response = self.client.EntityExtractor(request)
        return response
コード例 #7
0
def get_serv():
    from client_wrapper import ServiceClient
    serv = ServiceClient(sc_service, 'EntityServantStub', 'localhost', 50051)
    return serv
コード例 #8
0
from flask import Flask, Response, jsonify, request
import sys, json
from bson.json_util import dumps
from google.protobuf.json_format import MessageToJson
from client_wrapper import ServiceClient

import todoCRUD_pb2 as todoCRUD
import todoCRUD_pb2_grpc as todoCRUDGrpc

app = Flask(__name__)
app.config['tasks'] = ServiceClient(todoCRUDGrpc, 'ToDoCRUDStub', 'localhost',
                                    50051)


@app.route('/api/v1.0/task/<id>', methods=['PUT', 'GET', 'DELETE'])
def task(id):

    requestCRUD = todoCRUD.SingleRequest(_id=int(id))

    if (request.method == 'DELETE'):

        def delete_task():
            response = app.config['tasks'].taskDelete(requestCRUD)
            return "Task Deleted :p"

        return Response(delete_task())

    elif (request.method == 'PUT'):
        _data = request.get_json(silent=True)
        requestCRUD = todoCRUD.UpdateRequest(_id=int(id),
                                             title=_data['title'],
コード例 #9
0
ファイル: app.py プロジェクト: amitsaha/python-grpc-demo
from flask import Flask, Response
import sys

from google.protobuf.json_format import MessageToJson
from client_wrapper import ServiceClient

import users_pb2_grpc as users_service
import users_types_pb2 as users_messages

app = Flask(__name__)
app.config['users'] = ServiceClient(users_service, 'UsersStub', 'users', 50051)


@app.route('/users/')
def users_get():
    request = users_messages.GetUsersRequest(user=[
        users_messages.User(username="******", user_id=1),
        users_messages.User(username="******", user_id=1)
    ])

    def get_user():
        response = app.config['users'].GetUsers(request)
        for resp in response:
            yield MessageToJson(resp)

    return Response(get_user(), content_type='application/json')
コード例 #10
0
sys.path.extend([
    '../grpc-services/protos/gen-py', '../grpc-services', 'grpc-services',
    'grpc-services/protos/gen-py'
])
from google.protobuf.json_format import MessageToJson
from client_wrapper import ServiceClient

import users_pb2_grpc as users_service
import users_types_pb2 as users_messages

import airlines_pb2_grpc as airlines_service
import airlines_types_pb2 as airlines_messages

app = Flask(__name__)
app.config['users'] = ServiceClient(users_service, 'UsersStub', 'localhost',
                                    50061)
app.config['airlines'] = ServiceClient(airlines_service, 'AirlinesStub',
                                       'localhost', 50061)


@app.route('/users/')
def users_get():
    request = users_messages.GetUsersRequest(user=[
        users_messages.User(username="******", user_id=1),
        users_messages.User(username="******", user_id=1)
    ])

    response_list = []

    def get_users():
        response = app.config['users'].GetUsers(request)
コード例 #11
0
ファイル: hanlp_client.py プロジェクト: CoderOverflow/stack
 def __init__(self, host='localhost', port=10052):
     logger.info("connect to hanlp provider %s %d ..."%(host, port))
     self.client=ServiceClient(nlp_service, 'NlpProcsStub', host, port)
コード例 #12
0
import services_common_pb2 as sc
import services_common_pb2_grpc as sc_service
from client_wrapper import ServiceClient
from sagas.conf.conf import cf

serv = ServiceClient(sc_service, 'EntityServantStub', 'localhost', 50051)


def a_query():
    q = sc.InfoQuery(queryItems=[""])
    names = serv.GetEntityNames(q)
    print(names)


def a_store():
    from values_pb2 import TaStringEntries, TaStringEntriesBatch
    from sagas.util.string_util import abbrev
    import xml.etree.ElementTree as ET
    from sagas.ofbiz.entity_prefabs import EntityPrefabs
    xml_file = f'{cf.conf_dir}/stack/data/product/ProductPriceTestData.xml'
    tree = ET.parse(xml_file)
    root = tree.getroot()
    ep = EntityPrefabs()
    record_set, ids = ep.convert_to_record_set(root)

    rs = []
    for item in record_set:
        rs.append(item[1])
        print(item[1].entityName)  # TaStringEntries
        print('\t', abbrev(item[0]))
    batch = TaStringEntriesBatch(records=rs)
コード例 #13
0
ファイル: app.py プロジェクト: Ajay-Raj-S/student_grpc_server
from flask import Flask, Response, request
import sys

from google.protobuf.json_format import MessageToJson
from client_wrapper import ServiceClient

import get_students_pb2_grpc as student_services
import get_students_pb2 as students_messages

app = Flask(__name__)
app.config['students'] = ServiceClient(student_services, 'StudentsStub',
                                       'localhost', 50051)


@app.route('/')
def get_student_details():
    stud_id = request.args.get('id', 1)
    req = students_messages.get_student_id(student_id=int(stud_id))
    response = app.config['students'].StudentDetails(req)
    response = MessageToJson(response)
    print(response)
    return Response(response, content_type='application/json')


if __name__ == '__main__':
    app.run()
コード例 #14
0
ファイル: action_broker.py プロジェクト: CoderOverflow/stack
 def __init__(self):
     self.client = ServiceClient(nlp_service, 'NlpProcsStub', 'localhost',
                                 10052)