Spaces:
Running
Running
Upload report_flags.py
Browse files- report_flags.py +8 -2
report_flags.py
CHANGED
|
@@ -156,7 +156,7 @@ def read_score(text):
|
|
| 156 |
"""(percent, kind, tool) read from the report's first pages, e.g. (23.0, 'AI', 'Turnitin').
|
| 157 |
kind is 'AI' or 'Similarity'; percent is None if no score could be found."""
|
| 158 |
low = (text or "").lower()
|
| 159 |
-
tool = next((name for key, name in _TOOLS if key in low), "
|
| 160 |
best = None # (priority, position, pct, kind)
|
| 161 |
for m in _PCT.finditer(low):
|
| 162 |
pct = float(m.group(1))
|
|
@@ -185,6 +185,9 @@ def read_score(text):
|
|
| 185 |
return best[2], best[3], tool
|
| 186 |
|
| 187 |
|
|
|
|
|
|
|
|
|
|
| 188 |
def estimate_after(score, pairs):
|
| 189 |
"""Estimated report score after rewriting. pairs = [(original flagged sentence, final sentence)].
|
| 190 |
The report's score comes from its flagged text; each flagged sentence keeps the share of its wording that is
|
|
@@ -196,7 +199,10 @@ def estimate_after(score, pairs):
|
|
| 196 |
for o, n in pairs:
|
| 197 |
w = max(1, len(o.split()))
|
| 198 |
tot += w
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
| 200 |
return round(score * kept / tot, 1) if tot else score
|
| 201 |
|
| 202 |
|
|
|
|
| 156 |
"""(percent, kind, tool) read from the report's first pages, e.g. (23.0, 'AI', 'Turnitin').
|
| 157 |
kind is 'AI' or 'Similarity'; percent is None if no score could be found."""
|
| 158 |
low = (text or "").lower()
|
| 159 |
+
tool = next((name for key, name in _TOOLS if key in low), "Report")
|
| 160 |
best = None # (priority, position, pct, kind)
|
| 161 |
for m in _PCT.finditer(low):
|
| 162 |
pct = float(m.group(1))
|
|
|
|
| 185 |
return best[2], best[3], tool
|
| 186 |
|
| 187 |
|
| 188 |
+
KEEP_OVERLAP = 0.5 # wording overlap at/above which a flagged sentence is assumed to stay flagged
|
| 189 |
+
|
| 190 |
+
|
| 191 |
def estimate_after(score, pairs):
|
| 192 |
"""Estimated report score after rewriting. pairs = [(original flagged sentence, final sentence)].
|
| 193 |
The report's score comes from its flagged text; each flagged sentence keeps the share of its wording that is
|
|
|
|
| 199 |
for o, n in pairs:
|
| 200 |
w = max(1, len(o.split()))
|
| 201 |
tot += w
|
| 202 |
+
# detectors also flag lightly reworded (AI-paraphrased) text: a sentence only starts to count as cleared
|
| 203 |
+
# once more than half of its wording has changed (overlap below 50%), reaching zero at 0% overlap
|
| 204 |
+
ov = 1.0 if n.strip() == o.strip() else similarity_to_source(o, n) / 100.0
|
| 205 |
+
kept += w * min(1.0, ov / KEEP_OVERLAP)
|
| 206 |
return round(score * kept / tot, 1) if tot else score
|
| 207 |
|
| 208 |
|