pysegmenters-rules_segmenter 1.6.265__tar.gz → 1.6.271__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/.pre-commit-config.yaml +0 -2
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/PKG-INFO +1 -8
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/pyproject.toml +2 -19
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/src/pysegmenters_rules_segmenter/__init__.py +1 -1
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/src/pysegmenters_rules_segmenter/rules_segmenter.py +17 -80
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/src/pysegmenters_rules_segmenter/rules_sentencizer.py +5 -0
- pysegmenters_rules_segmenter-1.6.265/.bumpversion.cfg +0 -23
- pysegmenters_rules_segmenter-1.6.265/.github/workflows/main.yml +0 -37
- pysegmenters_rules_segmenter-1.6.265/.readthedocs.yml +0 -15
- pysegmenters_rules_segmenter-1.6.265/RELEASE.md +0 -39
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/.gitignore +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/.gitmodules +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/.python-version +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/AUTHORS.md +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/CHANGELOG.md +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/LICENSE +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/README.md +0 -0
- {pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/Taskfile.yml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pysegmenters-rules_segmenter
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.271
|
|
4
4
|
Summary: Rule-based segmenter
|
|
5
5
|
Project-URL: Homepage, https://github.com/oterrier/pysegmenters_rules_segmenter/
|
|
6
6
|
Author-email: Olivier Terrier <olivier.terrier@kairntech.com>
|
|
@@ -22,14 +22,7 @@ Requires-Python: >=3.12
|
|
|
22
22
|
Requires-Dist: pymultirole-plugins<1.7.0,>=1.6.0
|
|
23
23
|
Requires-Dist: spacy[lookups]>=3.7.0
|
|
24
24
|
Provides-Extra: dev
|
|
25
|
-
Requires-Dist: bump2version; extra == 'dev'
|
|
26
25
|
Requires-Dist: pre-commit; extra == 'dev'
|
|
27
|
-
Provides-Extra: docs
|
|
28
|
-
Requires-Dist: lxml-html-clean; extra == 'docs'
|
|
29
|
-
Requires-Dist: m2r2; extra == 'docs'
|
|
30
|
-
Requires-Dist: sphinx; extra == 'docs'
|
|
31
|
-
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
|
|
32
|
-
Requires-Dist: sphinxcontrib-apidoc; extra == 'docs'
|
|
33
26
|
Provides-Extra: sbom
|
|
34
27
|
Requires-Dist: cyclonedx-bom; extra == 'sbom'
|
|
35
28
|
Requires-Dist: pip-audit; extra == 'sbom'
|
{pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/pyproject.toml
RENAMED
|
@@ -44,17 +44,7 @@ test = [
|
|
|
44
44
|
"ruff",
|
|
45
45
|
"pip",
|
|
46
46
|
]
|
|
47
|
-
|
|
48
|
-
"sphinx",
|
|
49
|
-
"sphinx-rtd-theme",
|
|
50
|
-
"m2r2",
|
|
51
|
-
"sphinxcontrib.apidoc",
|
|
52
|
-
"lxml_html_clean",
|
|
53
|
-
]
|
|
54
|
-
dev = [
|
|
55
|
-
"pre-commit",
|
|
56
|
-
"bump2version",
|
|
57
|
-
]
|
|
47
|
+
dev = ["pre-commit"]
|
|
58
48
|
|
|
59
49
|
sbom = ["cyclonedx-bom", "pip-audit"]
|
|
60
50
|
|
|
@@ -70,14 +60,7 @@ exclude = [
|
|
|
70
60
|
"/tests",
|
|
71
61
|
"/docs",
|
|
72
62
|
"Jenkinsfile",
|
|
73
|
-
"
|
|
74
|
-
"bumpversion.py",
|
|
75
|
-
"mypy.ini",
|
|
76
|
-
"hgnc_cache.sqlite",
|
|
77
|
-
"trivy-html-template.tpl",
|
|
78
|
-
"MIGRATION.md",
|
|
79
|
-
".gitignore",
|
|
80
|
-
".dockerignore"
|
|
63
|
+
".gitignore"
|
|
81
64
|
]
|
|
82
65
|
|
|
83
66
|
[tool.pytest.ini_options]
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import logging
|
|
3
|
-
import time
|
|
4
3
|
from abc import ABC
|
|
5
4
|
from functools import cache
|
|
6
5
|
from typing import Any, cast
|
|
@@ -10,8 +9,7 @@ from pydantic import BaseModel, Field
|
|
|
10
9
|
from pymultirole_plugins.util import comma_separated_to_list
|
|
11
10
|
from pymultirole_plugins.v1.schema import Document, Sentence
|
|
12
11
|
from pymultirole_plugins.v1.segmenter import SegmenterBase, SegmenterParameters
|
|
13
|
-
from spacy.cli.download import
|
|
14
|
-
from spacy.language import Language
|
|
12
|
+
from spacy.cli.download import download, get_compatibility
|
|
15
13
|
from wasabi import msg
|
|
16
14
|
|
|
17
15
|
from pysegmenters_rules_segmenter.rules_sentencizer import RuleSentencizer
|
|
@@ -116,13 +114,13 @@ class RulesSegmenter(SegmenterBase, ABC):
|
|
|
116
114
|
exc_info=True,
|
|
117
115
|
)
|
|
118
116
|
return documents
|
|
117
|
+
json_split = json_rules_to_string(split_rules)
|
|
118
|
+
json_join = json_rules_to_string(join_rules)
|
|
119
119
|
for document in documents:
|
|
120
120
|
# Retrieve nlp pipe
|
|
121
|
-
lang =
|
|
121
|
+
lang = (document.metadata or {}).get("language")
|
|
122
122
|
if lang is None or lang not in supported_languages:
|
|
123
123
|
raise AttributeError(f"Metadata language {lang} is required and must be in {SUPPORTED_LANGUAGES}")
|
|
124
|
-
json_split = json_rules_to_string(split_rules)
|
|
125
|
-
json_join = json_rules_to_string(join_rules)
|
|
126
124
|
nlp, enable_pipes = get_custom_sentencizer(lang, json_split, json_join)
|
|
127
125
|
with nlp.select_pipes(enable=enable_pipes):
|
|
128
126
|
document.sentences = []
|
|
@@ -140,12 +138,6 @@ class RulesSegmenter(SegmenterBase, ABC):
|
|
|
140
138
|
return RulesSegmenterParameters
|
|
141
139
|
|
|
142
140
|
|
|
143
|
-
def document_language(doc: Document, default: str = None):
|
|
144
|
-
if doc.metadata is not None and "language" in doc.metadata:
|
|
145
|
-
return doc.metadata["language"]
|
|
146
|
-
return default
|
|
147
|
-
|
|
148
|
-
|
|
149
141
|
def json_rules_to_string(json_rules: list[list[dict[str, Any]]]):
|
|
150
142
|
str_rules = None
|
|
151
143
|
if json_rules:
|
|
@@ -158,7 +150,7 @@ def json_rules_to_string(json_rules: list[list[dict[str, Any]]]):
|
|
|
158
150
|
return str_rules
|
|
159
151
|
|
|
160
152
|
|
|
161
|
-
#
|
|
153
|
+
# spaCy model of each language; a language without one gets a blank model
|
|
162
154
|
MODEL_SHORTCUTS = {
|
|
163
155
|
"en": "en_core_web_sm",
|
|
164
156
|
"de": "de_core_news_sm",
|
|
@@ -167,31 +159,29 @@ MODEL_SHORTCUTS = {
|
|
|
167
159
|
"fr": "fr_core_news_sm",
|
|
168
160
|
"it": "it_core_news_sm",
|
|
169
161
|
"nl": "nl_core_news_sm",
|
|
170
|
-
"el": "el_core_news_sm",
|
|
171
|
-
"nb": "nb_core_news_sm",
|
|
172
|
-
"lt": "lt_core_news_sm",
|
|
173
|
-
"xx": "xx_ent_wiki_sm",
|
|
174
162
|
"zh": "zh_core_web_sm",
|
|
175
163
|
"ru": "ru_core_news_sm",
|
|
176
|
-
"ja": "ja_core_news_sm",
|
|
177
164
|
}
|
|
178
165
|
|
|
179
166
|
|
|
180
167
|
@cache
|
|
181
|
-
def get_nlp(lang: str, exclude=()
|
|
182
|
-
del ttl_hash
|
|
168
|
+
def get_nlp(lang: str, exclude=()):
|
|
183
169
|
model = MODEL_SHORTCUTS.get(lang, lang)
|
|
184
|
-
# model = lang
|
|
185
170
|
try:
|
|
186
|
-
|
|
187
|
-
except
|
|
188
|
-
|
|
189
|
-
|
|
171
|
+
return spacy.load(model, exclude=exclude)
|
|
172
|
+
except OSError:
|
|
173
|
+
if model not in get_compatibility():
|
|
174
|
+
msg.fail(
|
|
175
|
+
f"No compatible package found for '{model}' (spaCy v{spacy.about.__version__}), fallback to blank model"
|
|
176
|
+
)
|
|
177
|
+
return spacy.blank(model)
|
|
178
|
+
download(model)
|
|
179
|
+
return spacy.load(model, exclude=exclude)
|
|
190
180
|
|
|
191
181
|
|
|
192
182
|
@cache
|
|
193
|
-
def get_custom_sentencizer(lang: str, json_split: str, json_join: str
|
|
194
|
-
nlp = get_nlp(lang, exclude=("parser", "tagger", "ner", "lemmatizer")
|
|
183
|
+
def get_custom_sentencizer(lang: str, json_split: str, json_join: str):
|
|
184
|
+
nlp = get_nlp(lang, exclude=("parser", "tagger", "ner", "lemmatizer"))
|
|
195
185
|
split_rules = json.loads(json_split) if json_split else None
|
|
196
186
|
join_rules = json.loads(json_join) if json_join else None
|
|
197
187
|
unique_name = f"sentencizer_{json_split if json_split else ''}_{json_join if json_join else ''}"
|
|
@@ -200,56 +190,3 @@ def get_custom_sentencizer(lang: str, json_split: str, json_join: str, ttl_hash=
|
|
|
200
190
|
)
|
|
201
191
|
enable_pipes = [p for p in nlp.pipe_names if not p.startswith("sentencizer_") or p == sentencizer.name]
|
|
202
192
|
return nlp, enable_pipes
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
@cache
|
|
206
|
-
def get_spacy_sentencizer(lang: str, ttl_hash=None):
|
|
207
|
-
nlp = get_nlp(lang, exclude=(), ttl_hash=ttl_hash)
|
|
208
|
-
enable_pipes = list(nlp.pipe_names)
|
|
209
|
-
return nlp, enable_pipes
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
def get_ttl_hash(seconds=3600):
|
|
213
|
-
"""Return the same value withing `seconds` time period"""
|
|
214
|
-
return round(time.time() / seconds)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def load_spacy_model(model, exclude, *pip_args):
|
|
218
|
-
suffix = "-py3-none-any.whl"
|
|
219
|
-
dl_tpl = "{m}-{v}/{m}-{v}{s}"
|
|
220
|
-
model_name = model
|
|
221
|
-
if model in MODEL_SHORTCUTS:
|
|
222
|
-
msg.warn(
|
|
223
|
-
f"As of spaCy v3.0, shortcuts like '{model}' are deprecated. Please "
|
|
224
|
-
f"use the full pipeline package name '{MODEL_SHORTCUTS[model]}' instead."
|
|
225
|
-
)
|
|
226
|
-
model_name = MODEL_SHORTCUTS[model]
|
|
227
|
-
compatibility = get_compatibility()
|
|
228
|
-
if model_name not in compatibility:
|
|
229
|
-
msg.fail(
|
|
230
|
-
f"No compatible package found for '{model}' (spaCy v{spacy.about.__version__}), fallback to blank model"
|
|
231
|
-
)
|
|
232
|
-
return spacy.blank(model_name)
|
|
233
|
-
else:
|
|
234
|
-
version = get_version(model_name, compatibility)
|
|
235
|
-
download_model(dl_tpl.format(m=model_name, v=version, s=suffix), pip_args)
|
|
236
|
-
msg.good(
|
|
237
|
-
"Download and installation successful",
|
|
238
|
-
f"You can now load the package via spacy.load('{model_name}')",
|
|
239
|
-
)
|
|
240
|
-
# If a model is downloaded and then loaded within the same process, our
|
|
241
|
-
# is_package check currently fails, because pkg_resources.working_set
|
|
242
|
-
# is not refreshed automatically (see #3923). We're trying to work
|
|
243
|
-
# around this here be requiring the package explicitly.
|
|
244
|
-
require_package(model_name)
|
|
245
|
-
return spacy.load(model_name, exclude=exclude)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
def require_package(name):
|
|
249
|
-
try:
|
|
250
|
-
import pkg_resources
|
|
251
|
-
|
|
252
|
-
pkg_resources.working_set.require(name)
|
|
253
|
-
return True
|
|
254
|
-
except: # noqa: E722
|
|
255
|
-
return False
|
|
@@ -68,6 +68,11 @@ class RuleSentencizer:
|
|
|
68
68
|
for token in doc[start:end]:
|
|
69
69
|
if token.is_sent_start:
|
|
70
70
|
token.is_sent_start = False
|
|
71
|
+
# Tokens no rule split on do not start a sentence: without this, a text where no rule
|
|
72
|
+
# matched has no SENT_START annotation, hence no sentence at all (SHERPA-3083)
|
|
73
|
+
for token in doc[1:]:
|
|
74
|
+
if token.is_sent_start is None:
|
|
75
|
+
token.is_sent_start = False
|
|
71
76
|
if doc.has_annotation("SENT_START"):
|
|
72
77
|
# Trim starting spaces
|
|
73
78
|
for sent in doc.sents:
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
[bumpversion]
|
|
2
|
-
current_version = 0.1.0.dev0
|
|
3
|
-
commit = True
|
|
4
|
-
tag = True
|
|
5
|
-
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<build>\d+))?
|
|
6
|
-
serialize =
|
|
7
|
-
{major}.{minor}.{patch}.{release}{build}
|
|
8
|
-
{major}.{minor}.{patch}
|
|
9
|
-
|
|
10
|
-
[bumpversion:part:release]
|
|
11
|
-
optional_value = prod
|
|
12
|
-
first_value = dev
|
|
13
|
-
values =
|
|
14
|
-
dev
|
|
15
|
-
prod
|
|
16
|
-
|
|
17
|
-
[bumpversion:part:build]
|
|
18
|
-
|
|
19
|
-
[bumpversion:file:pysegmenters_rules_segmenter/__init__.py]
|
|
20
|
-
|
|
21
|
-
[bumpversion:file:CHANGELOG.md]
|
|
22
|
-
search = ## [unreleased]
|
|
23
|
-
replace = ## [{new_version}]
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
name: tests
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
runs-on: ${{ matrix.os }}
|
|
8
|
-
strategy:
|
|
9
|
-
max-parallel: 4
|
|
10
|
-
matrix:
|
|
11
|
-
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
12
|
-
python-version: [3.8]
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v1
|
|
15
|
-
- shell: bash
|
|
16
|
-
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
|
|
17
|
-
id: extract_branch
|
|
18
|
-
- shell: bash
|
|
19
|
-
run: echo "##[set-output name=py_version;]$(py_ver=${{ matrix.python-version }} && echo ${py_ver//./})"
|
|
20
|
-
id: extract_py_version
|
|
21
|
-
- name: Set up Python ${{ matrix.python-version }}
|
|
22
|
-
uses: actions/setup-python@v1
|
|
23
|
-
with:
|
|
24
|
-
python-version: ${{ matrix.python-version }}
|
|
25
|
-
- name: Install dependencies
|
|
26
|
-
run: |
|
|
27
|
-
python -m pip install --upgrade pip
|
|
28
|
-
pip install tox tox-gh-actions
|
|
29
|
-
- name: Test
|
|
30
|
-
run: tox
|
|
31
|
-
- name: Upload coverage
|
|
32
|
-
if: matrix.os == 'ubuntu-latest'
|
|
33
|
-
uses: codecov/codecov-action@v1.0.3
|
|
34
|
-
with:
|
|
35
|
-
token: ${{secrets.CODECOV_TOKEN}}
|
|
36
|
-
file: ./.coverage.xml
|
|
37
|
-
flags: ${{ steps.extract_branch.outputs.branch }},py${{ steps.extract_py_version.outputs.py_version }}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# Release Instructions
|
|
2
|
-
|
|
3
|
-
This document guides a contributor through creating a release of pysegmenters_rules_segmenter.
|
|
4
|
-
|
|
5
|
-
## Preflight checks
|
|
6
|
-
|
|
7
|
-
### Ensure all tests pass
|
|
8
|
-
|
|
9
|
-
Locally you can run `tox` to check that all tests pass, and check that tests
|
|
10
|
-
against all supported environments are passing also by checking qsim's
|
|
11
|
-
[GitHub actions](https://github.com/oterrier/pysegmenters_rules_segmenter/actions?query=branch%3Amaster+workflow%3Atests).
|
|
12
|
-
|
|
13
|
-
#### Verify that `AUTHORS.md` is up-to-date
|
|
14
|
-
|
|
15
|
-
The following command shows the number of commits per author since the last
|
|
16
|
-
annotated tag:
|
|
17
|
-
```
|
|
18
|
-
t=$(git describe --abbrev=0); echo Commits since $t; git shortlog -s $t..
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Make the release
|
|
22
|
-
|
|
23
|
-
Run
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
bumpversion release # bump version from .devX to release version
|
|
27
|
-
git push --tags # push tagged release to upstream
|
|
28
|
-
flit publish # publish to PyPI
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Start work on the next release
|
|
32
|
-
|
|
33
|
-
Run
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
bumpversion minor
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
To start work on the next release
|
|
File without changes
|
|
File without changes
|
{pysegmenters_rules_segmenter-1.6.265 → pysegmenters_rules_segmenter-1.6.271}/.python-version
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|