Metadata-Version: 2.4
Name: jreadability
Version: 1.1.4
Summary: Calculate readability scores for Japanese texts.
Author-email: Joshua Hamilton <hamiltonjoshuadavid@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Joshua Hamilton
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: homepage, https://github.com/joshdavham/jreadability
Keywords: japanese,readability
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fugashi
Requires-Dist: unidic-lite
Provides-Extra: dev
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Dynamic: license-file

<div align="center">
    <img src="https://raw.githubusercontent.com/joshdavham/jreadability/0bb50f9ea65b2092dd3fdf2f2193d51cb394fe4d/logo.svg" height="75">
</div>
<br />

<div align="center">
    <i>Text readability calculator for Japanese learners 🇯🇵</i>
</div>

<br />

<div align="center" style="text-decoration: none;">
    <a href="https://pypi.org/project/jreadability/"><img src="https://img.shields.io/pypi/v/jreadability"></a>
    <a href="https://github.com/joshdavham/jreadability/blob/main/LICENSE" style="text-decoration: none;"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg"></a>
    <a href="https://codecov.io/gh/joshdavham/jreadability" > 
    <img src="https://codecov.io/gh/joshdavham/jreadability/branch/main/graph/badge.svg?token=UPOMHPIHD7"/> 
    </a>
</div>

<br />

jReadability allows python developers to calculate the readability of Japanese text using the model developed by Jae-ho Lee and Yoichiro Hasebe in [Introducing a readability evaluation system for Japanese language education](https://jreadability.net/file/hasebe-lee-2015-castelj.pdf) and [Readability measurement of Japanese texts based on levelled corpora](https://researchmap.jp/jhlee/published_papers/21426109). **Note that this is not an official implementation.**

## Demo

You can play with an interactive demo [here](https://jreadability-demo.streamlit.app/).

## Installation
```
pip install jreadability
```

## Quickstart
```python
from jreadability import compute_readability

# "Good morning! The weather is nice today."
text = 'おはようございます！今日は天気がいいですね。' 

score = compute_readability(text)

print(score) # 6.438000000000001
```

## Readability scores

| Level              | Readability score range |
|--------------------|-------------------------|
| Upper-advanced     | [0.5, 1.5)                 |
| Lower-advanced     | [1.5, 2.5)               |
| Upper-intermediate | [2.5, 3.5)               |
| Lower-intermediate | [3.5, 4.5)               |
| Upper-elementary   | [4.5, 5.5)               |
| Lower-elementary   | [5.5, 6.5)               |

Note that this readability calculator is specifically for <u>non-native speakers</u> learning to read Japanese. This is not to be confused with something like grade level or other readability scores meant for native speakers.

### Model

```
readability = {mean number of words per sentence} * -0.056
            + {percentage of kango} * -0.126
            + {percentage of wago} * -0.042
            + {percentage of verbs} * -0.145
            + {percentage of particles} * -0.044
            + 11.724
```

*\* "kango" (漢語) means Japanese word of Chinese origin while "wago" (和語) means native Japanese word.*

#### Note on model consistency

The readability scores produced by this python package tend to differ slightly from the scores produced on the official [jreadability website](https://jreadability.net/sys/en). This is likely due to the version difference in UniDic between these two implementations as this package uses UniDic 2.1.2 while theirs uses UniDic 2.2.0. This issue may be resolved in the future.

## Batch processing

jreadability makes use of [fugashi](https://github.com/polm/fugashi)'s tagger under the hood and initializes a new tagger everytime `compute_readability` is invoked. If you are processing a large number of texts, it is recommended to initialize the tagger first on your own, then pass it as an argument to each subsequent `compute_readability` call.

```python
from fugashi import Tagger

texts = [...]

tagger = Tagger()

for text in texts:
    
    score = compute_readability(text, tagger) # fast :D
    #score = compute_readability(text) # slow :'(
    ...
```

## Documentation

You can find this repo's (very minimal) documentation [here](https://joshdavham.github.io/jreadability/jreadability.html).

## Other implementations

The official jReadability implementation can be found on [jreadability.net](https://jreadability.net/)

A node.js implementation can also be found [here](https://github.com/Bennycopter/jreadability).
