semvec/pypi-packages huggingface dataset:
snowflake-sqlalchemy-json 1.1.2
A library to handle JSON with snowflake-sqlalchemy.
License: MIT
Requires Python: >=3.7, <4
Keywords: snowflake sqlalchemy

[![PyPI version](https://badge.fury.io/py/snowflake-sqlalchemy-json.svg)](https://badge.fury.io/py/snowflake-sqlalchemy-json)
[![build](https://github.com/masamitsu-murase/snowflake-sqlalchemy-json/actions/workflows/ci.yml/badge.svg)](https://github.com/masamitsu-murase/snowflake-sqlalchemy-json/actions/workflows/ci.yml)

# snowflake-sqlalchemy-json

This is a library to handle JSON data in [snowflake-sqlalchemy](https://pypi.org/project/snowflake-sqlalchemy/).

## Installation

```bash
$ pip install snowflake-sqlalchemy-json
```

## Usage

Note that the current version support SELECT of JSON columns, but it does not support INSERT or UPDATE of them.

This library supports access to elements in JSON columns.  
You can access JSON columns as follows:

1. Define a column as `JSON` type.  
   Though the actual column type is `VARIANT`, you have to use `JSON` instead.
1. You can refer to elements in the column like `dict`.  
   If `Book` has a JSON column, `json_data`, you can refer to an element in the column as `Book.json_data["key"]`.
1. You can also use [`func.flatten` function](https://docs.snowflake.com/en/sql-reference/functions/flatten.html) to flatten values in a JSON column.  
   Please refer to the following example.

```python
import snowflake_sqlalchemy_json
from sqlalchemy import Column, Integer, JSON, String, func, select
from sqlalchemy.orm import declarative_base, DeclarativeMeta
from sqlalchemy.sql import quoted_name

# You have to call this function to enable `func.flatten`.
snowflake_sqlalchemy_json.register_json_handler()

Base: DeclarativeMeta = declarative_base()


class Book(Base):
    __tablename__ = quoted_name("database_name.schema_name.books", False)
    id = Column(Integer, primary_key=True)
    title = Column(String(255))
    json_data = Column(JSON)


editors = func.flatten(Book.json_data["editors"]).lateral()
query = select(
    Book.title,
    editors.c.value["name"],
).select_from(Book).join(
    editors,
    True,
).where(
    editors.c.value["type"] == "chief",
).order_by(editors.c.value["name"].desc())
```

`query` in the above example generates the following SQL.

```sql
SELECT database_name.schema_name.books.title, GET(anon_2.value, 'name') AS anon_1
FROM database_name.schema_name.books JOIN LATERAL flatten(INPUT => (GET(database_name.schema_name.books.json_data, 'editors'))) AS anon_2 ON true
WHERE GET(anon_2.value, 'type') = 'chief' ORDER BY GET(anon_2.value, 'name') DESC
```
cas2iob 0.1.0
Converter of UIMA CAS XMI files from INCEpTION with nested NER tags, NEL tags and components into IOB TSV files
License: MIT
Requires Python: >=3.7

# CAS2IOB

CAS2IOB is a converter of UIMA CAS XMI files using in the INCEpTION annotation platform into IOB TSV files. In contrast to the internal convertor in INCEpTION, it handles the nested NER tags, NEL tags and components, and saves them into multiple columns of a TSV-file:
```
TOKEN  NE-COARSE   NE-FINE NE-FINE-COMP    NE-NESTED   NEL-WikidataQID
```

It reads the UIMA CAS XMI files using [dkpro-cassis](https://github.com/dkpro/dkpro-cassis) library.

## Installation

```python
pip install cas2iob
```

## Using as a library

Import cas2iob:
```python
import cas2iob
```

Convert `./input.xmi` with `./TypeSystem.xml` into `./output.tsv`:
```python
cas2iob.file('./input.xmi', 'output.tsv')
```

Convert all files in `./input` folder with `./TypeSystem.xml` into `./output` folder:
```python
cas2iob.folder('./input', './output')
```

If `./TypeSystem.xml` is located in a different folder, add it to the commands above as the third argument.

If you don't want to include column names in a TSV-file, add the forth argument `metadata=False`.

## Using in CLI

```shell
% cas2iob --help
                                                                                
 Usage: cas2iob [OPTIONS] INPUT_PATH OUTPUT_PATH [TYPESYSTEM_XML] [METADATA]    
                                                                                
╭─ Arguments ──────────────────────────────────────────────────────────────────╮
│ *    input_path          PATH              [default: None] [required]        │
│ *    output_path         PATH              [default: None] [required]        │
│      typesystem_xml      [TYPESYSTEM_XML]  [default: ./TypeSystem.xml]       │
│      metadata            [METADATA]        [default: True]                   │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --install-completion          Install completion for the current shell.      │
│ --show-completion             Show completion for the current shell, to copy │
│                               it or customize the installation.              │
│ --help                        Show this message and exit.                    │
╰──────────────────────────────────────────────────────────────────────────────╯
```