label-flatten

Flatten hierarchical concepts or labels system to declarative sentences and labels.


License
MIT
Install
pip install label-flatten==0.1.3

Documentation

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)