Пример #1
0
 def test_node_response(self):
     node = StatNode()
     node.load_query("query")
     resp = node.response()
     stat = [
         int(word) for word in resp.split()
         if word.replace('.', '').isdigit()
     ]
     self.assertTrue(isinstance(resp, str))
Пример #2
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()
Пример #3
0
 def response(self):
     if self.node_type == "rank":
         node = RankNode()
     elif self.node_type == "stat":
         node = StatNode()
     node.load_query(self.query)
     return node.response()
Пример #4
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()
Пример #5
0
 def test_get_player_stat(self):
     node = StatNode()
     val = node.get_player_stat("Kobe Bryant", "true shooting percentage")
     self.assertTrue(isinstance(val, float))
Пример #6
0
 def test_extract_stat(self):
     node = StatNode()
     node.load_query("What is Kobe Bryant's true shooting percentage?")
     stat = node.extract_stat()
     self.assertEqual(stat, "true shooting percentage")
Пример #7
0
 def test_extract_name(self):
     node = StatNode()
     node.load_query("What is Kobe Bryant's shooting percentage?")
     name = node.extract_name()
     self.assertEqual(name, "Kobe Bryant's")
Пример #8
0
 def test_generate_random_response(self):
     node = StatNode()
     val = node.generate_random_response("true shooting percentage",
                                         "Kobe Bryant", 0.54)
     self.assertIsInstance(val, str)