Beispiel #1
0
 def __init__(self, args):
     self.args = args
     self.conf = Config()
     self.conf.init('brain-ta.conf')
     if args.engine.lower() == 'nlp1':
         self.remote = 'localhost:{0}'.format(
             self.conf.get('brain-ta.nlp.1.kor.port'))
         channel = grpc.insecure_channel(self.remote)
         self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(
             channel)
     elif args.engine.lower() == 'nlp2':
         self.remote = 'localhost:{0}'.format(
             self.conf.get('brain-ta.nlp.2.kor.port'))
         channel = grpc.insecure_channel(self.remote)
         self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(
             channel)
     elif args.engine.lower() == 'nlp3':
         self.remote = 'localhost:{0}'.format(
             self.conf.get('brain-ta.nlp.3.kor.port'))
         channel = grpc.insecure_channel(self.remote)
         self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(
             channel)
     else:
         print 'Not existed Engine'
         raise Exception('Not existed Engine')
Beispiel #2
0
    def morp_analyze(self, text):
        self.conf.init('brain-ta.conf')
        #nlp_client = NlpClient()

        remote = 'localhost:' + self.conf.get('brain-ta.nlp.1.kor.port')
        channel = grpc.insecure_channel(remote)
        self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(channel)

        nlp_result = self.analyze(text, 1, 1)

        return nlp_result['sentences'][0]['morps']
Beispiel #3
0
 def __init__(self):
     remote = "localhost:{0}".format(
         self.conf.get('brain-ta.nlp.2.kor.port'))
     channel = grpc.insecure_channel(remote)
     self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(channel)
Beispiel #4
0
    def test_nlp(self):
        nlp_client = NlpClient()
        #nlp_client.get_provider()
        # This is related to nlp1 and brain-ta issue 185
        #nlp_client.get_named_entity()

        # NLP analysis level 지정 방법
        # 1. parameter로 지정( or 변수로 할당)
        # level = 0
        # nlp_client.analyze('안녕하세요. 자연어 처리 엔진을 원격으로 호출해요.', level)

        # 2. 사용자가 입력
        while True:
            print("Usage : NLP Analysis Engine")
            print(
                "Level 0 : All NLP Analysis With Morpheme, Named Entity, Word Sense Disambiguation, Dependency Parser, Semantic Role Labeling and Zero Anaphora"
            )
            print("Level 1 : Word, Morpheme")
            print("Level 2 : Level 1 + Named Entity")
            print("Level 3 : Level 2 + Word Sense Disambiguation")
            print("Level 4 : Level 3 + Dependency Parser")
            print("Level 5 : Level 4 + Semantic Role Labeling")
            print("Level 6 : Level 5 + Zero Anaphora")
            print("quit : Exit the System!!")

            select = raw_input("Select NLP Analysis Level : ")

            if select == "quit":
                break

            flag, level = self.is_number(select)

            if flag == True:
                if level > 6 or level < 0:
                    print("Select Error!!")
                    print("You must type only Number range 0-2")
                    continue
                else:
                    print("Usage : Extraction Keyword Frequency Engine")
                    print(
                        "Level 0 : Extract keyword frequency with NP, VP, NamedEntity"
                    )
                    print(
                        "Level 1 : Don't extract keyword frequency with NP, VP, NamedEntity"
                    )
                    keyword_select = raw_input(
                        "Select Keyword Frequency Level :")
                    keyword_flag, keyword_level = self.is_number(
                        keyword_select)
                    if keyword_flag == True:
                        if keyword_level > 1 or keyword_level < 0:
                            print("Select Error!!")
                            print("You must type only Number range 0-1")
                            continue
                        elif keyword_level == 0 or keyword_level == 1:
                            remote = 'localhost:' + conf.get(
                                'brain-ta.nlp.3.kor.port')
                            channel = grpc.insecure_channel(remote)
                            self.stub = nlp_pb2_grpc.NaturalLanguageProcessingServiceStub(
                                channel)
                            start_time = time.time()
                            self.analyze("안녕하세요. 판교에 위치한 회사입니다.", level,
                                         keyword_level)
                            print(time.time() - start_time)
                        else:
                            print("Select Error!!")
                            print("You must type only Number!!")
                            continue
            else:
                print("Select Error!!")
                print("You must type only Number!!")
                continue