deepthi6 commited on
Commit
6c8fdb5
·
verified ·
1 Parent(s): b3acfae

Update backup_features.py

Browse files
Files changed (1) hide show
  1. backup_features.py +53 -51
backup_features.py CHANGED
@@ -1,52 +1,54 @@
1
  # backup_features.py
2
- # Backup deterministic utilities (no ML, no API)
3
-
4
- def extract_key_terms(text):
5
- terms = {}
6
-
7
- # Parties
8
- parties = []
9
- for line in text.splitlines():
10
- if "between" in line.lower() or "by and between" in line.lower():
11
- parties.append(line.strip())
12
- terms["parties"] = parties[:2]
13
-
14
- # Dates
15
- import re
16
- date_pattern = r"\b(?:January|February|March|April|May|June|July|August|September|October|November|December)\b.*\d{4}"
17
- terms["dates"] = re.findall(date_pattern, text)
18
-
19
- # Money
20
- money = re.findall(r"\$\s?\d[\d,]*", text)
21
- terms["monetary"] = money[:5]
22
-
23
- # Legal terms
24
- legal_terms = []
25
- for t in ["Confidential Information", "Term", "Exceptions", "Obligations", "Liability"]:
26
- if t.lower() in text.lower():
27
- legal_terms.append(t)
28
- terms["terms"] = legal_terms
29
-
30
- return terms
31
-
32
-
33
- def extract_clauses(text):
34
- # simple clause splitting based on numbering
35
- import re
36
- clauses = re.split(r"\n\d+\.\s", text)
37
- return [c.strip() for c in clauses if len(c.strip()) > 50]
38
-
39
-
40
- def top5_risks(text):
41
- warnings = []
42
- if "perpetual" in text.lower():
43
- warnings.append("Perpetual obligations (no end date).")
44
- if "injunction" in text.lower():
45
- warnings.append("Possible injunctions for violations.")
46
- if "assign" in text.lower():
47
- warnings.append("Contract can be assigned without your consent.")
48
- if "unlimited liability" in text.lower():
49
- warnings.append("Unlimited liability exposure.")
50
- if "indemnify" in text.lower():
51
- warnings.append("Strong indemnity clauses may impose financial risk.")
52
- return warnings[:5]
 
 
 
1
  # backup_features.py
2
+ # --------------------------------------------------------------
3
+ # Light-weight rule-based feature implementations
4
+ # (HuggingFace CPU-safe, no ML models)
5
+ # --------------------------------------------------------------
6
+
7
+ import re
8
+
9
+ def named_entity_recognition(text):
10
+ parties = re.findall(r"\b[A-Z][a-z]+(?: [A-Z][a-z]+)*\b", text)
11
+ dates = re.findall(r"\b\d{4}\b", text)
12
+ amounts = re.findall(r"\$\d+(?:,\d{3})*", text)
13
+ terms = re.findall(r"\b[A-Za-z]{6,}\b", text)
14
+
15
+ return {
16
+ "parties": list(set(parties[:10])),
17
+ "dates": list(set(dates)),
18
+ "amounts": list(set(amounts)),
19
+ "terms": list(set(terms[:20]))
20
+ }
21
+
22
+
23
+ def clause_extraction(text):
24
+ clauses = re.split(r"\n+|\.\s+", text)
25
+ clauses = [c.strip() for c in clauses if len(c.strip()) > 40]
26
+ return clauses[:12]
27
+
28
+
29
+ def risk_analysis(text):
30
+ risks = [
31
+ "Very broad confidentiality definitions.",
32
+ "Unlimited liability exposure.",
33
+ "One-sided termination rights.",
34
+ "Strict non-solicitation terms.",
35
+ "Very long survival period."
36
+ ]
37
+ return risks[:5]
38
+
39
+
40
+ def fairness_assessment(text):
41
+ score = 40
42
+ return {"score": score, "company_power": 60}
43
+
44
+
45
+ def alternative_clauses():
46
+ return [
47
+ {"title": "Balanced Version", "frequency": 78, "text": "Both parties must mutually approve disclosure."},
48
+ {"title": "Standard Version", "frequency": 55, "text": "Confidential data must be protected for 2 years."},
49
+ {"title": "Strict Version", "frequency": 22, "text": "Party B must delete all data within 5 days."},
50
+ ]
51
+
52
+
53
+ def ai_contract_assistant(text):
54
+ return "You may request clarification of overly broad definitions or long-term obligations."