Example #1
0
class SemanticHierarchyTestCase(unittest.TestCase):
    def setUp(self):
        base_dir = os.path.dirname(__file__)
        self.analyzer = SemanticHierarchyAnalyzer(
            os.path.join(base_dir, "./data/semantic_hierarchy.lst"))

    def tearDown(self):
        pass

    def testSemanticHierarchy(self):
        res = self.analyzer.get_hierarchy_tags(u'电力')
        self.assertEquals(list(res), [u"电能", u"能源", u"技术"])
Example #2
0
 def setUp(self):
     base_dir = os.path.dirname(__file__)
     self.analyzer = SemanticHierarchyAnalyzer(
         os.path.join(base_dir, "./data/semantic_hierarchy.lst"))
Example #3
0
def semantic_hierarchy(word):
    global semantic_hierarchy_analyzer
    if semantic_hierarchy_analyzer is None:
        semantic_hierarchy_analyzer = SemanticHierarchyAnalyzer()
    return json.dumps(semantic_hierarchy_analyzer.get_hierarchy_tags(word), ensure_ascii=False)