furrow 0.1.0__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.
- furrow-0.1.0/LICENSE +21 -0
- furrow-0.1.0/PKG-INFO +57 -0
- furrow-0.1.0/README.md +47 -0
- furrow-0.1.0/pyproject.toml +13 -0
- furrow-0.1.0/src/furrow/__init__.py +1 -0
- furrow-0.1.0/src/furrow/engine.py +127 -0
furrow-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elinah
|
|
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.
|
furrow-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: furrow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A sleek state-machine parser to segment, extract, and format structured question chains from smashed-together text streams (OCR, handwriting text dumps, transcripts, and LLM outputs).
|
|
5
|
+
Author-email: Elinah Moyo <growthsim2@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# Furrow
|
|
12
|
+
|
|
13
|
+
A lightweight, zero-dependency Python package to extract, segment, and format structured question chains from unformatted, smashed-together text blocks (OCR, handwriting text dumps, unformatted LLM outputs, or transcripts) without data loss.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install furrow
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from furrow import Plow
|
|
25
|
+
|
|
26
|
+
# 1. Initialize with your raw string
|
|
27
|
+
messy_text = "was1 . i was a girl19.There i with her 500 grapes .7. Amazing!"
|
|
28
|
+
engine = Plow(messy_text)
|
|
29
|
+
|
|
30
|
+
# 2. Get questions as a list of dictionaries
|
|
31
|
+
print(engine.collect())
|
|
32
|
+
# [{'question_number': '19', 'text': '.There i with her 500 grapes .'}, ...]
|
|
33
|
+
|
|
34
|
+
# 3. Get the text layout with newlines safely injected
|
|
35
|
+
print(engine.render())
|
|
36
|
+
# Output:
|
|
37
|
+
# was
|
|
38
|
+
# 1. i was a girl
|
|
39
|
+
# 19.There i with her 500 grapes .
|
|
40
|
+
# 7. Amazing!
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## How It Works
|
|
44
|
+
|
|
45
|
+
Furrow uses a single-pass state machine to parse and structure text layout:
|
|
46
|
+
|
|
47
|
+
* **State Tracking**: Steps through the text character by character to map the exact indices where number blocks start and end.
|
|
48
|
+
|
|
49
|
+
* **Noise Filtering**: Measures the distance between identified numbers and trailing periods. This allows it to separate inline data variables (like `500 grapes`) from actual question indices (like `19.`).
|
|
50
|
+
* **Data Safety**: Injects newline characters (`\n`) via string slicing. This ensures 100% data preservation of non-question text (headers, footers, intro text).
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
* **`engine.collect()`**: Compiles and returns a list of question data nodes for databases or JSON storage.
|
|
55
|
+
* **`engine.render()`**: Returns the full original text formatted with clean line breaks for UI display.
|
|
56
|
+
|
|
57
|
+
*Note: You do not need to call the internal parsing loops manually. Calling either `.collect()` or `.render()` triggers `.run()` automatically if it has not executed yet.*
|
furrow-0.1.0/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Furrow
|
|
2
|
+
|
|
3
|
+
A lightweight, zero-dependency Python package to extract, segment, and format structured question chains from unformatted, smashed-together text blocks (OCR, handwriting text dumps, unformatted LLM outputs, or transcripts) without data loss.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install furrow
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from furrow import Plow
|
|
15
|
+
|
|
16
|
+
# 1. Initialize with your raw string
|
|
17
|
+
messy_text = "was1 . i was a girl19.There i with her 500 grapes .7. Amazing!"
|
|
18
|
+
engine = Plow(messy_text)
|
|
19
|
+
|
|
20
|
+
# 2. Get questions as a list of dictionaries
|
|
21
|
+
print(engine.collect())
|
|
22
|
+
# [{'question_number': '19', 'text': '.There i with her 500 grapes .'}, ...]
|
|
23
|
+
|
|
24
|
+
# 3. Get the text layout with newlines safely injected
|
|
25
|
+
print(engine.render())
|
|
26
|
+
# Output:
|
|
27
|
+
# was
|
|
28
|
+
# 1. i was a girl
|
|
29
|
+
# 19.There i with her 500 grapes .
|
|
30
|
+
# 7. Amazing!
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## How It Works
|
|
34
|
+
|
|
35
|
+
Furrow uses a single-pass state machine to parse and structure text layout:
|
|
36
|
+
|
|
37
|
+
* **State Tracking**: Steps through the text character by character to map the exact indices where number blocks start and end.
|
|
38
|
+
|
|
39
|
+
* **Noise Filtering**: Measures the distance between identified numbers and trailing periods. This allows it to separate inline data variables (like `500 grapes`) from actual question indices (like `19.`).
|
|
40
|
+
* **Data Safety**: Injects newline characters (`\n`) via string slicing. This ensures 100% data preservation of non-question text (headers, footers, intro text).
|
|
41
|
+
|
|
42
|
+
## API Reference
|
|
43
|
+
|
|
44
|
+
* **`engine.collect()`**: Compiles and returns a list of question data nodes for databases or JSON storage.
|
|
45
|
+
* **`engine.render()`**: Returns the full original text formatted with clean line breaks for UI display.
|
|
46
|
+
|
|
47
|
+
*Note: You do not need to call the internal parsing loops manually. Calling either `.collect()` or `.render()` triggers `.run()` automatically if it has not executed yet.*
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "furrow"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A sleek state-machine parser to segment, extract, and format structured question chains from smashed-together text streams (OCR, handwriting text dumps, transcripts, and LLM outputs)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Elinah Moyo", email = "growthsim2@gmail.com" }]
|
|
13
|
+
dependencies = []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .engine import Plow
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
class Plow:
|
|
2
|
+
def __init__(self,input_data):
|
|
3
|
+
self.text = input_data
|
|
4
|
+
self.token = []
|
|
5
|
+
self._has_run = False
|
|
6
|
+
|
|
7
|
+
def run(self):
|
|
8
|
+
#oky now we search ch boundaried to find indexes
|
|
9
|
+
number = ""
|
|
10
|
+
number_start = None
|
|
11
|
+
number_end = None
|
|
12
|
+
period_pos = None
|
|
13
|
+
|
|
14
|
+
active_number = False
|
|
15
|
+
|
|
16
|
+
for i in range(len(self.text)):
|
|
17
|
+
current = self.text[i]
|
|
18
|
+
|
|
19
|
+
if current.isdigit():
|
|
20
|
+
if not active_number:
|
|
21
|
+
number_start = i
|
|
22
|
+
active_number = True
|
|
23
|
+
|
|
24
|
+
number+= current
|
|
25
|
+
else:
|
|
26
|
+
if number != "":
|
|
27
|
+
number_end = i-1
|
|
28
|
+
|
|
29
|
+
current_number_data = {
|
|
30
|
+
"number": number,
|
|
31
|
+
"start": number_start,
|
|
32
|
+
"end": number_end ,
|
|
33
|
+
"period_position": None
|
|
34
|
+
}
|
|
35
|
+
self.token.append(current_number_data)
|
|
36
|
+
|
|
37
|
+
number = ""
|
|
38
|
+
number_start = None
|
|
39
|
+
active_number = False
|
|
40
|
+
|
|
41
|
+
if current == ".":
|
|
42
|
+
period_pos = i
|
|
43
|
+
|
|
44
|
+
if self.token:
|
|
45
|
+
last = self.token[-1]
|
|
46
|
+
|
|
47
|
+
distance = period_pos-last["end"]
|
|
48
|
+
|
|
49
|
+
if distance <=3:
|
|
50
|
+
last["period_position"] = period_pos
|
|
51
|
+
|
|
52
|
+
self._has_run = True
|
|
53
|
+
|
|
54
|
+
def collect(self):
|
|
55
|
+
"""Gathers the split text chunks into structured question nodes."""
|
|
56
|
+
|
|
57
|
+
if not self._has_run:
|
|
58
|
+
self.run()
|
|
59
|
+
|
|
60
|
+
for item in self.token:
|
|
61
|
+
if item["period_position"] is None:
|
|
62
|
+
item["is_question"] = False
|
|
63
|
+
|
|
64
|
+
else:
|
|
65
|
+
distance = item["period_position"]- item["end"]
|
|
66
|
+
|
|
67
|
+
if distance <=3:
|
|
68
|
+
item["is_question"]= True
|
|
69
|
+
|
|
70
|
+
else:
|
|
71
|
+
item["is_question"]= False
|
|
72
|
+
|
|
73
|
+
## slice between
|
|
74
|
+
|
|
75
|
+
for i in range(len(self.token)):
|
|
76
|
+
if not self.token[i]["is_question"]:
|
|
77
|
+
continue
|
|
78
|
+
|
|
79
|
+
start = self.token[i]["period_position"]
|
|
80
|
+
end = len(self.text)
|
|
81
|
+
|
|
82
|
+
for j in range(i+1, len(self.token)):
|
|
83
|
+
if self.token[j]["is_question"]:
|
|
84
|
+
end = self.token[j]["start"]
|
|
85
|
+
break
|
|
86
|
+
|
|
87
|
+
self.token[i]["text"] = self.text[start:end]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
questions = []
|
|
91
|
+
|
|
92
|
+
for item in self.token:
|
|
93
|
+
if item.get("is_question"):
|
|
94
|
+
questions.append({
|
|
95
|
+
"question_number": item["number"],
|
|
96
|
+
"text": item["text"]
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
return questions
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def render(self):
|
|
103
|
+
|
|
104
|
+
### inject lines but not losing the non questions
|
|
105
|
+
if not self._has_run:
|
|
106
|
+
self.run()
|
|
107
|
+
|
|
108
|
+
if not self.token:
|
|
109
|
+
return self.text
|
|
110
|
+
|
|
111
|
+
valid_questions = [item for item in self.token if item.get("is_question")]
|
|
112
|
+
|
|
113
|
+
if not valid_questions:
|
|
114
|
+
return self.text
|
|
115
|
+
|
|
116
|
+
formatted_pieces = []
|
|
117
|
+
current_index = 0
|
|
118
|
+
|
|
119
|
+
for item in valid_questions:
|
|
120
|
+
start_pos = item["start"]
|
|
121
|
+
formatted_pieces.append(self.text[current_index:start_pos])
|
|
122
|
+
formatted_pieces.append("\n")
|
|
123
|
+
current_index = start_pos
|
|
124
|
+
|
|
125
|
+
formatted_pieces.append(self.text[current_index:])
|
|
126
|
+
return "".join(formatted_pieces)
|
|
127
|
+
|