fast-sentence-segment 0.1.9__tar.gz → 1.1.8__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.
- fast_sentence_segment-1.1.8/LICENSE +21 -0
- fast_sentence_segment-1.1.8/PKG-INFO +146 -0
- fast_sentence_segment-1.1.8/README.md +118 -0
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/__init__.py +18 -18
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/bp/__init__.py +1 -1
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/bp/segmenter.py +65 -68
- fast_sentence_segment-1.1.8/fast_sentence_segment/core/__init__.py +4 -0
- fast_sentence_segment-1.1.8/fast_sentence_segment/core/base_object.py +18 -0
- fast_sentence_segment-1.1.8/fast_sentence_segment/core/stopwatch.py +38 -0
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/__init__.py +6 -6
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/bullet_point_cleaner.py +55 -55
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/delimiters_to_periods.py +37 -37
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/newlines_to_periods.py +57 -57
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/numbered_list_normalizer.py +53 -53
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/post_process_sentences.py +48 -48
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/spacy_doc_segmenter.py +101 -101
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/svc/__init__.py +2 -2
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/svc/perform_paragraph_segmentation.py +50 -50
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/svc/perform_sentence_segmentation.py +129 -129
- {fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/pyproject.toml +49 -61
- fast_sentence_segment-1.1.8/setup.py +34 -0
- fast-sentence-segment-0.1.9/PKG-INFO +0 -54
- fast-sentence-segment-0.1.9/README.md +0 -29
- fast-sentence-segment-0.1.9/setup.py +0 -33
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Craig Trim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fast-sentence-segment
|
|
3
|
+
Version: 1.1.8
|
|
4
|
+
Summary: Fast and Efficient Sentence Segmentation
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: nlp,text,preprocess,segment
|
|
8
|
+
Author: Craig Trim
|
|
9
|
+
Author-email: craigtrim@gmail.com
|
|
10
|
+
Maintainer: Craig Trim
|
|
11
|
+
Maintainer-email: craigtrim@gmail.com
|
|
12
|
+
Requires-Python: >=3.9,<4.0
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Dist: spacy (>=3.8.0,<4.0.0)
|
|
24
|
+
Project-URL: Bug Tracker, https://github.com/craigtrim/fast-sentence-segment/issues
|
|
25
|
+
Project-URL: Repository, https://github.com/craigtrim/fast-sentence-segment
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Fast Sentence Segmentation
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/fast-sentence-segment/)
|
|
31
|
+
[](https://pypi.org/project/fast-sentence-segment/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
[](https://spacy.io/)
|
|
34
|
+
|
|
35
|
+
Fast and efficient sentence segmentation using spaCy. Handles complex edge cases like abbreviations (Dr., Mr., etc.), quoted text, and multi-paragraph documents.
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Paragraph-aware segmentation**: Returns sentences grouped by paragraph
|
|
40
|
+
- **Abbreviation handling**: Correctly handles "Dr.", "Mr.", "etc." without false splits
|
|
41
|
+
- **Cached processing**: LRU cache for repeated text processing
|
|
42
|
+
- **Flexible output**: Nested lists (by paragraph) or flattened list of sentences
|
|
43
|
+
- **Bullet point & numbered list normalization**: Cleans common list formats
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install fast-sentence-segment
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
After installation, download the spaCy model:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m spacy download en_core_web_sm
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from fast_sentence_segment import segment_text
|
|
61
|
+
|
|
62
|
+
text = "Here is a Dr. who says something. And then again, what else? I don't know. Do you?"
|
|
63
|
+
|
|
64
|
+
results = segment_text(text)
|
|
65
|
+
# Returns: [['Here is a Dr. who says something.', 'And then again, what else?', "I don't know.", 'Do you?']]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Basic Segmentation
|
|
71
|
+
|
|
72
|
+
The `segment_text` function returns a list of lists, where each inner list represents a paragraph containing its sentences:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from fast_sentence_segment import segment_text
|
|
76
|
+
|
|
77
|
+
text = """First paragraph here. It has two sentences.
|
|
78
|
+
|
|
79
|
+
Second paragraph starts here. This one also has multiple sentences. And a third."""
|
|
80
|
+
|
|
81
|
+
results = segment_text(text)
|
|
82
|
+
# Returns:
|
|
83
|
+
# [
|
|
84
|
+
# ['First paragraph here.', 'It has two sentences.'],
|
|
85
|
+
# ['Second paragraph starts here.', 'This one also has multiple sentences.', 'And a third.']
|
|
86
|
+
# ]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Flattened Output
|
|
90
|
+
|
|
91
|
+
If you don't need paragraph boundaries, use the `flatten` parameter:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
results = segment_text(text, flatten=True)
|
|
95
|
+
# Returns: ['First paragraph here.', 'It has two sentences.', 'Second paragraph starts here.', ...]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Direct Segmenter Access
|
|
99
|
+
|
|
100
|
+
For more control, use the `Segmenter` class directly:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from fast_sentence_segment import Segmenter
|
|
104
|
+
|
|
105
|
+
segmenter = Segmenter()
|
|
106
|
+
results = segmenter.input_text("Your text here.")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API Reference
|
|
110
|
+
|
|
111
|
+
| Function | Parameters | Returns | Description |
|
|
112
|
+
|----------|------------|---------|-------------|
|
|
113
|
+
| `segment_text()` | `input_text: str`, `flatten: bool = False` | `list` | Main entry point for segmentation |
|
|
114
|
+
| `Segmenter.input_text()` | `input_text: str` | `list[list[str]]` | Cached paragraph-aware segmentation |
|
|
115
|
+
|
|
116
|
+
## Why Nested Lists?
|
|
117
|
+
|
|
118
|
+
The segmentation process preserves document structure by segmenting into both paragraphs and sentences. Each outer list represents a paragraph, and each inner list contains that paragraph's sentences. This is useful for:
|
|
119
|
+
|
|
120
|
+
- Document structure analysis
|
|
121
|
+
- Paragraph-level processing
|
|
122
|
+
- Maintaining original text organization
|
|
123
|
+
|
|
124
|
+
Use `flatten=True` when you only need sentences without paragraph context.
|
|
125
|
+
|
|
126
|
+
## Requirements
|
|
127
|
+
|
|
128
|
+
- Python 3.8.5+
|
|
129
|
+
- spaCy 3.5.3
|
|
130
|
+
- en_core_web_sm spaCy model
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
139
|
+
|
|
140
|
+
1. Fork the repository
|
|
141
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
142
|
+
3. Run tests (`make test`)
|
|
143
|
+
4. Commit your changes
|
|
144
|
+
5. Push to the branch
|
|
145
|
+
6. Open a Pull Request
|
|
146
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Fast Sentence Segmentation
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/fast-sentence-segment/)
|
|
4
|
+
[](https://pypi.org/project/fast-sentence-segment/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://spacy.io/)
|
|
7
|
+
|
|
8
|
+
Fast and efficient sentence segmentation using spaCy. Handles complex edge cases like abbreviations (Dr., Mr., etc.), quoted text, and multi-paragraph documents.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Paragraph-aware segmentation**: Returns sentences grouped by paragraph
|
|
13
|
+
- **Abbreviation handling**: Correctly handles "Dr.", "Mr.", "etc." without false splits
|
|
14
|
+
- **Cached processing**: LRU cache for repeated text processing
|
|
15
|
+
- **Flexible output**: Nested lists (by paragraph) or flattened list of sentences
|
|
16
|
+
- **Bullet point & numbered list normalization**: Cleans common list formats
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install fast-sentence-segment
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
After installation, download the spaCy model:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
python -m spacy download en_core_web_sm
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from fast_sentence_segment import segment_text
|
|
34
|
+
|
|
35
|
+
text = "Here is a Dr. who says something. And then again, what else? I don't know. Do you?"
|
|
36
|
+
|
|
37
|
+
results = segment_text(text)
|
|
38
|
+
# Returns: [['Here is a Dr. who says something.', 'And then again, what else?', "I don't know.", 'Do you?']]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Basic Segmentation
|
|
44
|
+
|
|
45
|
+
The `segment_text` function returns a list of lists, where each inner list represents a paragraph containing its sentences:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from fast_sentence_segment import segment_text
|
|
49
|
+
|
|
50
|
+
text = """First paragraph here. It has two sentences.
|
|
51
|
+
|
|
52
|
+
Second paragraph starts here. This one also has multiple sentences. And a third."""
|
|
53
|
+
|
|
54
|
+
results = segment_text(text)
|
|
55
|
+
# Returns:
|
|
56
|
+
# [
|
|
57
|
+
# ['First paragraph here.', 'It has two sentences.'],
|
|
58
|
+
# ['Second paragraph starts here.', 'This one also has multiple sentences.', 'And a third.']
|
|
59
|
+
# ]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Flattened Output
|
|
63
|
+
|
|
64
|
+
If you don't need paragraph boundaries, use the `flatten` parameter:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
results = segment_text(text, flatten=True)
|
|
68
|
+
# Returns: ['First paragraph here.', 'It has two sentences.', 'Second paragraph starts here.', ...]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Direct Segmenter Access
|
|
72
|
+
|
|
73
|
+
For more control, use the `Segmenter` class directly:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from fast_sentence_segment import Segmenter
|
|
77
|
+
|
|
78
|
+
segmenter = Segmenter()
|
|
79
|
+
results = segmenter.input_text("Your text here.")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
| Function | Parameters | Returns | Description |
|
|
85
|
+
|----------|------------|---------|-------------|
|
|
86
|
+
| `segment_text()` | `input_text: str`, `flatten: bool = False` | `list` | Main entry point for segmentation |
|
|
87
|
+
| `Segmenter.input_text()` | `input_text: str` | `list[list[str]]` | Cached paragraph-aware segmentation |
|
|
88
|
+
|
|
89
|
+
## Why Nested Lists?
|
|
90
|
+
|
|
91
|
+
The segmentation process preserves document structure by segmenting into both paragraphs and sentences. Each outer list represents a paragraph, and each inner list contains that paragraph's sentences. This is useful for:
|
|
92
|
+
|
|
93
|
+
- Document structure analysis
|
|
94
|
+
- Paragraph-level processing
|
|
95
|
+
- Maintaining original text organization
|
|
96
|
+
|
|
97
|
+
Use `flatten=True` when you only need sentences without paragraph context.
|
|
98
|
+
|
|
99
|
+
## Requirements
|
|
100
|
+
|
|
101
|
+
- Python 3.8.5+
|
|
102
|
+
- spaCy 3.5.3
|
|
103
|
+
- en_core_web_sm spaCy model
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
108
|
+
|
|
109
|
+
## Contributing
|
|
110
|
+
|
|
111
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
112
|
+
|
|
113
|
+
1. Fork the repository
|
|
114
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
115
|
+
3. Run tests (`make test`)
|
|
116
|
+
4. Commit your changes
|
|
117
|
+
5. Push to the branch
|
|
118
|
+
6. Open a Pull Request
|
{fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/__init__.py
RENAMED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
from .bp import *
|
|
2
|
-
from .svc import *
|
|
3
|
-
from .dmo import *
|
|
4
|
-
|
|
5
|
-
from .bp.segmenter import Segmenter
|
|
6
|
-
|
|
7
|
-
segment = Segmenter().input_text
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def segment_text(input_text: str, flatten: bool = False) -> list:
|
|
11
|
-
results = segment(input_text)
|
|
12
|
-
|
|
13
|
-
if flatten:
|
|
14
|
-
flat = []
|
|
15
|
-
[[flat.append(y) for y in x] for x in results]
|
|
16
|
-
return flat
|
|
17
|
-
|
|
18
|
-
return results
|
|
1
|
+
from .bp import *
|
|
2
|
+
from .svc import *
|
|
3
|
+
from .dmo import *
|
|
4
|
+
|
|
5
|
+
from .bp.segmenter import Segmenter
|
|
6
|
+
|
|
7
|
+
segment = Segmenter().input_text
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def segment_text(input_text: str, flatten: bool = False) -> list:
|
|
11
|
+
results = segment(input_text)
|
|
12
|
+
|
|
13
|
+
if flatten:
|
|
14
|
+
flat = []
|
|
15
|
+
[[flat.append(y) for y in x] for x in results]
|
|
16
|
+
return flat
|
|
17
|
+
|
|
18
|
+
return results
|
{fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/bp/__init__.py
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
from .segmenter import Segmenter
|
|
1
|
+
from .segmenter import Segmenter
|
{fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/bp/segmenter.py
RENAMED
|
@@ -1,68 +1,65 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: UTF-8 -*-
|
|
3
|
-
""" Orchestrate Sentence Segmentation """
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from functools import lru_cache
|
|
7
|
-
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
f"\tTotal Time: {str(sw)}"]))
|
|
67
|
-
|
|
68
|
-
return paragraphs
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
""" Orchestrate Sentence Segmentation """
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
|
|
8
|
+
from fast_sentence_segment.core import BaseObject, Stopwatch
|
|
9
|
+
from fast_sentence_segment.svc import PerformParagraphSegmentation
|
|
10
|
+
from fast_sentence_segment.svc import PerformSentenceSegmentation
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Segmenter(BaseObject):
|
|
14
|
+
""" Orchestrate Sentence Segmentation """
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
""" Change Log
|
|
18
|
+
|
|
19
|
+
Created:
|
|
20
|
+
30-Sept-2021
|
|
21
|
+
"""
|
|
22
|
+
BaseObject.__init__(self, __name__)
|
|
23
|
+
self._segment_paragraphs = PerformParagraphSegmentation().process
|
|
24
|
+
self._segment_sentences = PerformSentenceSegmentation().process
|
|
25
|
+
|
|
26
|
+
def _input_text(self,
|
|
27
|
+
input_text: str) -> list:
|
|
28
|
+
paragraphs = []
|
|
29
|
+
|
|
30
|
+
for paragraph in self._segment_paragraphs(input_text):
|
|
31
|
+
paragraphs.append(self._segment_sentences(paragraph))
|
|
32
|
+
|
|
33
|
+
return paragraphs
|
|
34
|
+
|
|
35
|
+
@lru_cache(maxsize=1024, typed=True)
|
|
36
|
+
def input_text(self,
|
|
37
|
+
input_text: str) -> list:
|
|
38
|
+
"""Segment Input Text into Paragraphs and Sentences
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
input_text (str): An input string of any length or type
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ValueError: input must be a string
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
list: returns a list of lists.
|
|
48
|
+
Each outer list is a paragraph.
|
|
49
|
+
Each inner list contains 1..* sentences
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
if self.isEnabledForDebug and not isinstance(input_text, str):
|
|
53
|
+
raise ValueError(f"Expected str, got {type(input_text)}")
|
|
54
|
+
|
|
55
|
+
sw = Stopwatch()
|
|
56
|
+
|
|
57
|
+
paragraphs = self._input_text(input_text)
|
|
58
|
+
|
|
59
|
+
if self.isEnabledForInfo:
|
|
60
|
+
self.logger.info('\n'.join([
|
|
61
|
+
"Segmentation of Input Text Complete",
|
|
62
|
+
f"\tTotal Paragraphs: {len(paragraphs)}",
|
|
63
|
+
f"\tTotal Time: {str(sw)}"]))
|
|
64
|
+
|
|
65
|
+
return paragraphs
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Base object providing logging functionality."""
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
logging.basicConfig(
|
|
7
|
+
format='%(asctime)s : %(levelname)s : %(filename)s : %(funcName)s() : %(lineno)d : %(message)s',
|
|
8
|
+
level=logging.DEBUG)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BaseObject:
|
|
12
|
+
"""Base class providing logging capabilities."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, component_name: str):
|
|
15
|
+
self.logger = logging.getLogger(component_name)
|
|
16
|
+
self.isEnabledForDebug = self.logger.isEnabledFor(logging.DEBUG)
|
|
17
|
+
self.isEnabledForInfo = self.logger.isEnabledFor(logging.INFO)
|
|
18
|
+
self.isEnabledForWarning = self.logger.isEnabledFor(logging.WARNING)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Simple stopwatch for timing operations."""
|
|
3
|
+
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Stopwatch:
|
|
8
|
+
"""A simple stopwatch for measuring elapsed time."""
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
self._start = time.perf_counter()
|
|
12
|
+
self._end = None
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def duration(self):
|
|
16
|
+
return self._end - self._start if self._end else time.perf_counter() - self._start
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def running(self):
|
|
20
|
+
return not self._end
|
|
21
|
+
|
|
22
|
+
def restart(self):
|
|
23
|
+
self._start = time.perf_counter()
|
|
24
|
+
self._end = None
|
|
25
|
+
return self
|
|
26
|
+
|
|
27
|
+
def stop(self):
|
|
28
|
+
if self.running:
|
|
29
|
+
self._end = time.perf_counter()
|
|
30
|
+
return self
|
|
31
|
+
|
|
32
|
+
def __str__(self):
|
|
33
|
+
ms = self.duration * 1000
|
|
34
|
+
if ms >= 1000:
|
|
35
|
+
return f'{ms / 1000:.2f}s'
|
|
36
|
+
if ms >= 1:
|
|
37
|
+
return f'{ms:.2f}ms'
|
|
38
|
+
return f'{ms * 1000:.2f}μs'
|
{fast-sentence-segment-0.1.9 → fast_sentence_segment-1.1.8}/fast_sentence_segment/dmo/__init__.py
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from .bullet_point_cleaner import BulletPointCleaner
|
|
2
|
-
from .delimiters_to_periods import DelimitersToPeriods
|
|
3
|
-
from .newlines_to_periods import NewlinesToPeriods
|
|
4
|
-
from .post_process_sentences import PostProcessStructure
|
|
5
|
-
from .spacy_doc_segmenter import SpacyDocSegmenter
|
|
6
|
-
from .numbered_list_normalizer import NumberedListNormalizer
|
|
1
|
+
from .bullet_point_cleaner import BulletPointCleaner
|
|
2
|
+
from .delimiters_to_periods import DelimitersToPeriods
|
|
3
|
+
from .newlines_to_periods import NewlinesToPeriods
|
|
4
|
+
from .post_process_sentences import PostProcessStructure
|
|
5
|
+
from .spacy_doc_segmenter import SpacyDocSegmenter
|
|
6
|
+
from .numbered_list_normalizer import NumberedListNormalizer
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: UTF-8 -*-
|
|
3
|
-
""" Prevent Bullet Points from Triggering False Positive Segmentation """
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class BulletPointCleaner(BaseObject):
|
|
10
|
-
""" Prevent Bullet Points from Triggering False Positive Segmentation """
|
|
11
|
-
|
|
12
|
-
def __init__(self):
|
|
13
|
-
""" Change Log
|
|
14
|
-
|
|
15
|
-
Created:
|
|
16
|
-
30-Sept-2021
|
|
17
|
-
craigtrim@gmail.com
|
|
18
|
-
Updated:
|
|
19
|
-
19-Oct-2022
|
|
20
|
-
craigtrim@gmail.com
|
|
21
|
-
* clean up for segment_text_3_test.py
|
|
22
|
-
"""
|
|
23
|
-
BaseObject.__init__(self, __name__)
|
|
24
|
-
|
|
25
|
-
@staticmethod
|
|
26
|
-
def process(input_text: str) -> str:
|
|
27
|
-
"""
|
|
28
|
-
Purpose:
|
|
29
|
-
prevent numbered bullet points from triggering sentence detection
|
|
30
|
-
:param input_text:
|
|
31
|
-
any input text
|
|
32
|
-
:return:
|
|
33
|
-
preprocessed input text
|
|
34
|
-
"""
|
|
35
|
-
if input_text.startswith("-"):
|
|
36
|
-
input_text = input_text[1:] # segment_text_3_test.py
|
|
37
|
-
|
|
38
|
-
if " " in input_text:
|
|
39
|
-
input_text = input_text.replace(" ", " ")
|
|
40
|
-
|
|
41
|
-
# the replacement routine above leaves double '..' in the text
|
|
42
|
-
# this replacement will solve that
|
|
43
|
-
while ".." in input_text:
|
|
44
|
-
input_text = input_text.replace("..", ".")
|
|
45
|
-
|
|
46
|
-
while ". -" in input_text: # segment_text_3_test.py
|
|
47
|
-
input_text = input_text.replace(". -", ". ")
|
|
48
|
-
|
|
49
|
-
while ". . " in input_text:
|
|
50
|
-
input_text = input_text.replace(". . ", ".")
|
|
51
|
-
|
|
52
|
-
while ' ' in input_text:
|
|
53
|
-
input_text = input_text.replace(' ', ' ')
|
|
54
|
-
|
|
55
|
-
return input_text
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: UTF-8 -*-
|
|
3
|
+
""" Prevent Bullet Points from Triggering False Positive Segmentation """
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from fast_sentence_segment.core import BaseObject
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BulletPointCleaner(BaseObject):
|
|
10
|
+
""" Prevent Bullet Points from Triggering False Positive Segmentation """
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
""" Change Log
|
|
14
|
+
|
|
15
|
+
Created:
|
|
16
|
+
30-Sept-2021
|
|
17
|
+
craigtrim@gmail.com
|
|
18
|
+
Updated:
|
|
19
|
+
19-Oct-2022
|
|
20
|
+
craigtrim@gmail.com
|
|
21
|
+
* clean up for segment_text_3_test.py
|
|
22
|
+
"""
|
|
23
|
+
BaseObject.__init__(self, __name__)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def process(input_text: str) -> str:
|
|
27
|
+
"""
|
|
28
|
+
Purpose:
|
|
29
|
+
prevent numbered bullet points from triggering sentence detection
|
|
30
|
+
:param input_text:
|
|
31
|
+
any input text
|
|
32
|
+
:return:
|
|
33
|
+
preprocessed input text
|
|
34
|
+
"""
|
|
35
|
+
if input_text.startswith("-"):
|
|
36
|
+
input_text = input_text[1:] # segment_text_3_test.py
|
|
37
|
+
|
|
38
|
+
if " " in input_text:
|
|
39
|
+
input_text = input_text.replace(" ", " ")
|
|
40
|
+
|
|
41
|
+
# the replacement routine above leaves double '..' in the text
|
|
42
|
+
# this replacement will solve that
|
|
43
|
+
while ".." in input_text:
|
|
44
|
+
input_text = input_text.replace("..", ".")
|
|
45
|
+
|
|
46
|
+
while ". -" in input_text: # segment_text_3_test.py
|
|
47
|
+
input_text = input_text.replace(". -", ". ")
|
|
48
|
+
|
|
49
|
+
while ". . " in input_text:
|
|
50
|
+
input_text = input_text.replace(". . ", ".")
|
|
51
|
+
|
|
52
|
+
while ' ' in input_text:
|
|
53
|
+
input_text = input_text.replace(' ', ' ')
|
|
54
|
+
|
|
55
|
+
return input_text
|