dki-cta 0.4.5
for general table augmentation
License: MIT
Requires Python: >=3.7.0, <= 3.8


# CTA
This package is used for general table augmentation. For each given table, CTA will return a list
of column names which can either replace an original column or act as a new column of the table.

you can install cta simply with
```angular2html
pip install dki_cta
```

download nltk data before call cta
```
import nltk
nltk.download("wordnet")
nltk.download("omw-1.4")
```

cta needs some extra data to work, for example, a synonym dict and a pre-built index for the candidate table headers
(about 3.1G in total).
They will be downloaded when first create an object of CTA. You can explicitly specify the cache dir. If not given, they
will be downloaded in "~/.cta_cache_data/".

When creating an object of CTA, you can also specify which device the cta model should run on by assigning "cpu"
or "cuda:{GPU_ID}" to the parameter "device".
```python3
from cta import CTA
ct = CTA(device = "cuda:2", cache_dir = "~/.cta_cache_data/")
```


A simple example about how to use CTA is shown as follows:

Case 0 is a general input. In case 1, we give CTA more information about the input table. (If not given, CTA will predict 
these features.) And CTA also allows user to specify which column they want to find replacements for in the ``target column''
and input complex column names, e.g. ClgName, as shown in case 2.
```python3
from cta import CTA

tables = [
    {
        "columns":[
            ["#", [1,2]],
            ["College Name", ["FRESNO CITY COLLEGE", "COLLEGE OF THE SEQUOIAS"]],
            ["Transfers", [205, 203]],
            ["%", [0.205616851, 0.203610832]]
        ],
        "table_name": "she2 year top 20"
        # columns_types (list[str]), tpe(str) and table_id(str) are optional
    },
    {
        "columns":[
            ["#", [1,2]], # [column header, [val1, val2, ...]
            ["College Name", ["FRESNO CITY COLLEGE", "COLLEGE OF THE SEQUOIAS"]],
            ["Transfers", [205, 203]],
            ["%", [0.205616851, 0.203610832]]
        ],
        "table_name": "she2 year top 20",
        "column_types": ["number", "text", "number", "real"],  # optional, the data type of each column, should in ["date", "number", "real"(实数）, "text"]
        "tpe": "college", # optional, predefined 40 class (or other theme word(s))
        "table_id": "realtb_0" # optional
    },
    {
        "columns":[
            ["#", [1,2]],
            ["ClgName", ["FRESNO CITY COLLEGE", "COLLEGE OF THE SEQUOIAS"]],
            ["Transfers", [205, 203]],
            ["%", [0.205616851, 0.203610832]]
        ],
        "target_column": "Transfers",
        "table_name": "she2 year top 20"
        # columns_types (list[str]), tpe(str) and table_id(str) are optional
    }
]
# ct = CTA(device = "cuda:2", cache_dir = "./cta_cache_dir")
ct = CTA()
res = ct.process(input_tables=tables)
print(res)
```

The result should be a list of dict:

```json
[
    {
        "ADD":[
            "college address",
            "college fest name",
            "faculty name",
            "college location",
            "internal transfers",
            "college type",
            "enrollment",
            "department name"
        ],
        "REPLACE":{
            "College Name":[
                "university name",
                "name of the college",
                "college"
            ],
            "Transfers":[
                "transference",
                "transfer",
                "trans",
                "transaction",
                "transport"
            ]
        },
        "column_types":[
            "number",
            "text",
            "number",
            "real"
        ],
        "expanded_columns":[
            "#",
            "college name",
            "transfers",
            "%"
        ],
        "tpe":"school"
    },
    {
        "ADD":[
            "college address",
            "college fest name",
            "faculty name",
            "college location",
            "internal transfers",
            "college type",
            "enrollment",
            "department name"
        ],
        "REPLACE":{
            "College Name":[
                "university name",
                "name of the college",
                "college"
            ],
            "Transfers":[
                "transference",
                "transfer",
                "trans",
                "transaction",
                "transport"
            ]
        },
        "column_types":[
            "number",
            "text",
            "number",
            "real"
        ],
        "expanded_columns":[
            "#",
            "college name",
            "transfers",
            "%"
        ],
        "tpe":"school"
    },
    {
        "ADD":[
            "college address",
            "college location",
            "college",
            "internal transfers",
            "enrollment"
        ],
        "REPLACE":{
            "Transfers":[
                "transference",
                "transfer",
                "trans",
                "transaction",
                "transport"
            ]
        },
        "column_types":[
            "number",
            "text",
            "number",
            "real"
        ],
        "expanded_columns":[
            "#",
            "college name",
            "transfers",
            "%"
        ],
        "tpe":"school"
    }
]
```

"ADD" means the column headers which can be added to the original table as new columns.
"REPLACE" contains the column headers for replacements, e.g. we can replace the original header
"College Name" with "university name".


CTA could also be used to expand complex column names. An example is shown as follows:
```python
from cta import CTA
ct = CTA()
ori_cols = ["Test", "dept", "stu_name", "stu name", "StuName", "cnt", "stu.", "stu .", "StudentID", "HeadC", "appl"]
res = ct.expand_columns(ori_cols)
print(res)
```

The result should be
```python
['test', 'department', 'student name', 'student name', 'student name', 'count', 'student', 'student', 'student id', 'head c', 'application']
```