-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_patterns.py
72 lines (62 loc) · 2.28 KB
/
test_patterns.py
1
2
3
4
5
6
7
8
9
10
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
67
68
69
70
71
72
"""
Pattern matching test script for cognitive metrics.
This script validates the core pattern matching functionality,
following British English standards and proper type safety.
"""
import spacy
from pathlib import Path
import sys
def main():
"""Test core pattern matching functionality."""
print("Testing Pattern Matching")
print("======================")
try:
# Load spaCy model
print("\nLoading NLP model...")
nlp = spacy.load("en_core_web_sm")
print("✓ Model loaded successfully")
# Test text with various patterns
test_text = """
First, let's examine the evidence. According to recent studies,
the approach shows promising results. However, we must consider
some limitations. For example, the sample size was relatively
small. Therefore, while the data suggests positive outcomes,
further validation would be beneficial.
"""
# Process text
print("\nProcessing test text...")
doc = nlp(test_text)
print("✓ Text processed successfully")
# Define patterns to test
patterns = {
"Logical Steps": [
"first", "therefore", "while"
],
"Evidence Markers": [
"according to", "studies", "data suggests"
],
"Counterarguments": [
"however", "limitations"
],
"Examples": [
"for example"
]
}
# Test pattern matching
print("\nTesting patterns:")
for category, terms in patterns.items():
print(f"\n{category}:")
for term in terms:
found = term.lower() in test_text.lower()
print(f"- {term}: {'✓' if found else '✗'}")
if found:
# Find the sentence containing the pattern
for sent in doc.sents:
if term.lower() in sent.text.lower():
print(f" Context: {sent.text.strip()}")
print("\n✓ Pattern matching test completed successfully!")
except Exception as e:
print(f"\n✗ Error: {e}")
return
if __name__ == "__main__":
main()