Exemplo n.º 1
0
    def test_from_json(self):

        json_data = {
            "type": Match.type_to_string(Match.WORD),
            "node": "WORD [Hello]",
            "words": ["Hello"],
            "multi_word": False,
            "wild_card": False
        }

        match = Match.from_json(json_data)
        self.assertIsNotNone(match)
        self.assertEqual(Match.WORD, match.matched_node_type)
        self.assertEqual(False, match._matched_node_multi_word)
        self.assertEqual(False, match._matched_node_wildcard)
        self.assertEqual("WORD [Hello]", match._matched_node_str)
        self.assertEqual(["Hello"], match._matched_node_words)
Exemplo n.º 2
0
    def _write_matches_to_db(self, client_context, matched_context, matchid):
        match_count = 1
        for match in matched_context.matched_nodes:
            matchnodedao = self._storage_engine.session.query(MatchNodeDAO). \
                filter(MatchNodeDAO.matchid == matchid,
                       MatchNodeDAO.matchcount == match_count).first()

            if matchnodedao is None:
                matchnodedao = MatchNodeDAO(matchid=matchid,
                                            matchcount=match_count,
                                            matchtype=Match.type_to_string(match.matched_node_type),
                                            matchnode=match.matched_node_str,
                                            matchstr=match.joined_words(client_context),
                                            wildcard=match.matched_node_wildcard,
                                            multiword=match.matched_node_multi_word)

                self._storage_engine.session.add(matchnodedao)
                YLogger.debug(client_context, "Writing matched node %s", matchnodedao)

            else:
                YLogger.debug(client_context, "Matched node already exists, %s", matchnodedao)

            match_count += 1
Exemplo n.º 3
0
 def test_type_to_string(self):
     self.assertEqual("Word", Match.type_to_string(Match.WORD))
     self.assertEqual("Topic", Match.type_to_string(Match.TOPIC))
     self.assertEqual("That", Match.type_to_string(Match.THAT))
     self.assertEqual("Unknown", Match.type_to_string(999))