Yargy uses rules and dictionaries to extract structured information from Russian texts. Yargy is similar to Tomita parser.
Install
Yargy supports Python 3.7+, PyPy 3, depends only on Pymorphy2.
$ pip install yargy
Usage
from yargy import Parser, rule, and_, not_
from yargy.interpretation import fact
from yargy.predicates import gram
from yargy.relations import gnc_relation
from yargy.pipelines import morph_pipeline
Name = fact(
'Name',
['first', 'last'],
)
Person = fact(
'Person',
['position', 'name']
)
LAST = and_(
gram('Surn'),
not_(gram('Abbr')),
)
FIRST = and_(
gram('Name'),
not_(gram('Abbr')),
)
POSITION = morph_pipeline([
'управляющий директор',
'вице-мэр'
])
gnc = gnc_relation()
NAME = rule(
FIRST.interpretation(
Name.first
).match(gnc),
LAST.interpretation(
Name.last
).match(gnc)
).interpretation(
Name
)
PERSON = rule(
POSITION.interpretation(
Person.position
).match(gnc),
NAME.interpretation(
Person.name
)
).interpretation(
Person
)
parser = Parser(PERSON)
match = parser.match('управляющий директор Иван Ульянов')
print(match)
Person(
position='управляющий директор',
name=Name(
first='Иван',
last='Ульянов'
)
)
Documentation
All materials are in Russian:
Support
- Chat — https://t.me/natural_language_processing
- Issues — https://github.com/natasha/yargy/issues
- Commercial support — https://lab.alexkuk.ru
Development
Dev env
brew install graphviz
python -m venv ~/.venvs/natasha-yargy
source ~/.venvs/natasha-yargy/bin/activate
pip install -r requirements/dev.txt
pip install -e .
python -m ipykernel install --user --name natasha-yargy
Test + lint
make test
Update docs
make exec-docs
# Manually check git diff docs/, commit
Release
# Update setup.py version
git commit -am 'Up version'
git tag v0.16.0
git push
git push --tags
# Github Action builds dist and publishes to PyPi
Metadata
Release files for yargy 0.16.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yargy-0.16.0.tar.gz | 68.2 kB | Without provenance | Details for yargy-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yargy-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for yargy-0.16.0-py3-none-any.whl |
Total release size: 102.2 kB
Release files / yargy-0.16.0.tar.gz
| Download URL | yargy-0.16.0.tar.gz |
|---|---|
| Size | 68.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c917eefb32a40c23c46b6ca88d68927072dd00ab94e90fd5dc6ab0a62b59b593
|
|
BLAKE2b-256 checksum How to use checksums |
87ff0ac3b2ae6aca6026e1acc872c1c371182662e94b1c1ab0b9c68854472670
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / yargy-0.16.0-py3-none-any.whl
| Download URL | yargy-0.16.0-py3-none-any.whl |
|---|---|
| Size | 34.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ca469fa47b336367fab49e8f33ccc195584f69ab758e8196f2fdaa7492adf22
|
|
BLAKE2b-256 checksum How to use checksums |
b755d065a9812c619889fbe01a1863743ee45f7c60c462fc95b19576972ee9e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for yargy 0.16.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.