- Notifications
You must be signed in to change notification settings - Fork4
Yet another Python binding for Juman++/KNP/KWJA
License
ku-nlp/rhoknp
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Documentation:https://rhoknp.readthedocs.io/en/latest/
Source Code:https://github.com/ku-nlp/rhoknp
rhoknp is a Python binding forJuman++,KNP, andKWJA.1
importrhoknp# Perform morphological analysis by Juman++jumanpp=rhoknp.Jumanpp()sentence=jumanpp.apply_to_sentence("電気抵抗率は電気の通しにくさを表す物性値である。")# Access to the resultformorphemeinsentence.morphemes:# a.k.a. keitai-so ...# Save the resultwithopen("result.jumanpp","wt")asf:f.write(sentence.to_jumanpp())# Load the resultwithopen("result.jumanpp","rt")asf:sentence=rhoknp.Sentence.from_jumanpp(f.read())
pip install rhoknp
Let's begin by using Juman++ with rhoknp.Here, we present a simple example demonstrating how Juman++ can be used to analyze a sentence.
# Perform morphological analysis by Juman++jumanpp=rhoknp.Jumanpp()sentence=jumanpp.apply_to_sentence("電気抵抗率は電気の通しにくさを表す物性値である。")
You can easily access the individual morphemes that make up the sentence.
formorphemeinsentence.morphemes:# a.k.a. keitai-so ...
Sentence objects can be saved in the JUMAN format.
# Save the sentence in the JUMAN formatwithopen("sentence.jumanpp","wt")asf:f.write(sentence.to_jumanpp())# Load the sentencewithopen("sentence.jumanpp","rt")asf:sentence=rhoknp.Sentence.from_jumanpp(f.read())
Almost the same APIs are available for KNP.
# Perform language analysis by KNPknp=rhoknp.KNP()sentence=knp.apply_to_sentence("電気抵抗率は電気の通しにくさを表す物性値である。")
KNP performs language analysis at multiple levels.
forclauseinsentence.clauses:# a.k.a., setsu ...forphraseinsentence.phrases:# a.k.a. bunsetsu ...forbase_phraseinsentence.base_phrases:# a.k.a. kihon-ku ...formorphemeinsentence.morphemes:# a.k.a. keitai-so ...
Sentence objects can be saved in the KNP format.
# Save the sentence in the KNP formatwithopen("sentence.knp","wt")asf:f.write(sentence.to_knp())# Load the sentencewithopen("sentence.knp","rt")asf:sentence=rhoknp.Sentence.from_knp(f.read())
Furthermore, rhoknp provides convenient APIs for document-level language analysis.
document=rhoknp.Document.from_raw_text("電気抵抗率は電気の通しにくさを表す物性値である。単に抵抗率とも呼ばれる。")# If you know sentence boundaries, you can use `Document.from_sentences` instead.document=rhoknp.Document.from_sentences( ["電気抵抗率は電気の通しにくさを表す物性値である。","単に抵抗率とも呼ばれる。", ])
Document objects can be handled in a similar manner as Sentence objects.
# Perform morphological analysis by Juman++document=jumanpp.apply_to_document(document)# Access language units in the documentforsentenceindocument.sentences: ...formorphemeindocument.morphemes: ...# Save language analysis by Juman++withopen("document.jumanpp","wt")asf:f.write(document.to_jumanpp())# Load language analysis by Juman++withopen("document.jumanpp","rt")asf:document=rhoknp.Document.from_jumanpp(f.read())
For more information, please refer to theexamples anddocumentation.
Main differences frompyknp
pyknp serves as the official Python binding for Juman++ and KNP.In the development of rhoknp, we redesigned the API, considering the current use cases of pyknp.The key differences between the two are as follows:
- Support for document-level language analysis: rhoknp allows you to load and instantiate the results of document-level language analysis, including cohesion analysis and discourse relation analysis.
- Strict type-awareness: rhoknp has been thoroughly annotated with type annotations, ensuring strict type checking and improved code clarity.
- Comprehensive test suite: rhoknp is extensively tested with a comprehensive test suite. You can view the code coverage report onCodecov.
MIT
We warmly welcome contributions to rhoknp.You can get started by reading thecontribution guide.
Footnotes
The logo was generated by OpenAI DALL·E 2.↩
About
Yet another Python binding for Juman++/KNP/KWJA
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.