Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,6 +141,62 @@ SEV = {
|
|
| 141 |
(7,"HIGH"):"HIGH", (7,"MEDIUM"):"MEDIUM", (7,"LOW"):"LOW",
|
| 142 |
}
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
# NEW (Phase 5): maps each structural pattern to the closest existing
|
| 145 |
# `pred` class id. This is what lets a structural override also correct
|
| 146 |
# maqasid_enrichment (Phase 2) and jurisdiction_overlay (Phase 3) below —
|
|
@@ -767,6 +823,17 @@ def classify(text: str, context: str = "general",
|
|
| 767 |
compliant_alternative = altmap["primary"]
|
| 768 |
structural_fix = altmap["structural_fix"]
|
| 769 |
aaoifi_standard = altmap["aaoifi_standard"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
if reconciliation["source"] == "structural_override":
|
| 771 |
aaoifi_standard = top["aaoifi_standard"]
|
| 772 |
structural_fix = top["explanation"]
|
|
|
|
| 141 |
(7,"HIGH"):"HIGH", (7,"MEDIUM"):"MEDIUM", (7,"LOW"):"LOW",
|
| 142 |
}
|
| 143 |
|
| 144 |
+
# NEW (Phase 6): the generic Gharar citation in ALTERNATIVE_MAP[2] was
|
| 145 |
+
# hardcoded to always cite AAOIFI SS26 (Takaful) / SS10 (Salam) — found,
|
| 146 |
+
# via direct review of real Murabaha documents, to be actively confusing
|
| 147 |
+
# on the single most common contract type MACI is used against: citing
|
| 148 |
+
# Takaful (insurance) and Salam (forward-delivery sale) standards on a
|
| 149 |
+
# Murabaha contract's Gharar flag doesn't map to anything actually in
|
| 150 |
+
# the document. This does simple keyword-based contract-type detection
|
| 151 |
+
# and picks the AAOIFI standard that's actually contextually relevant,
|
| 152 |
+
# defaulting to Murabaha (SS8) — the most common case, and the standard
|
| 153 |
+
# the structural layer already cites for the same document type — rather
|
| 154 |
+
# than defaulting to Takaful, which was a poor default to begin with.
|
| 155 |
+
GHARAR_CITATION_BY_CONTRACT_TYPE = {
|
| 156 |
+
"murabaha": {
|
| 157 |
+
"aaoifi_standard": "AAOIFI Shari'a Standard No. 8 (Murabaha), \u00a72/2 \u2014 price, subject matter, and delivery terms must be clearly specified",
|
| 158 |
+
"structural_fix": "Specify subject matter, price, delivery date, and quality within the Murabaha agreement itself \u2014 ambiguity here is what AAOIFI SS8 \u00a72/2 requires be removed.",
|
| 159 |
+
},
|
| 160 |
+
"tawarruq": {
|
| 161 |
+
"aaoifi_standard": "AAOIFI Shari'a Standard No. 30 (Monetisation / Tawarruq) \u2014 subject matter and pricing must be clearly specified and free of ambiguity",
|
| 162 |
+
"structural_fix": "Specify the underlying commodity, price, and settlement terms within the Tawarruq arrangement itself.",
|
| 163 |
+
},
|
| 164 |
+
"salam": {
|
| 165 |
+
"aaoifi_standard": "AAOIFI Shari'a Standard No. 10 (Salam and Parallel Salam)",
|
| 166 |
+
"structural_fix": "Specify subject matter, quantity, quality, and delivery date at contract formation, as required for a valid Salam sale.",
|
| 167 |
+
},
|
| 168 |
+
"takaful": {
|
| 169 |
+
"aaoifi_standard": "AAOIFI Shari'a Standard No. 26 (Takaful)",
|
| 170 |
+
"structural_fix": "Specify the risk being covered, contribution basis, and surplus-distribution terms within the Takaful policy itself.",
|
| 171 |
+
},
|
| 172 |
+
"ijara": {
|
| 173 |
+
"aaoifi_standard": "AAOIFI Shari'a Standard No. 9 (Ijarah and Ijarah Muntahia Bittamleek)",
|
| 174 |
+
"structural_fix": "Specify the leased asset, rental terms, and maintenance responsibility within the Ijara agreement itself.",
|
| 175 |
+
},
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
def detect_contract_type(text: str) -> str:
|
| 179 |
+
"""
|
| 180 |
+
Simple keyword-based contract-type detection, English + Arabic,
|
| 181 |
+
used only to pick a contextually-relevant Gharar citation. Not a
|
| 182 |
+
claim of deep semantic contract understanding — a document that
|
| 183 |
+
never names its own contract type falls back to Murabaha, the most
|
| 184 |
+
common case in current usage and the type the structural layer is
|
| 185 |
+
most built around, rather than an arbitrary unrelated default.
|
| 186 |
+
"""
|
| 187 |
+
t = text.lower()
|
| 188 |
+
if "tawarruq" in t or "توارق" in text:
|
| 189 |
+
return "tawarruq"
|
| 190 |
+
if "salam" in t or "سلم" in text:
|
| 191 |
+
return "salam"
|
| 192 |
+
if "takaful" in t or "تكافل" in text:
|
| 193 |
+
return "takaful"
|
| 194 |
+
if "ijara" in t or "ijarah" in t or "إجارة" in text:
|
| 195 |
+
return "ijara"
|
| 196 |
+
if "murabaha" in t or "مرابحة" in text:
|
| 197 |
+
return "murabaha"
|
| 198 |
+
return "murabaha"
|
| 199 |
+
|
| 200 |
# NEW (Phase 5): maps each structural pattern to the closest existing
|
| 201 |
# `pred` class id. This is what lets a structural override also correct
|
| 202 |
# maqasid_enrichment (Phase 2) and jurisdiction_overlay (Phase 3) below —
|
|
|
|
| 823 |
compliant_alternative = altmap["primary"]
|
| 824 |
structural_fix = altmap["structural_fix"]
|
| 825 |
aaoifi_standard = altmap["aaoifi_standard"]
|
| 826 |
+
|
| 827 |
+
# NEW (Phase 6): for a generic (non-structural, non-hard-negative)
|
| 828 |
+
# Gharar flag, replace the old hardcoded Takaful/Salam citation with
|
| 829 |
+
# one chosen by detected contract type — see
|
| 830 |
+
# GHARAR_CITATION_BY_CONTRACT_TYPE above for why this changed.
|
| 831 |
+
if pred == 2 and reconciliation["source"] not in ("structural_override", "hard_negative_downgrade"):
|
| 832 |
+
contract_type = detect_contract_type(text)
|
| 833 |
+
citation = GHARAR_CITATION_BY_CONTRACT_TYPE[contract_type]
|
| 834 |
+
aaoifi_standard = citation["aaoifi_standard"]
|
| 835 |
+
structural_fix = citation["structural_fix"]
|
| 836 |
+
|
| 837 |
if reconciliation["source"] == "structural_override":
|
| 838 |
aaoifi_standard = top["aaoifi_standard"]
|
| 839 |
structural_fix = top["explanation"]
|