예제 #1
0
    def test_response(self):
        node = InfoNode()
        test_verbs = ["be", "do", "build", "make", "Cannot Understand"]

        for verb in test_verbs:
            node.load_query(verb)
            resp = node.response()
            self.assertIsInstance(
                resp, str,
                "response test failed at verb: {}. Got instance of {}, expected instance of str"
                .format(verb, type(resp)))
예제 #2
0
    def test_generate_random_response(self):
        node = InfoNode()
        test_verbs = ["be", "do", "build", "make", "Cannot Understand"]

        for true_verb in test_verbs:
            verbs = node.generate_random_response(true_verb, test=True)

            self.assertTrue(
                true_verb in verbs,
                "generate_random_response test failed at verb: {}. Got response for verb(s): {}, expecting response for verb: {}."
                .format(true_verb, verbs, true_verb))
예제 #3
0
    def test_random_response(self):
        node = InfoNode()
        make_response = node.random_make_response()
        be_response = node.random_be_response()

        self.assertIsInstance(
            make_response, str,
            'make response returned instance of {}, expected instance of str'.
            format(type(make_response)))
        self.assertIsInstance(
            be_response, str,
            'be response returned instance of {}, expected instance of str'.
            format(type(be_response)))
예제 #4
0
    def response(self):
        """
        Function to return the the response bases on the query.

        This function checks the query passed in by the user, and returns the
        response from the appopriate query. The query should have already been
        passed in when creating the "InferenceNetwork" object.
        ----------
        self    : none

        Returns
        -------
        response  : string
            The appropriate response to the user's input query
        """
        if self.node_type == "info":
            node = InfoNode()
        else:
            # Check if query is NBA related
            flag = isNBA(self.query)
            if flag == 0:
                return unsure
            elif flag == -1:
                return non_nba

            # Query is definitely NBA related
            if self.node_type == "rank":
                node = RankNode()

            if self.node_type == "stat":
                node = StatNode()

        node.load_query(self.query)
        return node.response()
예제 #5
0
    def test_extract_components(self):
        node = InfoNode()
        test_phrase = {
            "who are you?": "be",
            "what do you do?": "do",
            "who build you?": "build",
            "who made you?": "make"
        }

        for phrase in test_phrase:
            node.load_query(phrase)
            test_verb = list(node.extract_components())[0]
            true_verb = test_phrase.get(phrase)

            self.assertTrue(
                test_verb == true_verb,
                "extract_components test failed at phrase: {}. Got verb: {}, expecting verb: {}."
                .format(phrase, test_verb, true_verb))
예제 #6
0
 def response(self):
     if self.node_type == "rank":
         node = RankNode()
     elif self.node_type == "stat":
         node = StatNode()
     elif self.node_type == "info":
         node = InfoNode()
     node.load_query(self.query)
     return node.response()
예제 #7
0
    def response(self):
        if self.node_type == "info":
            node = InfoNode()
        else:
            # Check if query is NBA related
            flag = isNBA(self.query)
            if flag == 0:
                return unsure
            elif flag == -1:
                return non_nba

            # Query is definitely NBA related
            if self.node_type == "rank":
                node = RankNode()

            if self.node_type == "stat":
                node = StatNode()

        node.load_query(self.query)
        return node.response()