Esempio n. 1
0
    def __init__(self, name="MianBot"):
        self.name = name  # The name of chatbot.

        self.speech = ''  # The lastest user's input
        self.speech_domain = ''  # The domain of speech.
        self.speech_matchee = ''  # The matchee term of speech.
        self.speech_path = None  # The classification tree traveling path of speech.
        self.speech_seg = []

        self.root_domain = None  # The root domain of user's input.
        self.domain_similarity = 0.0  # The similarity between domain and speech.

        cur_dir = os.getcwd()
        os.chdir(os.path.dirname(__file__))
        self.extract_attr_log = open('log/extract_arrt.log',
                                     'w',
                                     encoding='utf-8')
        self.exception_log = open('log/exception.log', 'w', encoding='utf-8')
        os.chdir(cur_dir)

        # For rule matching
        self.console = console.Console(model_path="model/ch-corpus-3sg.bin")
        self.custom_rulebase = crb.CustomRuleBase()  # for one time matching.
        self.custom_rulebase.model = self.console.rb.model  # pass word2vec model

        # For QA
        self.github_qa_unupdated = True
        if not self.github_qa_unupdated:
            self.answerer = qa.Answerer()

        self.default_response = ["是嗎?", "我不太明白你的意思", "原來如此"]
Esempio n. 2
0
    def __init__(self,
                 name="MianBot",
                 build_console=True,
                 w2v_model_path="model/ch-corpus-3sg.bin"):
        """
        # Args:
         - build_console: whether to construct topic matching based on word vectors console,
         如果只需要 qa 模組,可將 build_console 關閉,可見 demo_qa.py
        """

        self.name = name  # The name of chatbot.

        self.speech = ''  # The lastest user's input
        self.speech_domain = ''  # The domain of speech.
        self.speech_matchee = ''  # The matchee term of speech.
        self.speech_path = None  # The classification tree traveling path of speech.
        self.speech_seg = []

        self.root_domain = None  # The root domain of user's input.
        self.domain_similarity = 0.0  # The similarity between domain and speech.

        cur_dir = os.getcwd()
        os.chdir(os.path.dirname(__file__))
        self.extract_attr_log = open('log/extract_arrt.log',
                                     'w',
                                     encoding='utf-8')
        self.exception_log = open('log/exception.log', 'w', encoding='utf-8')
        os.chdir(cur_dir)

        # For rule matching
        if build_console:
            self.console = console.Console(model_path=w2v_model_path)
            # self.custom_rulebase = crb.CustomRuleBase() # for one time matching.
            # self.custom_rulebase.model = self.console.rb.model # pass word2vec model

        # For Question Answering
        self.github_qa_unupdated = False
        if not self.github_qa_unupdated:
            try:
                self.answerer = qa.Answerer()
            except Exception as exc:
                print(
                    "[QA] Please confirm the directory structure of the questions and answer data set is correct."
                )
                print(
                    "[QA] If you are still getting errors,s change self.github_qa_unupdated to True"
                )

        self.default_response = [
            "Say it again?", "I did not catch that.",
            "I do not know what you mean.", "Huh?"
        ]
Esempio n. 3
0
    def __init__(self,
                 name="阿母",
                 build_console=True,
                 w2v_model_path="model/ch-corpus-3sg.bin"):
        """
        # Args:
         - build_console: 是否要建構依照詞向量進行主題匹配的 console,
         如果只需要 qa 模組,可將 build_console 關閉,可見 demo_qa.py
        """

        self.name = name  # The name of chatbot.

        self.speech = ''  # The lastest user's input
        self.speech_domain = ''  # The domain of speech.
        self.speech_matchee = ''  # The matchee term of speech.
        self.speech_path = None  # The classification tree traveling path of speech.
        self.speech_seg = []

        self.root_domain = None  # The root domain of user's input.
        self.domain_similarity = 0.0  # The similarity between domain and speech.

        cur_dir = os.getcwd()
        os.chdir(os.path.dirname(__file__))
        self.extract_attr_log = open('log/extract_arrt.log',
                                     'w',
                                     encoding='utf-8')
        self.exception_log = open('log/exception.log', 'w', encoding='utf-8')
        os.chdir(cur_dir)

        # For rule matching
        if build_console:
            self.console = console.Console(model_path=w2v_model_path)
            # self.custom_rulebase = crb.CustomRuleBase() # for one time matching.
            # self.custom_rulebase.model = self.console.rb.model # pass word2vec model

        # For Question Answering
        self.github_qa_unupdated = False
        if not self.github_qa_unupdated:

            try:
                self.answerer = qa.Answerer()
            except Exception as exc:
                print("[QA] 請確認問答資料集的目錄結構是否正確")
                print(
                    "[QA] 如尚未取得問答資料集, 請至 Github: zake7749/Chatbot/Readme.md 中下載, 或將 self.github_qa_unupdated 設為 true"
                )

        self.default_response = [
            "是嗎?", "我不太明白你的意思", "原來如此", "可以再說一次嗎", "不要滑手機了快去養成習慣"
        ]