Spaces:
Sleeping
Sleeping
File size: 1,148 Bytes
b324327 |
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 |
# agents/parse_agent.py
import re
def extract_clauses_from_text(text):
"""
Takes full legal text and returns a list of clauses based on patterns like 'شق 1:', 'شق 2:' etc.
"""
# Urdu pattern for شق
pattern = r"(شق[\s\d:]+)"
# Split using regex
parts = re.split(pattern, text)
# Rebuild clean clause blocks
clauses = []
for i in range(1, len(parts), 2):
heading = parts[i].strip()
body = parts[i + 1].strip() if (i + 1) < len(parts) else ""
full_clause = f"{heading} {body}".strip()
if len(full_clause) > 20:
clauses.append(full_clause)
return clauses
# Test this code separately
if __name__ == "__main__":
sample_text = """
شق 1: کرایہ دار کو ہر ماہ کی 5 تاریخ تک کرایہ ادا کرنا ہوگا۔
شق 2: مکان خالی کرنے کے لیے 30 دن کا نوٹس دینا لازمی ہے۔
شق 3: مالک مکان بغیر اطلاع کے کرایہ نہیں بڑھا سکتا۔
"""
extracted = extract_clauses_from_text(sample_text)
for c in extracted:
print("➡️", c)
|