-
Notifications
You must be signed in to change notification settings - Fork 0
Dev/main v0.2.0: Added detokenisation and sentence splitting features #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mtanti
wants to merge
3
commits into
main
Choose a base branch
from
dev/main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ Top-level package. | |
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| malti/sent_splitter | ||
| malti/tokeniser | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| sent_splitter | ||
| ============= | ||
|
|
||
| Sentence splitters for Maltese text. | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| sent_splitter/sent_splitter.rst | ||
| sent_splitter/km_sent_splitter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| km_sent_splitter | ||
| ================ | ||
|
|
||
| The MLRS Korpus Malti's sentence splitter. | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| km_sent_splitter/km_sent_splitter.rst |
10 changes: 10 additions & 0 deletions
10
docs/source/malti/sent_splitter/km_sent_splitter/km_sent_splitter.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| km_sent_splitter.py | ||
| =================== | ||
|
|
||
| .. automodule:: malti.sent_splitter.km_sent_splitter.km_sent_splitter | ||
| :members: | ||
| :show-inheritance: | ||
| :inherited-members: | ||
| :special-members: | ||
| :exclude-members: __weakref__ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| sent_splitter.py | ||
| ================ | ||
|
|
||
| .. automodule:: malti.sent_splitter.sent_splitter | ||
| :members: | ||
| :show-inheritance: | ||
| :inherited-members: | ||
| :special-members: | ||
| :exclude-members: __weakref__ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ Select a topic to learn about below: | |
|
|
||
| usage/install | ||
| usage/tokenisers | ||
| usage/sentence_splitters | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| Sentence splitters | ||
| ================== | ||
|
|
||
| Sentence splitters are used to break up text represented as a single string (such as from a text file) into a list of sentences. | ||
|
|
||
|
|
||
| The ``split`` function | ||
| ---------------------- | ||
|
|
||
| The simplest way to sentence split a text in ``malti`` is as follows: | ||
|
|
||
| .. code-block:: python | ||
| :linenos: | ||
|
|
||
| import malti.sent_splitter | ||
|
|
||
| text = 'Eżempju ta\' sentenza. Eżempju ta\' sentenza oħra.' | ||
| sentences = malti.sent_splitter.split(text) | ||
| print(sentences) | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| ['Eżempju ta\' sentenza.', 'Eżempju ta\' sentenza oħra.'] | ||
|
|
||
|
|
||
| The ``SentSplitter`` class | ||
| -------------------------- | ||
|
|
||
| The above is a convenience function that makes use of a default sentence splitter (``KMSentSplitter`` in this version). | ||
| To gain access to all the features of sentence splitters, they should be used in their class form, for example: | ||
|
|
||
| .. code-block:: python | ||
| :linenos: | ||
|
|
||
| import malti.sent_splitter | ||
|
|
||
| splitter = malti.sent_splitter.KMSentSplitter() | ||
|
|
||
| text = 'Eżempju ta\' sentenza. Eżempju ta\' sentenza oħra.' | ||
| sentences = splitter.split(text) | ||
| print(sentences) | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| ['Eżempju ta\' sentenza.', 'Eżempju ta\' sentenza oħra.'] | ||
|
|
||
|
|
||
| Available sentence splitters | ||
| ---------------------------- | ||
|
|
||
| The following sentence splitters are available: | ||
|
|
||
| * ``malti.tokeniser.KMSentSplitter`` (:doc:`../malti/sent_splitter/km_sent_splitter/km_sent_splitter`): A ``SentSplitter`` that is equivalent to the one used to split sentences in the `Korpus Malti <https://mlrs.research.um.edu.mt/CQPweb/>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| sentence_splitter==1.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,6 @@ | |
|
|
||
| import os | ||
|
|
||
| __version__ = '0.1.0' | ||
| __version__ = '0.2.0' | ||
|
|
||
| path = os.path.dirname(os.path.abspath(__file__)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ''' | ||
| Sentence splitters for Maltese text. | ||
| ''' | ||
|
|
||
| from malti.sent_splitter.sent_splitter import SentSplitter | ||
| from malti.sent_splitter.km_sent_splitter.km_sent_splitter import KMSentSplitter | ||
|
|
||
|
|
||
| ####################################################### | ||
| def split( | ||
| text: str, | ||
| ) -> list[str]: | ||
| ''' | ||
| Default sentence splitter. | ||
| In this version, ``KMSentenceSplitter`` is used. | ||
|
|
||
| :param text: The text to split. | ||
| :return: The list of sentences. | ||
| ''' | ||
| return KMSentSplitter().split(text) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ''' | ||
| The MLRS Korpus Malti's sentence splitter. | ||
| ''' |
49 changes: 49 additions & 0 deletions
49
src/malti/sent_splitter/km_sent_splitter/km_sent_splitter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| ''' | ||
| Korpus Malti sentence splitter. | ||
| ''' | ||
|
|
||
| import os | ||
| import sentence_splitter | ||
| import malti | ||
| from malti.sent_splitter.sent_splitter import SentSplitter | ||
|
|
||
|
|
||
| __all__ = [ | ||
| 'KMSentSplitter', | ||
| ] | ||
|
|
||
|
|
||
| ####################################################### | ||
| class KMSentSplitter(SentSplitter): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the full word "Sentence" for this? Similarly for the module name, etc. |
||
| ''' | ||
| The sentence splitter used by the MLRS Korpus Malti corpus. | ||
| ''' | ||
|
|
||
| ####################################################### | ||
| def __init__( | ||
| self, | ||
| ) -> None: | ||
| ''' | ||
| Constructor. | ||
| ''' | ||
| super().__init__() | ||
| self._spltter = sentence_splitter.SentenceSplitter( | ||
| language='it', | ||
| non_breaking_prefix_file=os.path.join( | ||
| malti.path, 'sent_splitter', 'km_sent_splitter', | ||
| 'mt_non_breaking_prefixes.txt', | ||
| ), | ||
| ) | ||
|
|
||
| ####################################################### | ||
| def split( | ||
| self, | ||
| text: str, | ||
| ) -> list[str]: | ||
| ''' | ||
| Split a text into a list of sentences. | ||
|
|
||
| :param text: The text to split. | ||
| :return: The list of sentences. | ||
| ''' | ||
| return self._spltter.split(text) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these comments, they add unnecessary clutter.