Пример #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
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