File size: 1,222 Bytes
8397f09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re

# 1. Define clause types and keywords
clause_keywords = {
    "Termination": ["terminate", "termination", "cancel", "notice period"],
    "Indemnity": ["indemnify", "hold harmless", "liability", "defend"],
    "Jurisdiction": ["governed by", "laws of", "jurisdiction"],
    "Confidentiality": ["confidential", "non-disclosure", "NDA"],
    "Risky Terms": ["sole discretion", "no liability", "not responsible"]
}

# 2. Risk levels (simple mapping)
risk_levels = {
    "Termination": "Medium",
    "Indemnity": "High",
    "Jurisdiction": "Low",
    "Confidentiality": "Medium",
    "Risky Terms": "High"
}

# 3. Clause detection logic
def detect_clauses(text):
    sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    results = []

    for sentence in sentences:
        for clause_type, keywords in clause_keywords.items():
            if any(keyword.lower() in sentence.lower() for keyword in keywords):
                results.append({
                    "clause": sentence.strip(),
                    "type": clause_type,
                    "risk_level": risk_levels.get(clause_type, "Unknown")
                })
                break  # Stop after first match to avoid duplicates
    return results