pythen 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.
- pythen-0.1.0/LICENSE +21 -0
- pythen-0.1.0/PKG-INFO +176 -0
- pythen-0.1.0/README.md +139 -0
- pythen-0.1.0/docs/__init__.py +10 -0
- pythen-0.1.0/examples/__init__.py +19 -0
- pythen-0.1.0/examples/contract_law.py +262 -0
- pythen-0.1.0/examples/gdpr_article17.py +217 -0
- pythen-0.1.0/pythen/__init__.py +43 -0
- pythen-0.1.0/pythen/evaluator.py +201 -0
- pythen-0.1.0/pythen/utils.py +222 -0
- pythen-0.1.0/pythen.egg-info/PKG-INFO +176 -0
- pythen-0.1.0/pythen.egg-info/SOURCES.txt +18 -0
- pythen-0.1.0/pythen.egg-info/dependency_links.txt +1 -0
- pythen-0.1.0/pythen.egg-info/requires.txt +7 -0
- pythen-0.1.0/pythen.egg-info/top_level.txt +4 -0
- pythen-0.1.0/setup.cfg +4 -0
- pythen-0.1.0/setup.py +53 -0
- pythen-0.1.0/tests/__init__.py +6 -0
- pythen-0.1.0/tests/test_evaluator.py +199 -0
- pythen-0.1.0/tests/test_utils.py +257 -0
pythen-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PYTHEN Contributors
|
|
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.
|
pythen-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pythen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A flexible framework for legal reasoning in Python
|
|
5
|
+
Home-page: https://github.com/nguyenthanhasia/pythen
|
|
6
|
+
Author: PYTHEN Contributors
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Legal Industry
|
|
10
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Requires-Python: >=3.7
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-cov>=2.10; extra == "dev"
|
|
25
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
26
|
+
Requires-Dist: flake8>=3.9; extra == "dev"
|
|
27
|
+
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: classifier
|
|
30
|
+
Dynamic: description
|
|
31
|
+
Dynamic: description-content-type
|
|
32
|
+
Dynamic: home-page
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
Dynamic: provides-extra
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
Dynamic: summary
|
|
37
|
+
|
|
38
|
+
# PYTHEN: A Flexible Framework for Legal Reasoning in Python
|
|
39
|
+
|
|
40
|
+
[](https://opensource.org/licenses/MIT)
|
|
41
|
+
[](https://www.python.org/)
|
|
42
|
+
|
|
43
|
+
**PYTHEN** is a Python-native framework for defeasible legal reasoning. It provides an intuitive, human-readable way to model complex legal rules, conditions, and exceptions, making formal legal reasoning accessible to developers, legal professionals, and researchers without extensive logic programming expertise.
|
|
44
|
+
|
|
45
|
+
Inspired by **PROLEG** (PROlog-based LEGal reasoning support system) and guided by the philosophy of **The Zen of Python**, PYTHEN bridges the gap between powerful symbolic reasoning systems and the practical, ubiquitous Python ecosystem.
|
|
46
|
+
|
|
47
|
+
## Key Features
|
|
48
|
+
|
|
49
|
+
- **Simple & Readable Syntax**: Rules are defined in a clean JSON format that is easy to read and write.
|
|
50
|
+
- **Python-Native Philosophy**: The design is inspired by The Zen of Python, emphasizing simplicity, readability, and practicality. The `ALL` and `ANY` operators directly mirror Python's built-in `all()` and `any()` functions.
|
|
51
|
+
- **Defeasible Reasoning**: Explicitly model exceptions to rules, a core feature of legal reasoning.
|
|
52
|
+
- **Accessible**: Designed for developers, legal scholars, and students who are comfortable with Python but may not be experts in Prolog or formal logic.
|
|
53
|
+
- **LLM-Friendly**: The structured JSON format makes PYTHEN an ideal target for autoformalization pipelines, where Large Language Models (LLMs) translate natural language legal text into executable rules.
|
|
54
|
+
- **Explainable AI (XAI)**: Generate clear, step-by-step explanations of the reasoning process for transparency and debugging.
|
|
55
|
+
- **Zero Dependencies**: The core evaluator is written in pure Python with no external dependencies.
|
|
56
|
+
|
|
57
|
+
## Philosophy: The Zen of Python in Legal Tech
|
|
58
|
+
|
|
59
|
+
PYTHEN's design is deeply influenced by The Zen of Python (PEP 20). We believe these principles are especially relevant for legal technology:
|
|
60
|
+
|
|
61
|
+
> - **Beautiful is better than ugly.** Legal rules should be represented cleanly.
|
|
62
|
+
> - **Explicit is better than implicit.** Exceptions and conditions are stated clearly in each rule.
|
|
63
|
+
> - **Simple is better than complex.** No need to learn a complex new syntax if you already know Python and JSON.
|
|
64
|
+
> - **Readability counts.** A legal rule base should be understandable by lawyers, not just programmers.
|
|
65
|
+
|
|
66
|
+
By adhering to these principles, PYTHEN aims to make computational law more accessible, transparent, and maintainable.
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
**From PyPI (Recommended):**
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install pythen
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**For Development:**
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
git clone https://github.com/nguyenthanhasia/pythen.git
|
|
80
|
+
cd pythen
|
|
81
|
+
pip install -e .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Quickstart: 30-Second Example
|
|
85
|
+
|
|
86
|
+
Let's model a simple rule: "A contract is voidable if the party was a minor, UNLESS the contract was for necessities."
|
|
87
|
+
|
|
88
|
+
**1. Define the Rules**
|
|
89
|
+
|
|
90
|
+
Create a list of rule dictionaries. The `op` can be `ANY` (like Python's `any()`) or `ALL` (like `all()`).
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from pythen import RuleTreeEvaluator
|
|
94
|
+
|
|
95
|
+
# Define the rule set
|
|
96
|
+
contract_rules = [
|
|
97
|
+
{
|
|
98
|
+
"p": "contract_voidable",
|
|
99
|
+
"op": "ANY",
|
|
100
|
+
"conditions": ["party_is_minor"],
|
|
101
|
+
"exceptions": ["contract_for_necessities"]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"p": "party_is_minor",
|
|
105
|
+
"op": "ALL",
|
|
106
|
+
"conditions": ["party_age_below_18"],
|
|
107
|
+
"exceptions": []
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**2. Define the Facts**
|
|
113
|
+
|
|
114
|
+
Create a list of facts for a specific case.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Case 1: A 16-year-old buys a luxury item
|
|
118
|
+
facts_case_1 = ["party_age_below_18"]
|
|
119
|
+
|
|
120
|
+
# Case 2: A 17-year-old buys food (a necessity)
|
|
121
|
+
facts_case_2 = ["party_age_below_18", "contract_for_necessities"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**3. Evaluate**
|
|
125
|
+
|
|
126
|
+
Instantiate the `RuleTreeEvaluator` and evaluate the target predicate against the facts.
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
evaluator = RuleTreeEvaluator(contract_rules)
|
|
130
|
+
|
|
131
|
+
# Evaluate Case 1
|
|
132
|
+
result_1 = evaluator.evaluate(facts_case_1, "contract_voidable")
|
|
133
|
+
print(f"Case 1 (Luxury Item): Is contract voidable? {result_1}")
|
|
134
|
+
# Output: Case 1 (Luxury Item): Is contract voidable? True
|
|
135
|
+
|
|
136
|
+
# Evaluate Case 2
|
|
137
|
+
result_2 = evaluator.evaluate(facts_case_2, "contract_voidable")
|
|
138
|
+
print(f"Case 2 (Necessities): Is contract voidable? {result_2}")
|
|
139
|
+
# Output: Case 2 (Necessities): Is contract voidable? False
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Documentation
|
|
143
|
+
|
|
144
|
+
For more detailed information, please see the `docs` directory:
|
|
145
|
+
|
|
146
|
+
- **[Getting Started](./docs/getting_started.md)**: A full tutorial on using PYTHEN.
|
|
147
|
+
- **[API Reference](./docs/api_reference.md)**: Detailed documentation for the `RuleTreeEvaluator` class and utility functions.
|
|
148
|
+
- **[Rule Syntax](./docs/rule_syntax.md)**: A complete guide to the JSON rule format.
|
|
149
|
+
- **[Philosophy](./docs/philosophy.md)**: A deeper dive into the design principles behind PYTHEN.
|
|
150
|
+
|
|
151
|
+
## Examples
|
|
152
|
+
|
|
153
|
+
This repository includes several end-to-end examples in the `examples/` directory:
|
|
154
|
+
|
|
155
|
+
- **[GDPR Article 17 (Right to Erasure)](./examples/gdpr_article17.py)**: A comprehensive model of the "Right to be Forgotten," demonstrating how to handle multiple conditions and exceptions in a real-world regulation.
|
|
156
|
+
- **[Contract Law (Voidable Contracts)](./examples/contract_law.py)**: A model of the conditions that make a contract voidable, such as lack of capacity or duress.
|
|
157
|
+
|
|
158
|
+
To run the examples:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
python3 examples/gdpr_article17.py
|
|
162
|
+
python3 examples/contract_law.py
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
Contributions are welcome! Whether you're a developer, a legal scholar, or a student, you can help improve PYTHEN. Please see our [Contributing Guidelines](./CONTRIBUTING.md) for more details on how to get started.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
PYTHEN is licensed under the [MIT License](./LICENSE).
|
|
172
|
+
|
|
173
|
+
## Citing PYTHEN
|
|
174
|
+
|
|
175
|
+
If you use PYTHEN in your research, please cite our work. (BibTeX entry to be provided upon publication).
|
|
176
|
+
|
pythen-0.1.0/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# PYTHEN: A Flexible Framework for Legal Reasoning in Python
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.python.org/)
|
|
5
|
+
|
|
6
|
+
**PYTHEN** is a Python-native framework for defeasible legal reasoning. It provides an intuitive, human-readable way to model complex legal rules, conditions, and exceptions, making formal legal reasoning accessible to developers, legal professionals, and researchers without extensive logic programming expertise.
|
|
7
|
+
|
|
8
|
+
Inspired by **PROLEG** (PROlog-based LEGal reasoning support system) and guided by the philosophy of **The Zen of Python**, PYTHEN bridges the gap between powerful symbolic reasoning systems and the practical, ubiquitous Python ecosystem.
|
|
9
|
+
|
|
10
|
+
## Key Features
|
|
11
|
+
|
|
12
|
+
- **Simple & Readable Syntax**: Rules are defined in a clean JSON format that is easy to read and write.
|
|
13
|
+
- **Python-Native Philosophy**: The design is inspired by The Zen of Python, emphasizing simplicity, readability, and practicality. The `ALL` and `ANY` operators directly mirror Python's built-in `all()` and `any()` functions.
|
|
14
|
+
- **Defeasible Reasoning**: Explicitly model exceptions to rules, a core feature of legal reasoning.
|
|
15
|
+
- **Accessible**: Designed for developers, legal scholars, and students who are comfortable with Python but may not be experts in Prolog or formal logic.
|
|
16
|
+
- **LLM-Friendly**: The structured JSON format makes PYTHEN an ideal target for autoformalization pipelines, where Large Language Models (LLMs) translate natural language legal text into executable rules.
|
|
17
|
+
- **Explainable AI (XAI)**: Generate clear, step-by-step explanations of the reasoning process for transparency and debugging.
|
|
18
|
+
- **Zero Dependencies**: The core evaluator is written in pure Python with no external dependencies.
|
|
19
|
+
|
|
20
|
+
## Philosophy: The Zen of Python in Legal Tech
|
|
21
|
+
|
|
22
|
+
PYTHEN's design is deeply influenced by The Zen of Python (PEP 20). We believe these principles are especially relevant for legal technology:
|
|
23
|
+
|
|
24
|
+
> - **Beautiful is better than ugly.** Legal rules should be represented cleanly.
|
|
25
|
+
> - **Explicit is better than implicit.** Exceptions and conditions are stated clearly in each rule.
|
|
26
|
+
> - **Simple is better than complex.** No need to learn a complex new syntax if you already know Python and JSON.
|
|
27
|
+
> - **Readability counts.** A legal rule base should be understandable by lawyers, not just programmers.
|
|
28
|
+
|
|
29
|
+
By adhering to these principles, PYTHEN aims to make computational law more accessible, transparent, and maintainable.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
**From PyPI (Recommended):**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install pythen
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**For Development:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/nguyenthanhasia/pythen.git
|
|
43
|
+
cd pythen
|
|
44
|
+
pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quickstart: 30-Second Example
|
|
48
|
+
|
|
49
|
+
Let's model a simple rule: "A contract is voidable if the party was a minor, UNLESS the contract was for necessities."
|
|
50
|
+
|
|
51
|
+
**1. Define the Rules**
|
|
52
|
+
|
|
53
|
+
Create a list of rule dictionaries. The `op` can be `ANY` (like Python's `any()`) or `ALL` (like `all()`).
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from pythen import RuleTreeEvaluator
|
|
57
|
+
|
|
58
|
+
# Define the rule set
|
|
59
|
+
contract_rules = [
|
|
60
|
+
{
|
|
61
|
+
"p": "contract_voidable",
|
|
62
|
+
"op": "ANY",
|
|
63
|
+
"conditions": ["party_is_minor"],
|
|
64
|
+
"exceptions": ["contract_for_necessities"]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"p": "party_is_minor",
|
|
68
|
+
"op": "ALL",
|
|
69
|
+
"conditions": ["party_age_below_18"],
|
|
70
|
+
"exceptions": []
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**2. Define the Facts**
|
|
76
|
+
|
|
77
|
+
Create a list of facts for a specific case.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
# Case 1: A 16-year-old buys a luxury item
|
|
81
|
+
facts_case_1 = ["party_age_below_18"]
|
|
82
|
+
|
|
83
|
+
# Case 2: A 17-year-old buys food (a necessity)
|
|
84
|
+
facts_case_2 = ["party_age_below_18", "contract_for_necessities"]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**3. Evaluate**
|
|
88
|
+
|
|
89
|
+
Instantiate the `RuleTreeEvaluator` and evaluate the target predicate against the facts.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
evaluator = RuleTreeEvaluator(contract_rules)
|
|
93
|
+
|
|
94
|
+
# Evaluate Case 1
|
|
95
|
+
result_1 = evaluator.evaluate(facts_case_1, "contract_voidable")
|
|
96
|
+
print(f"Case 1 (Luxury Item): Is contract voidable? {result_1}")
|
|
97
|
+
# Output: Case 1 (Luxury Item): Is contract voidable? True
|
|
98
|
+
|
|
99
|
+
# Evaluate Case 2
|
|
100
|
+
result_2 = evaluator.evaluate(facts_case_2, "contract_voidable")
|
|
101
|
+
print(f"Case 2 (Necessities): Is contract voidable? {result_2}")
|
|
102
|
+
# Output: Case 2 (Necessities): Is contract voidable? False
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Documentation
|
|
106
|
+
|
|
107
|
+
For more detailed information, please see the `docs` directory:
|
|
108
|
+
|
|
109
|
+
- **[Getting Started](./docs/getting_started.md)**: A full tutorial on using PYTHEN.
|
|
110
|
+
- **[API Reference](./docs/api_reference.md)**: Detailed documentation for the `RuleTreeEvaluator` class and utility functions.
|
|
111
|
+
- **[Rule Syntax](./docs/rule_syntax.md)**: A complete guide to the JSON rule format.
|
|
112
|
+
- **[Philosophy](./docs/philosophy.md)**: A deeper dive into the design principles behind PYTHEN.
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
This repository includes several end-to-end examples in the `examples/` directory:
|
|
117
|
+
|
|
118
|
+
- **[GDPR Article 17 (Right to Erasure)](./examples/gdpr_article17.py)**: A comprehensive model of the "Right to be Forgotten," demonstrating how to handle multiple conditions and exceptions in a real-world regulation.
|
|
119
|
+
- **[Contract Law (Voidable Contracts)](./examples/contract_law.py)**: A model of the conditions that make a contract voidable, such as lack of capacity or duress.
|
|
120
|
+
|
|
121
|
+
To run the examples:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python3 examples/gdpr_article17.py
|
|
125
|
+
python3 examples/contract_law.py
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Contributions are welcome! Whether you're a developer, a legal scholar, or a student, you can help improve PYTHEN. Please see our [Contributing Guidelines](./CONTRIBUTING.md) for more details on how to get started.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
PYTHEN is licensed under the [MIT License](./LICENSE).
|
|
135
|
+
|
|
136
|
+
## Citing PYTHEN
|
|
137
|
+
|
|
138
|
+
If you use PYTHEN in your research, please cite our work. (BibTeX entry to be provided upon publication).
|
|
139
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PYTHEN Documentation
|
|
3
|
+
|
|
4
|
+
This directory contains comprehensive documentation for the PYTHEN framework:
|
|
5
|
+
|
|
6
|
+
- getting_started.md: A beginner's guide to using PYTHEN
|
|
7
|
+
- api_reference.md: Detailed API documentation
|
|
8
|
+
- rule_syntax.md: Complete guide to the rule syntax
|
|
9
|
+
- philosophy.md: The design philosophy behind PYTHEN
|
|
10
|
+
"""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PYTHEN Examples
|
|
3
|
+
|
|
4
|
+
This package contains end-to-end examples demonstrating PYTHEN's application
|
|
5
|
+
to various legal domains:
|
|
6
|
+
|
|
7
|
+
- gdpr_article17: GDPR Article 17 - Right to Erasure
|
|
8
|
+
- contract_law: Contract Law - Voidable Contracts
|
|
9
|
+
|
|
10
|
+
Each example includes realistic scenarios and demonstrates how to:
|
|
11
|
+
1. Define legal rules with conditions and exceptions
|
|
12
|
+
2. Evaluate rules against facts
|
|
13
|
+
3. Trace and explain evaluation results
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from . import gdpr_article17
|
|
17
|
+
from . import contract_law
|
|
18
|
+
|
|
19
|
+
__all__ = ["gdpr_article17", "contract_law"]
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Contract Law Example - Voidable Contracts
|
|
3
|
+
|
|
4
|
+
This example demonstrates PYTHEN's application to contract law,
|
|
5
|
+
specifically determining when a contract is voidable.
|
|
6
|
+
|
|
7
|
+
This shows how PYTHEN can model complex legal doctrines with
|
|
8
|
+
multiple conditions and exceptions.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from pythen import RuleTreeEvaluator, print_rules
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Define the rule set for voidable contracts
|
|
15
|
+
VOIDABLE_CONTRACT_RULES = [
|
|
16
|
+
{
|
|
17
|
+
"p": "contract_voidable",
|
|
18
|
+
"op": "ANY",
|
|
19
|
+
"conditions": [
|
|
20
|
+
"party_lacks_capacity",
|
|
21
|
+
"contract_induced_by_fraud",
|
|
22
|
+
"contract_induced_by_duress",
|
|
23
|
+
"contract_induced_by_undue_influence",
|
|
24
|
+
"contract_induced_by_misrepresentation"
|
|
25
|
+
],
|
|
26
|
+
"exceptions": [
|
|
27
|
+
"contract_for_necessities",
|
|
28
|
+
"contract_ratified",
|
|
29
|
+
"contract_performed",
|
|
30
|
+
"party_waived_right"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"p": "party_lacks_capacity",
|
|
35
|
+
"op": "ANY",
|
|
36
|
+
"conditions": [
|
|
37
|
+
"party_is_minor",
|
|
38
|
+
"party_is_mentally_incapacitated",
|
|
39
|
+
"party_is_intoxicated"
|
|
40
|
+
],
|
|
41
|
+
"exceptions": []
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"p": "party_is_minor",
|
|
45
|
+
"op": "ALL",
|
|
46
|
+
"conditions": ["party_age_below_18"],
|
|
47
|
+
"exceptions": []
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"p": "party_is_mentally_incapacitated",
|
|
51
|
+
"op": "ALL",
|
|
52
|
+
"conditions": ["party_lacks_mental_capacity"],
|
|
53
|
+
"exceptions": []
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"p": "contract_induced_by_fraud",
|
|
57
|
+
"op": "ALL",
|
|
58
|
+
"conditions": [
|
|
59
|
+
"false_statement_made",
|
|
60
|
+
"statement_material",
|
|
61
|
+
"party_relied_on_statement",
|
|
62
|
+
"party_suffered_damage"
|
|
63
|
+
],
|
|
64
|
+
"exceptions": []
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"p": "contract_induced_by_duress",
|
|
68
|
+
"op": "ALL",
|
|
69
|
+
"conditions": [
|
|
70
|
+
"threat_made",
|
|
71
|
+
"threat_unlawful",
|
|
72
|
+
"threat_induced_contract"
|
|
73
|
+
],
|
|
74
|
+
"exceptions": []
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"p": "contract_induced_by_undue_influence",
|
|
78
|
+
"op": "ALL",
|
|
79
|
+
"conditions": [
|
|
80
|
+
"relationship_of_trust",
|
|
81
|
+
"excessive_pressure_applied",
|
|
82
|
+
"party_did_not_act_freely"
|
|
83
|
+
],
|
|
84
|
+
"exceptions": []
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"p": "contract_induced_by_misrepresentation",
|
|
88
|
+
"op": "ALL",
|
|
89
|
+
"conditions": [
|
|
90
|
+
"false_representation_made",
|
|
91
|
+
"representation_material",
|
|
92
|
+
"party_relied_on_representation"
|
|
93
|
+
],
|
|
94
|
+
"exceptions": []
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"p": "contract_for_necessities",
|
|
98
|
+
"op": "ALL",
|
|
99
|
+
"conditions": ["goods_are_necessities"],
|
|
100
|
+
"exceptions": []
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def example_1_minor_contract():
|
|
106
|
+
"""
|
|
107
|
+
Example 1: Contract with a minor
|
|
108
|
+
|
|
109
|
+
Scenario: A 16-year-old purchases a video game console.
|
|
110
|
+
The contract is voidable because the party is a minor.
|
|
111
|
+
However, if the goods are necessities, the contract may be enforceable.
|
|
112
|
+
"""
|
|
113
|
+
print("\n" + "="*70)
|
|
114
|
+
print("EXAMPLE 1: Contract with a Minor")
|
|
115
|
+
print("="*70)
|
|
116
|
+
|
|
117
|
+
print("\nScenario A: Non-necessity goods (video game console)")
|
|
118
|
+
facts_a = ["party_age_below_18"]
|
|
119
|
+
|
|
120
|
+
evaluator = RuleTreeEvaluator(VOIDABLE_CONTRACT_RULES, enable_trace=True)
|
|
121
|
+
result_a = evaluator.evaluate(facts_a, "contract_voidable")
|
|
122
|
+
|
|
123
|
+
print(f"Facts: {facts_a}")
|
|
124
|
+
print(f"Is contract voidable? {result_a}")
|
|
125
|
+
|
|
126
|
+
print("\n" + "-"*70)
|
|
127
|
+
print("\nScenario B: Necessity goods (food, clothing)")
|
|
128
|
+
facts_b = ["party_age_below_18", "goods_are_necessities"]
|
|
129
|
+
|
|
130
|
+
result_b = evaluator.evaluate(facts_b, "contract_voidable")
|
|
131
|
+
|
|
132
|
+
print(f"Facts: {facts_b}")
|
|
133
|
+
print(f"Is contract voidable? {result_b}")
|
|
134
|
+
print("\nExplanation:")
|
|
135
|
+
print(evaluator.explain(facts_b, "contract_voidable"))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def example_2_fraud():
|
|
139
|
+
"""
|
|
140
|
+
Example 2: Contract induced by fraud
|
|
141
|
+
|
|
142
|
+
Scenario: A seller misrepresents the condition of a car.
|
|
143
|
+
The buyer discovers the fraud and seeks to void the contract.
|
|
144
|
+
"""
|
|
145
|
+
print("\n" + "="*70)
|
|
146
|
+
print("EXAMPLE 2: Contract Induced by Fraud")
|
|
147
|
+
print("="*70)
|
|
148
|
+
|
|
149
|
+
facts = [
|
|
150
|
+
"false_statement_made",
|
|
151
|
+
"statement_material",
|
|
152
|
+
"party_relied_on_statement",
|
|
153
|
+
"party_suffered_damage"
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
evaluator = RuleTreeEvaluator(VOIDABLE_CONTRACT_RULES, enable_trace=True)
|
|
157
|
+
result = evaluator.evaluate(facts, "contract_voidable")
|
|
158
|
+
|
|
159
|
+
print(f"\nFacts: {facts}")
|
|
160
|
+
print(f"Is contract voidable? {result}")
|
|
161
|
+
print("\nExplanation:")
|
|
162
|
+
print(evaluator.explain(facts, "contract_voidable"))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def example_3_duress():
|
|
166
|
+
"""
|
|
167
|
+
Example 3: Contract induced by duress
|
|
168
|
+
|
|
169
|
+
Scenario: A person is threatened with violence unless they sign a contract.
|
|
170
|
+
The contract is voidable due to duress.
|
|
171
|
+
"""
|
|
172
|
+
print("\n" + "="*70)
|
|
173
|
+
print("EXAMPLE 3: Contract Induced by Duress")
|
|
174
|
+
print("="*70)
|
|
175
|
+
|
|
176
|
+
facts = [
|
|
177
|
+
"threat_made",
|
|
178
|
+
"threat_unlawful",
|
|
179
|
+
"threat_induced_contract"
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
evaluator = RuleTreeEvaluator(VOIDABLE_CONTRACT_RULES, enable_trace=True)
|
|
183
|
+
result = evaluator.evaluate(facts, "contract_voidable")
|
|
184
|
+
|
|
185
|
+
print(f"\nFacts: {facts}")
|
|
186
|
+
print(f"Is contract voidable? {result}")
|
|
187
|
+
print("\nExplanation:")
|
|
188
|
+
print(evaluator.explain(facts, "contract_voidable"))
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def example_4_ratification():
|
|
192
|
+
"""
|
|
193
|
+
Example 4: Contract with ratification
|
|
194
|
+
|
|
195
|
+
Scenario: A minor enters into a contract, but later ratifies it
|
|
196
|
+
(affirms it after reaching majority). The contract is no longer voidable.
|
|
197
|
+
"""
|
|
198
|
+
print("\n" + "="*70)
|
|
199
|
+
print("EXAMPLE 4: Contract Ratification")
|
|
200
|
+
print("="*70)
|
|
201
|
+
|
|
202
|
+
facts = [
|
|
203
|
+
"party_age_below_18",
|
|
204
|
+
"contract_ratified" # Exception: contract has been ratified
|
|
205
|
+
]
|
|
206
|
+
|
|
207
|
+
evaluator = RuleTreeEvaluator(VOIDABLE_CONTRACT_RULES, enable_trace=True)
|
|
208
|
+
result = evaluator.evaluate(facts, "contract_voidable")
|
|
209
|
+
|
|
210
|
+
print(f"\nFacts: {facts}")
|
|
211
|
+
print(f"Is contract voidable? {result}")
|
|
212
|
+
print("\nExplanation:")
|
|
213
|
+
print(evaluator.explain(facts, "contract_voidable"))
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def example_5_mental_incapacity():
|
|
217
|
+
"""
|
|
218
|
+
Example 5: Contract with mentally incapacitated party
|
|
219
|
+
|
|
220
|
+
Scenario: A person with dementia signs a contract.
|
|
221
|
+
The contract is voidable due to lack of mental capacity.
|
|
222
|
+
"""
|
|
223
|
+
print("\n" + "="*70)
|
|
224
|
+
print("EXAMPLE 5: Mental Incapacity")
|
|
225
|
+
print("="*70)
|
|
226
|
+
|
|
227
|
+
facts = [
|
|
228
|
+
"party_lacks_mental_capacity"
|
|
229
|
+
]
|
|
230
|
+
|
|
231
|
+
evaluator = RuleTreeEvaluator(VOIDABLE_CONTRACT_RULES, enable_trace=True)
|
|
232
|
+
result = evaluator.evaluate(facts, "contract_voidable")
|
|
233
|
+
|
|
234
|
+
print(f"\nFacts: {facts}")
|
|
235
|
+
print(f"Is contract voidable? {result}")
|
|
236
|
+
print("\nExplanation:")
|
|
237
|
+
print(evaluator.explain(facts, "contract_voidable"))
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def main():
|
|
241
|
+
"""Run all examples."""
|
|
242
|
+
print("\n" + "="*70)
|
|
243
|
+
print("PYTHEN: Contract Law - Voidable Contracts Examples")
|
|
244
|
+
print("="*70)
|
|
245
|
+
|
|
246
|
+
# Print the rule set
|
|
247
|
+
print_rules(VOIDABLE_CONTRACT_RULES)
|
|
248
|
+
|
|
249
|
+
# Run examples
|
|
250
|
+
example_1_minor_contract()
|
|
251
|
+
example_2_fraud()
|
|
252
|
+
example_3_duress()
|
|
253
|
+
example_4_ratification()
|
|
254
|
+
example_5_mental_incapacity()
|
|
255
|
+
|
|
256
|
+
print("\n" + "="*70)
|
|
257
|
+
print("Examples completed!")
|
|
258
|
+
print("="*70 + "\n")
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
main()
|