parsely-dip 0.0.4__tar.gz → 0.0.6__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.
- {parsely_dip-0.0.4/src/parsely_dip.egg-info → parsely_dip-0.0.6}/PKG-INFO +12 -2
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/README.md +11 -1
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/pyproject.toml +1 -1
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/__init__.py +1 -1
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/nlp.py +7 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6/src/parsely_dip.egg-info}/PKG-INFO +12 -2
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip.egg-info/SOURCES.txt +2 -1
- parsely_dip-0.0.6/tests/test_runner.py +202 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/LICENSE +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/setup.cfg +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/cli/__init__.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/cli/main.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/__init__.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/regex.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/registry.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/splitter.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/engine/stanza_service.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/intents/__init__.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/intents/day.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/intents/scrum.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/intents/time.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/intents/weather.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip/patterns/__init__.py +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip.egg-info/dependency_links.txt +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip.egg-info/entry_points.txt +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip.egg-info/requires.txt +0 -0
- {parsely_dip-0.0.4 → parsely_dip-0.0.6}/src/parsely_dip.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parsely-dip
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: PARSELY-DIP: Deterministic Intent Parser — RegEx and NLP pipeline for intent recognition
|
|
5
5
|
Author-email: George Butiri <george@iseestudios.com>
|
|
6
6
|
License: Proprietary
|
|
@@ -786,9 +786,19 @@ Every NLP pattern must be maximally specific. Include all words that disambiguat
|
|
|
786
786
|
|
|
787
787
|
```
|
|
788
788
|
WEATHER_API_KEY=your_openweathermap_key
|
|
789
|
-
STANZA_API_TOKEN=
|
|
789
|
+
STANZA_API_TOKEN=shared_secret_both_sides_use_this
|
|
790
790
|
```
|
|
791
791
|
|
|
792
|
+
#### About `STANZA_API_TOKEN`
|
|
793
|
+
|
|
794
|
+
The Stanza NLP service accepts an optional `X-Stanza-Token` header and — if `STANZA_API_TOKEN` is set in the service's environment — rejects requests whose header does not match. This keeps drive-by localhost scripts from hitting your running NLP service.
|
|
795
|
+
|
|
796
|
+
**Starting in 0.0.6, parsely-dip reads the same `STANZA_API_TOKEN` env var from its own process and sends it as `X-Stanza-Token` on every Stanza request.** Both sides must have the same value. Practical implications:
|
|
797
|
+
|
|
798
|
+
- **If your Stanza service has no token set:** do nothing. parsely-dip sends no header, service accepts the request, things work.
|
|
799
|
+
- **If your Stanza service has a token set:** export the same value in the environment where you call `parse()` (or load your `.env` before importing parsely-dip). Without it, the NLP layer silently falls through to LLM/no-match on every request.
|
|
800
|
+
- **If you run a web app that calls `parse()`:** make sure your app process inherits `STANZA_API_TOKEN` — it's not enough to have it in a file the app doesn't load.
|
|
801
|
+
|
|
792
802
|
### pyproject.toml Dependencies
|
|
793
803
|
|
|
794
804
|
```toml
|
|
@@ -763,9 +763,19 @@ Every NLP pattern must be maximally specific. Include all words that disambiguat
|
|
|
763
763
|
|
|
764
764
|
```
|
|
765
765
|
WEATHER_API_KEY=your_openweathermap_key
|
|
766
|
-
STANZA_API_TOKEN=
|
|
766
|
+
STANZA_API_TOKEN=shared_secret_both_sides_use_this
|
|
767
767
|
```
|
|
768
768
|
|
|
769
|
+
#### About `STANZA_API_TOKEN`
|
|
770
|
+
|
|
771
|
+
The Stanza NLP service accepts an optional `X-Stanza-Token` header and — if `STANZA_API_TOKEN` is set in the service's environment — rejects requests whose header does not match. This keeps drive-by localhost scripts from hitting your running NLP service.
|
|
772
|
+
|
|
773
|
+
**Starting in 0.0.6, parsely-dip reads the same `STANZA_API_TOKEN` env var from its own process and sends it as `X-Stanza-Token` on every Stanza request.** Both sides must have the same value. Practical implications:
|
|
774
|
+
|
|
775
|
+
- **If your Stanza service has no token set:** do nothing. parsely-dip sends no header, service accepts the request, things work.
|
|
776
|
+
- **If your Stanza service has a token set:** export the same value in the environment where you call `parse()` (or load your `.env` before importing parsely-dip). Without it, the NLP layer silently falls through to LLM/no-match on every request.
|
|
777
|
+
- **If you run a web app that calls `parse()`:** make sure your app process inherits `STANZA_API_TOKEN` — it's not enough to have it in a file the app doesn't load.
|
|
778
|
+
|
|
769
779
|
### pyproject.toml Dependencies
|
|
770
780
|
|
|
771
781
|
```toml
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "parsely-dip"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.6"
|
|
8
8
|
description = "PARSELY-DIP: Deterministic Intent Parser — RegEx and NLP pipeline for intent recognition"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "Proprietary"}
|
|
@@ -5,6 +5,7 @@ then matches against NLP pattern specs (JSON).
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import json
|
|
8
|
+
import os
|
|
8
9
|
import requests
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
|
|
@@ -122,10 +123,16 @@ def check_nlp(user_input, patterns, stanza_url=None):
|
|
|
122
123
|
"""
|
|
123
124
|
url = stanza_url or STANZA_URL
|
|
124
125
|
|
|
126
|
+
headers = {}
|
|
127
|
+
token = os.getenv("STANZA_API_TOKEN")
|
|
128
|
+
if token:
|
|
129
|
+
headers["X-Stanza-Token"] = token
|
|
130
|
+
|
|
125
131
|
try:
|
|
126
132
|
response = requests.post(
|
|
127
133
|
url,
|
|
128
134
|
json={"user_input": user_input},
|
|
135
|
+
headers=headers,
|
|
129
136
|
timeout=5
|
|
130
137
|
)
|
|
131
138
|
response.raise_for_status()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parsely-dip
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: PARSELY-DIP: Deterministic Intent Parser — RegEx and NLP pipeline for intent recognition
|
|
5
5
|
Author-email: George Butiri <george@iseestudios.com>
|
|
6
6
|
License: Proprietary
|
|
@@ -786,9 +786,19 @@ Every NLP pattern must be maximally specific. Include all words that disambiguat
|
|
|
786
786
|
|
|
787
787
|
```
|
|
788
788
|
WEATHER_API_KEY=your_openweathermap_key
|
|
789
|
-
STANZA_API_TOKEN=
|
|
789
|
+
STANZA_API_TOKEN=shared_secret_both_sides_use_this
|
|
790
790
|
```
|
|
791
791
|
|
|
792
|
+
#### About `STANZA_API_TOKEN`
|
|
793
|
+
|
|
794
|
+
The Stanza NLP service accepts an optional `X-Stanza-Token` header and — if `STANZA_API_TOKEN` is set in the service's environment — rejects requests whose header does not match. This keeps drive-by localhost scripts from hitting your running NLP service.
|
|
795
|
+
|
|
796
|
+
**Starting in 0.0.6, parsely-dip reads the same `STANZA_API_TOKEN` env var from its own process and sends it as `X-Stanza-Token` on every Stanza request.** Both sides must have the same value. Practical implications:
|
|
797
|
+
|
|
798
|
+
- **If your Stanza service has no token set:** do nothing. parsely-dip sends no header, service accepts the request, things work.
|
|
799
|
+
- **If your Stanza service has a token set:** export the same value in the environment where you call `parse()` (or load your `.env` before importing parsely-dip). Without it, the NLP layer silently falls through to LLM/no-match on every request.
|
|
800
|
+
- **If you run a web app that calls `parse()`:** make sure your app process inherits `STANZA_API_TOKEN` — it's not enough to have it in a file the app doesn't load.
|
|
801
|
+
|
|
792
802
|
### pyproject.toml Dependencies
|
|
793
803
|
|
|
794
804
|
```toml
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""PARSELY-DIP Test Runner
|
|
2
|
+
|
|
3
|
+
Loads .tests files and runs each test case against the pattern engine.
|
|
4
|
+
Writes results to parsely_tests table in db/parsely.db.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
py tests/test_runner.py tests/tell_time.tests
|
|
8
|
+
py tests/test_runner.py tests/tell_time.tests --type regex
|
|
9
|
+
py tests/test_runner.py tests/tell_time.tests --type nlp
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
import os
|
|
14
|
+
import sqlite3
|
|
15
|
+
import argparse
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
# Add src to path
|
|
20
|
+
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
|
|
21
|
+
|
|
22
|
+
from parsely_dip.engine.regex import load_patterns, check_regex
|
|
23
|
+
from parsely_dip.engine.nlp import load_nlp_patterns, check_nlp
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
DB_PATH = Path(__file__).parent.parent / 'db' / 'parsely.db'
|
|
27
|
+
PATTERNS_DIR = Path(__file__).parent.parent / 'src' / 'parsely_dip' / 'patterns'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parse_test_file(filepath):
|
|
31
|
+
"""Parse a .tests file into test cases.
|
|
32
|
+
|
|
33
|
+
Format: sentence => intent | type | expected
|
|
34
|
+
Returns list of dicts.
|
|
35
|
+
"""
|
|
36
|
+
tests = []
|
|
37
|
+
path = Path(filepath)
|
|
38
|
+
if not path.exists():
|
|
39
|
+
print(f"Test file not found: {filepath}")
|
|
40
|
+
return tests
|
|
41
|
+
|
|
42
|
+
for line in path.read_text(encoding='utf-8').splitlines():
|
|
43
|
+
line = line.strip()
|
|
44
|
+
if not line or line.startswith('#'):
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
parts = line.split('=>')
|
|
48
|
+
if len(parts) != 2:
|
|
49
|
+
continue
|
|
50
|
+
|
|
51
|
+
sentence = parts[0].strip()
|
|
52
|
+
meta = parts[1].strip()
|
|
53
|
+
fields = [f.strip() for f in meta.split('|')]
|
|
54
|
+
|
|
55
|
+
if len(fields) != 3:
|
|
56
|
+
print(f"Skipping malformed line: {line}")
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
intent, test_type, expected = fields
|
|
60
|
+
tests.append({
|
|
61
|
+
'input': sentence,
|
|
62
|
+
'intent': intent,
|
|
63
|
+
'type': test_type,
|
|
64
|
+
'expected': int(expected)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return tests
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def run_tests(tests, type_filter=None, source_file=None):
|
|
71
|
+
"""Run test cases against the engine.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
tests: list of test dicts from parse_test_file
|
|
75
|
+
type_filter: 'regex', 'nlp', or None (both)
|
|
76
|
+
source_file: name of the .tests file
|
|
77
|
+
"""
|
|
78
|
+
# Load patterns
|
|
79
|
+
regex_patterns = load_patterns(PATTERNS_DIR / 'base.patterns')
|
|
80
|
+
nlp_patterns = load_nlp_patterns(PATTERNS_DIR / 'base_nlp.json')
|
|
81
|
+
|
|
82
|
+
run_timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
83
|
+
db = sqlite3.connect(str(DB_PATH))
|
|
84
|
+
|
|
85
|
+
passed = 0
|
|
86
|
+
failed = 0
|
|
87
|
+
skipped = 0
|
|
88
|
+
errors = []
|
|
89
|
+
|
|
90
|
+
# Check if stanza is available for NLP tests
|
|
91
|
+
stanza_available = False
|
|
92
|
+
nlp_needed = any(t['type'] == 'nlp' for t in tests)
|
|
93
|
+
if nlp_needed and type_filter != 'regex':
|
|
94
|
+
try:
|
|
95
|
+
import requests
|
|
96
|
+
r = requests.get('http://127.0.0.1:5013/', timeout=2)
|
|
97
|
+
stanza_available = True
|
|
98
|
+
except Exception:
|
|
99
|
+
print(" Stanza service not running — NLP tests will be skipped")
|
|
100
|
+
|
|
101
|
+
for t in tests:
|
|
102
|
+
if type_filter and t['type'] != type_filter:
|
|
103
|
+
skipped += 1
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
if t['type'] == 'nlp' and not stanza_available:
|
|
107
|
+
skipped += 1
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
# Run the test
|
|
111
|
+
if t['type'] == 'regex':
|
|
112
|
+
intent, _ = check_regex(t['input'], regex_patterns)
|
|
113
|
+
matched = 1 if intent == t['intent'] else 0
|
|
114
|
+
elif t['type'] == 'nlp':
|
|
115
|
+
intent, _ = check_nlp(t['input'], nlp_patterns)
|
|
116
|
+
matched = 1 if intent == t['intent'] else 0
|
|
117
|
+
else:
|
|
118
|
+
skipped += 1
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
# Compare
|
|
122
|
+
test_passed = (matched == t['expected'])
|
|
123
|
+
if test_passed:
|
|
124
|
+
passed += 1
|
|
125
|
+
status = 'PASS'
|
|
126
|
+
else:
|
|
127
|
+
failed += 1
|
|
128
|
+
status = 'FAIL'
|
|
129
|
+
errors.append({
|
|
130
|
+
'input': t['input'],
|
|
131
|
+
'intent': t['intent'],
|
|
132
|
+
'type': t['type'],
|
|
133
|
+
'expected': t['expected'],
|
|
134
|
+
'got': matched
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
# Write to DB
|
|
138
|
+
db.execute('''
|
|
139
|
+
INSERT INTO parsely_tests (pt_input, pt_intent, pt_type, pt_source, pt_expected, pt_result, pt_run)
|
|
140
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
141
|
+
''', (t['input'], t['intent'], t['type'], source_file, t['expected'], matched, run_timestamp))
|
|
142
|
+
|
|
143
|
+
db.commit()
|
|
144
|
+
db.close()
|
|
145
|
+
|
|
146
|
+
# Print results
|
|
147
|
+
total = passed + failed
|
|
148
|
+
print()
|
|
149
|
+
print(f" {'='*50}")
|
|
150
|
+
print(f" PARSELY-DIP Test Results")
|
|
151
|
+
print(f" {'='*50}")
|
|
152
|
+
print(f" Run: {run_timestamp}")
|
|
153
|
+
print(f" Source: {source_file}")
|
|
154
|
+
print(f" {'─'*50}")
|
|
155
|
+
print(f" Total: {total} | Passed: {passed} | Failed: {failed} | Skipped: {skipped}")
|
|
156
|
+
|
|
157
|
+
if total > 0:
|
|
158
|
+
pct = (passed / total) * 100
|
|
159
|
+
bar_len = 30
|
|
160
|
+
filled = int(bar_len * passed / total)
|
|
161
|
+
bar = '#' * filled + '-' * (bar_len - filled)
|
|
162
|
+
print(f" Score: [{bar}] {pct:.0f}%")
|
|
163
|
+
|
|
164
|
+
if errors:
|
|
165
|
+
print(f" {'─'*50}")
|
|
166
|
+
print(f" FAILURES:")
|
|
167
|
+
for e in errors:
|
|
168
|
+
exp_label = "MATCH" if e['expected'] == 1 else "NO MATCH"
|
|
169
|
+
got_label = "MATCH" if e['got'] == 1 else "NO MATCH"
|
|
170
|
+
print(f" [{e['type'].upper():5s}] \"{e['input']}\"")
|
|
171
|
+
print(f" Intent: {e['intent']} Expected: {exp_label} Got: {got_label}")
|
|
172
|
+
|
|
173
|
+
print(f" {'='*50}")
|
|
174
|
+
print()
|
|
175
|
+
|
|
176
|
+
return failed == 0
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def main():
|
|
180
|
+
parser = argparse.ArgumentParser(description='PARSELY-DIP Test Runner')
|
|
181
|
+
parser.add_argument('testfile', help='Path to .tests file')
|
|
182
|
+
parser.add_argument('--type', choices=['regex', 'nlp'], default=None,
|
|
183
|
+
help='Only run tests of this type')
|
|
184
|
+
args = parser.parse_args()
|
|
185
|
+
|
|
186
|
+
source_file = Path(args.testfile).name
|
|
187
|
+
|
|
188
|
+
print()
|
|
189
|
+
print(f" Loading tests from {source_file}...")
|
|
190
|
+
tests = parse_test_file(args.testfile)
|
|
191
|
+
if not tests:
|
|
192
|
+
print(" No tests found.")
|
|
193
|
+
return
|
|
194
|
+
|
|
195
|
+
print(f" Found {len(tests)} test cases")
|
|
196
|
+
|
|
197
|
+
success = run_tests(tests, type_filter=args.type, source_file=source_file)
|
|
198
|
+
sys.exit(0 if success else 1)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
if __name__ == '__main__':
|
|
202
|
+
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|