Label-Flatten
Flatten hierarchical concepts or labels system to declarative sentences and labels.
A Python module.
Example
Input
Label/Concept Hierarchy
-
ä¸ģé¤ Main Meal
- įæ Steak
- įįžč Stir-fried lamb
-
įå Dessert
- å¸ä¸ Pudding
- å°æˇæˇ Ice cream
Case Label: įæ Steak
Outputs
åŽæ¯įæīŧå°įã
åŽä¸æ¯įæīŧé¯įã
åŽæ¯ä¸ģé¤īŧå°įã
åŽä¸æ¯ä¸ģé¤īŧé¯įã
åŽæ¯įįžčīŧé¯įã
åŽä¸æ¯įįžčīŧå°įã
åŽä¸æ¯å¸ä¸īŧé¯įã
åŽä¸æ¯å¸ä¸īŧå°įã
åŽæ¯å°æˇæˇīŧé¯įã
åŽä¸æ¯å°æˇæˇīŧå°įã
åŽæ¯įåīŧé¯įã
åŽä¸æ¯įåīŧå°įã
It's a steak, right.
It's not a steak, wrong.
It's the main meal, right.
It's not the main meal, wrong.
It is stir-fried lamb, wrong.
It is not stir-fried lambb, right.
It's not pudding, wrong.
It's not pudding, right.
It is ice cream, wrong.
It's not ice cream, right.
It is dessert, wrong.
It's not dessert, right.
In this module, wrong is 0 and right is 1.
Install
pip install label-flatten
Usage
from label_flatten import Tree,Node
import copy
pth = "example_data.json"
labels = ["čžŖå鸥ä¸"]
tree_template = Tree(pth)
for label in labels:
new_tree = copy.deepcopy(tree_template)
labeled_tree = new_tree.give_label(label)
print(labeled_tree)
sentences = labeled_tree.write(mode="all")
for sen in sentences:
print(sen)