Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-kokabi committed Jul 30, 2023
1 parent 36abb01 commit 8f4f474
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 91 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
- [Others](#others)

## Evaluation
| Module name | |
| :--- | --- |

| Module name | |
| :--------------- | --------- |
| DependencyParser | **85.6%** |
| POSTagger | **98.8%** |
| Chunker | **93.4%** |
| Lemmatizer | **89.9%** |
| POSTagger | **98.8%** |
| Chunker | **93.4%** |
| Lemmatizer | **89.9%** |

## Introduction

Expand Down Expand Up @@ -52,16 +53,16 @@ Alternatively, you can install the latest update from GitHub (this version may b

## Pretrained-Models

Finally if you want to use our pretrained models, you can download it from the links below:
Finally if you want to use our pretrained models, you can download it from the links below:

| **Module name** | **Size** |
|:------------------------ |:-------- |
| [**Download WordEmbedding**](https://mega.nz/file/GqZUlbpS#XRYP5FHbPK2LnLZ8IExrhrw3ZQ-jclNSVCz59uEhrxY) | ~ 5 GB |
| [**Download SentEmbedding**](https://mega.nz/file/WzR0QChY#J1nG-HGq0UJP69VMY8I1YGl_MfEAFCo5iizpjofA4OY) | ~ 1 GB |
| [**Download POSTagger**](https://drive.google.com/file/d/1Q3JK4NVUC2t5QT63aDiVrCRBV225E_B3) | ~ 18 MB |
| [**Download UniversalDependencyParser**](https://drive.google.com/file/d/1MDapMSUXYfmQlu0etOAkgP5KDiWrNAV6/view?usp=share_link) | ~ 15 MB |
| [**Download DependencyParser**](https://drive.google.com/file/d/1Ww3xsZC5BXY5eN8-2TWo40G-WvppkXYD/view?usp=drive_link) | ~ 13 MB |
| [**Download Chunker**](https://drive.google.com/file/d/16hlAb_h7xdlxF4Ukhqk_fOV3g7rItVtk) | ~ 4 MB |
| **Module name** | **Size** |
| :------------------------------------------------------------------------------------------------------------------------------ | :------- |
| [**Download WordEmbedding**](https://mega.nz/file/GqZUlbpS#XRYP5FHbPK2LnLZ8IExrhrw3ZQ-jclNSVCz59uEhrxY) | ~ 5 GB |
| [**Download SentEmbedding**](https://mega.nz/file/WzR0QChY#J1nG-HGq0UJP69VMY8I1YGl_MfEAFCo5iizpjofA4OY) | ~ 1 GB |
| [**Download POSTagger**](https://drive.google.com/file/d/1Q3JK4NVUC2t5QT63aDiVrCRBV225E_B3) | ~ 18 MB |
| [**Download UniversalDependencyParser**](https://drive.google.com/file/d/1MDapMSUXYfmQlu0etOAkgP5KDiWrNAV6/view?usp=share_link) | ~ 15 MB |
| [**Download DependencyParser**](https://drive.google.com/file/d/1Ww3xsZC5BXY5eN8-2TWo40G-WvppkXYD/view?usp=drive_link) | ~ 13 MB |
| [**Download Chunker**](https://drive.google.com/file/d/16hlAb_h7xdlxF4Ukhqk_fOV3g7rItVtk) | ~ 4 MB |

## Usage

Expand Down
16 changes: 11 additions & 5 deletions documentation/content/hazm/chunker.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
!!! Note ""

دقت تجزیه‌گر سطحی در نسخهٔ حاضر {{chunker_evaluation_value | to_persian_numeral}} درصد است.

::: hazm.chunker
handler: python
options:
members: - Chunker - tree2brackets
show_root_heading: false
show_source: false
handler: python
options:
members:
- Chunker
- tree2brackets
show_root_heading: false
show_source: false
4 changes: 4 additions & 0 deletions documentation/content/hazm/dependency_parser.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
!!! Note ""

دقت تجزیه‌گر عمقی در نسخهٔ حاضر {{dependency_parser_evaluation_value | to_persian_numeral}} درصد است.

::: hazm.dependency_parser
handler: python
options:
Expand Down
5 changes: 5 additions & 0 deletions documentation/content/hazm/lemmatizer.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
!!! note ""

دقت لماتایزر در نسخهٔ حاضر {{lemmatizer_evaluation_value | to_persian_numeral}} درصد است.


::: hazm.lemmatizer
6 changes: 5 additions & 1 deletion documentation/content/hazm/pos_tagger.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
??? info "کاربرد عملی"
!!! note ""

دقت برچسب‌گذاری در نسخهٔ حاضر {{posTagger_evaluation_value | to_persian_numeral}} درصد است.

!!! info "کاربرد عملی"

برای آشنایی با کاربرد این ماژول می‌توانید به بخش کاربردهای هضم مراجعه کنید.

Expand Down
2 changes: 1 addition & 1 deletion documentation/content/hazm/word_tokenizer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
??? info "کاربرد عملی"

برای آشنایی عملی با کاربرد این ماژول می‌توانید به بخش کاربردهای هضم مراجعه کنید.
برای آشنایی با کاربرد این ماژول می‌توانید به بخش کاربردهای هضم مراجعه کنید.

در پروژه‌های زیر از این ماژول استفاده شده است:

Expand Down
46 changes: 4 additions & 42 deletions documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
استخراج کنید. ریشهٔ کلمات را پیدا کنید. جملات را تحلیل صرفی و نحوی کنید.
وابستگی‌های دستوری را در متن شناسایی کنید و ... .

!!! info "مبتنی بر کتابخانهٔ nltk و سازگار با پایتون +۳.۸"
!!! info "مبتنی بر کتابخانهٔ nltk و سازگار با پایتون {{needed_python_version() | to_persian_numeral}}"
هضم بر مبنای کتابخانهٔ [NLTK](https://www.nltk.org/) توسعه داده شده و برای
**زبان فارسی** بومی‌سازی شده است. هضم با پایتون ۳.۸ و بالاتر سازگار است.
**زبان فارسی** بومی‌سازی شده است. هضم با پایتون {{needed_python_version() | to_persian_numeral}} سازگار است.

!!! info "محصولی از تیم روشن"
این کتابخانه در ابتدا به عنوان پروژه‌ای شخصی توسعه داده شد و اکنون زیر چتر
Expand All @@ -26,7 +26,7 @@
$ pip install hazm
```

سپس [منابع موردنظر را دانلود کنید](https://github.com/roshan-research/hazm#pretrained-models) و ترجیحاً در ریشهٔ پروژه اکسترکت کنید.
سپس [منابع موردنظر را دانلود کنید]({{pretrained_models}}) و ترجیحاً در ریشهٔ پروژه اکسترکت کنید.

و در آخر، هضم را را در پروژه خود ایمپورت کنید:

Expand All @@ -38,45 +38,7 @@ from hazm import *

کد پایین دیدی کلی از کاربردهای هضم نشان می‌دهد:

```py
from hazm import *

# Clean and normalize a text.
print(Normalizer().normalize("چه گل های زیبایی."))
# چه گل‌های زیبایی

# Find the word’s root (faster but less accurate)
print(Stemmer().stem("کتاب‌هایشان"))
# کتاب

# Find the word’s root (More accurate but slower)
print(Lemmatizer().lemmatize("می‌روم"))
# رفت#رو

# Break text into sentences.
print(SentenceTokenizer().tokenize("بسیار خوشحال بود! پرسید، چرا دیروز نیامدی ؟"))
# ['پرسید، چرا دیروز نیامدی ؟','! بسیار خوشحال بود']

# Break text into tokens.
print(WordTokenizer().tokenize("پرسید، چرا دیروز نیامدی؟"))
# ['پرسید', '،', 'چرا', 'دیروز', 'نیامدی', '؟']

# Assigns parts of speech to each word, such as noun, verb, adjective, etc.
tagger = POSTagger(model='pos_tagger.model')
print(tagger.tag(WordTokenizer().tokenize("ما بسیار کتاب می‌خوانیم")))
# [('ما', 'PRO'), ('بسیار', 'ADV'), ('کتاب', 'N'), ('می‌خوانیم', 'V')]

# Labels each word with its part of speech, such as noun, verb, adjective, etc.
chunker = chunker('chunker.model')
tagged = tagger.tag(word_tokenize('کتاب خواندن را دوست داریم'))
tree2brackets(chunker.parse(tagged))
# '[کتاب خواندن NP] [را POSTP] [دوست داریم VP]'

# Identify semantic relations between words in a sentence.
parser = DependencyParser(tagger=tagger, lemmatizer=lemmatizer)
parser.parse(word_tokenize('زنگ‌ها برای که به صدا درمی‌آید؟'))
# <DependencyGraph with 8 nodes>
```
{{hazm_code_example()}}

جزئیات بیشترِ این توابع را در بخش [کلاس‌ها و توابع](content/modules) پی بگیرید.
هضم علاوه بر کلاس‌ها و توابع مختص خود، کلاس‌ها و توابعی نیز برای خواندن
Expand Down
6 changes: 1 addition & 5 deletions hazm/chunker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# ruff: noqa: EXE002
"""این ماژول شامل کلاس‌ها و توابعی برای تجزیهٔ متن به عبارات اسمی، فعلی و حرف
اضافه‌ای است. **میزان دقت تجزیه‌گر سطحی در نسخهٔ حاضر ۹۳.۴ درصد [^1] است.**
[^1]:
این عدد با انتشار هر نسخه بروزرسانی می‌شود.
"""این ماژول شامل کلاس‌ها و توابعی برای تجزیهٔ متن به عبارات اسمی، فعلی و حرف است.
"""

from typing import Dict
Expand Down
4 changes: 0 additions & 4 deletions hazm/dependency_parser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"""این ماژول شامل کلاس‌ها و توابعی برای شناساییِ وابستگی‌های دستوری متن است.
برای استفاده از این ماژول، ابتدا [پیش‌نیازهای `dependecy_parser` را با حجمی حدود ۱۳ مگابایت دانلود کنید](https://github.com/roshan-research/hazm#pretrained-models) و در ریشهٔ پروژه یا مسیر دلخواه اکسترکت کنید.
**میزان دقت
این ماژول در نسخهٔ حاضر ۸۵.۶٪ درصد [^1] است.**
[^1]:
این عدد با انتشار هر نسخه بروزرسانی می‌شود
"""


Expand Down
5 changes: 0 additions & 5 deletions hazm/lemmatizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
کار را انجام می‌دهد و نتایج دقیق‌تری ارائه می‌دهد. البته هزینهٔ این دقت، سرعتِ
کمتر در ریشه‌یابی است.
**میزان دقت
لماتایزر در نسخهٔ حاضر ۸۹.۹ درصد [^1] است.**
[^1]:
این عدد با انتشار هر نسخه بروزرسانی می‌شود
"""


Expand Down
14 changes: 1 addition & 13 deletions hazm/pos_tagger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
"""این ماژول شامل کلاس‌ها و توابعی برای برچسب‌گذاری توکن‌هاست.
**میزان دقت
برچسب‌زنی در نسخهٔ حاضر ۹۸.۸ درصد [^1] است.**
[^1]:
این عدد با انتشار هر نسخه بروزرسانی می‌شود.
"""

from nltk.tag import stanford
Expand Down Expand Up @@ -34,13 +28,7 @@


class POSTagger(SequenceTagger):
"""این کلاس‌ها شامل توابعی برای برچسب‌گذاری توکن‌هاست. **میزان دقت برچسب‌زنی در
نسخهٔ حاضر ۹۸.۸ درصد [^1] است.** این کلاس تمام توابع خود را از کلاس
[SequenceTagger][hazm.sequence_tagger.SequenceTagger] به ارث می‌برد.
[^1]:
این عدد با انتشار هر نسخه بروزرسانی می‌شود.
"""
"""این کلاس‌ها شامل توابعی برای برچسب‌گذاری توکن‌هاست."""

def __init__(
self: "POSTagger", model=None, data_maker=None, universal_tag=False,
Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ docs_dir: documentation
site_dir: docs/docs

copyright: |
کپی‌رایت &copy; ۱۴۰۱ - ۱۴۰۲ <a href="https://github.com/roshan-research/hazm" target="_blank" rel="noopener">روشن</a> &nbsp;|&nbsp;
© کلیهٔ حقوق این سایت محفوظ و متعلق به شرکت روشن است. &nbsp;|&nbsp;
<a href="#__consent">تغییر تنظیمات کوکی</a>
theme:
Expand Down Expand Up @@ -54,6 +54,8 @@ theme:
- content.code.select

plugins:
- macros:
module_name: mkdocs_macros
- autorefs
- mkdocstrings:
custom_templates: documentation/templates
Expand Down
52 changes: 52 additions & 0 deletions mkdocs_macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import toml
from packaging import version
import re

def get_evaluation_values():
with open("README.md", "r", encoding="utf-8") as f:
content = f.read()

table = re.search(r"(?<=## Evaluation\n\n)[\s\S]*",content).group(0)

pattern = r"\|(\s*[\w\s]+)\s*\|\s*\*\*(\d+\.\d+)\%\*\*\s*\|"
matches = re.findall(pattern, table)

evaluation_values = {module.strip(): float(value) for module, value in matches}

return evaluation_values


def define_env(env):
env.variables.pretrained_models="https://github.com/roshan-research/hazm#pretrained-models"
env.variables.lemmatizer_evaluation_value = get_evaluation_values()["Lemmatizer"]
env.variables.posTagger_evaluation_value = get_evaluation_values()["POSTagger"]
env.variables.dependency_parser_evaluation_value = get_evaluation_values()["DependencyParser"]
env.variables.chunker_evaluation_value = get_evaluation_values()["Chunker"]


@env.filter
def to_persian_numeral(number):
english_to_persian = {'0': '۰', '1': '۱', '2': '۲', '3': '۳', '4': '۴', '5': '۵', '6': '۶', '7': '۷', '8': '۸', '9': '۹'}
return ''.join(english_to_persian.get(digit, digit) for digit in str(number))

@env.macro
def needed_python_version():
with open('pyproject.toml', 'r') as f:
toml_data = toml.load(f)

python_reqs = toml_data.get('tool', {}).get('poetry', {}).get('dependencies', {}).get('python', '')

versions = [version.parse(c.split('>=')[1]) for c in python_reqs.split(',') if c.startswith('>=')]
min_version = "+"+str(min(versions)) if versions else ''

return min_version

@env.macro
def hazm_code_example():
with open("README.md", 'r', encoding='utf-8') as file:
markdown_content = file.read()

pattern = r"(?<=## Usage\n\n)```python[\s\S]*```"

return re.search(pattern, markdown_content).group(0)

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pymdown-extensions="^9.11"
mkdocs-glightbox="^0.3.4"
mkdocstrings = "^0.21.2"
mkdocstrings-python = "^1.0.0"
mkdocs-macros-plugin = "^1.0.2"
toml = "^0.10.2"


[tool.poetry.group.docs]
Expand Down

0 comments on commit 8f4f474

Please sign in to comment.