semvec/pypi-packages huggingface dataset:
MyTextGrid 0.0.10.dev0
Manipulate TextGrid files
Requires Python: >=3.6

# MyTextGrid
A tiny python project for reading, writing and querying TextGrid files.

## Getting started

### 1. Installation

You can download it using the `pip` installer:

```
pip install MyTextGrid -U
```

### 2. The basics
To import the package, use `import MyTextGrid`.

Once this is done, use functions `create()` to create a TextGrid file from scratch or `read_from_file()` to read an existing file.

# Examples
## Creating a TextGrid from scratch

```
python
import MyTextGrid

# Create an empty TextGrid
tg = MyTextGrid.create(name = 'phrase', xmin = 0, xmax = 1)
```

## Reading a TextGrid from a file
To read an existing TextGrid file use the `read_from_file()` method. TextGrid files comes in [three formats](https://www.fon.hum.uva.nl/praat/manual/TextGrid_file_formats.html): long, short and binary. At this moment, only the long format is supported.

```
import MyTextGrid

# Create an empty TextGrid
path = r'C:\Users\rolan\Documents\projects\sentence1.TextGrid'
tg = MyTextGrid.read_from_file(path)
```
## Traversing a TextGrid
A TextGrid object is a container that stores one or more Tier objects. Each tier, at the same time, is a container itself and stores only two kinds of objects: Intervals or Points. Depending on that, a tier could be a IntervalTier or PointTier. To iterate through these containers use the `for` loop as in the following example. 

```
# tg is a variable that contains a TextGrid object.

# Iterate through a TextGrid 
for tier in tg:
    print(tier.name)
    print(tier.xmin)
    print(tier.xmax)
    print(tier.class_)
    # Iterate through an interval tier
    if tier.class_ == 'IntervalTier':
        for interval in tier:
            # Print Interval attributes
            print(interval.text)
            print(interval.xmin)
            print(interval.xmax)
    # Iterate through an interval tier
    elif tier.class_ == 'PointTier':
        for point in tier:
            # Print Point attributes
            print(point.time)
            print(point.text)
```
## Manipulating a TextGrid
```
# Insert tiers
tg.insert_point_tier("tone")
tg.insert_interval_tier("segment")
tg.insert_interval_tier("word")
tg.insert_interval_tier("phrase")

# Insert points and intervals
tg.insert_boundary('segment', 0.23, 0.30, 0.42, 0.62, 0.70, 0.82, 0.90, 0.98)
tg.insert_boundary('word', 0.23, 0.42, 0.98)
tg.insert_boundary('phrase', 0.23, 0.98)

tg.insert_point('tone', 0.66, "H")
tg.insert_point('tone', 0.94, "L")

# Add text to intervals
tg.set_interval_text('segment', 1, 'e', 'l', 'p', 'e', 'rr', 'o')
tg.set_interval_text('word', 1, 'el')
tg.set_interval_text('word', 2, 'perro')
tg.set_interval_text('phrase', 1, 'el perro')
```

## Saving a TextGrid file
```
# Save TextGrid
tg.save_as_text_file(r'C:\Users\rolan\Documents\projects\sentence1.TextGrid')
```
krdict 0.0.2
A module which helps to query the KRDict API.
Requires Python: >=3.9

# krdict.py

A python module which helps to query the [API](https://krdict.korean.go.kr/openApi/openApiInfo) of the
[Korean Learner's Dictionary](https://krdict.korean.go.kr/), provided by the National Institute of Korean Language.
Inspired by [krdict.js](https://github.com/Fox-Islam/krdict.js).

## Installation

To install the module via pip, run:

```
pip install krdict
```

To use this module, you'll need to generate an API key via [krdict](https://krdict.korean.go.kr/openApi/openApiRegister) (requires login).

## Usage
A minimal example query which assumes the `KRDICT_KEY` environment variable is set:

```python
import os
import json
import krdict

krdict.set_key(os.getenv('KRDICT_KEY'))
response = krdict.search_words(query='나무')

print(json.dumps(response, indent=2, ensure_ascii=False))
```

Assuming an error is not returned, this would print something like:

```json
{
  "data": {
    ...
    "results": [
      {
        "target_code": 32750,
        "word": "나무",
        "pronunciation": "나무",
        "link": "https://krdict.korean.go.kr/dicSearch/SearchView?ParaWordNo=32750",
        "meaning": [
          {
            "definition": "단단한 줄기에 가지와 잎이 달린, 여러 해 동안 자라는 식물.",
            "order": 1
          },
          ...
        ],
        "part_of_speech": "명사",
        "vocabulary_grade": "초급",
        "homograph_num": 0
      },
      ...
    ],
    "num_results": 10,
    "start_index": 1,
    "total_results": 53,
    "last_build_date": "20211001061204"
  },
  "request_params": {
    "q": "나무",
    "key": "YOUR_API_KEY"
  }
}
```