-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_fallacy_test.py
More file actions
116 lines (94 loc) · 3.67 KB
/
simple_fallacy_test.py
File metadata and controls
116 lines (94 loc) · 3.67 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Simple standalone test for fallacy detection patterns.
This script implements a minimal version of the pattern-based detection
to test if our patterns work with the test string.
"""
import re
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)
# Define fallacy types (simplified version)
FALLACY_TYPES = {
"False Dichotomy": "Presenting only two options when more likely exist.",
"Appeal to Emotion": "Using emotional appeals instead of logic.",
"Hasty Generalization": "Drawing broad conclusions from limited evidence.",
}
def test_fallacy_patterns(text):
"""
Test fallacy detection patterns on the provided text.
Args:
text: The text to analyze
Returns:
List of detected fallacies
"""
fallacies = []
# False Dichotomy - Legal Context
legal_false_dichotomy_patterns = [
r"(do not|never|avoid)\s+([\w\s]+)\s+(as|since|because)\s+it\s+(could|might|may|can be)\s+([\w\s]+)",
r"(refrain from)\s+([\w\s]+)\s+(as|since|because|even if)\s+([\w\s]+)",
]
for pattern in legal_false_dichotomy_patterns:
matches = re.finditer(pattern, text, re.IGNORECASE)
for match in matches:
fallacies.append(
{
"type": "False Dichotomy",
"description": FALLACY_TYPES["False Dichotomy"],
"text": match.group(0),
}
)
# Appeal to Emotion - Fear patterns
fear_appeal_patterns = [
r"(misconstrued|mistaken|misinterpreted)\s+as\s+([\w\s]+)",
r"(could|might|may)\s+be\s+(misconstrued|mistaken|misinterpreted)",
]
for pattern in fear_appeal_patterns:
matches = re.finditer(pattern, text, re.IGNORECASE)
for match in matches:
fallacies.append(
{
"type": "Appeal to Emotion",
"description": FALLACY_TYPES["Appeal to Emotion"],
"text": match.group(0),
}
)
# Hasty Generalization - Legal Context
hasty_gen_patterns = [
r"(do not|never|avoid)\s+([\w\s]+)\s+(legal|law|laws)",
r"(even if)\s+you\s+have\s+access\s+to\s+([\w\s]+)",
]
for pattern in hasty_gen_patterns:
matches = re.finditer(pattern, text, re.IGNORECASE)
for match in matches:
fallacies.append(
{
"type": "Hasty Generalization",
"description": FALLACY_TYPES["Hasty Generalization"],
"text": match.group(0),
}
)
return fallacies
def main():
# Define our test string
test_string = """Do not interpret laws or suggest legal courses of action.
Never Imply Legal Knowledge: Even if you have access to legal information, refrain from using it to analyze or comment on a user's situation.
Avoid General Legal Information: Do not provide general information about legal concepts (e.g., marital property, asset division) as it could be misconstrued as advice."""
logger.info("Test string:")
logger.info("-" * 80)
logger.info(test_string)
logger.info("-" * 80)
# Run pattern detection test
fallacies = test_fallacy_patterns(test_string)
# Print results
logger.info(f"Pattern-based detection found {len(fallacies)} fallacies:")
for i, fallacy in enumerate(fallacies, 1):
logger.info(f"{i}. {fallacy['type']}: {fallacy['text']}")
logger.info(f" Description: {fallacy['description']}")
logger.info("\nTest completed.")
if __name__ == "__main__":
main()