Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1847,7 +1847,10 @@ def rewrite_residual_list_comma(sent, coordinator="and"):
|
|
| 1847 |
"""
|
| 1848 |
Last list-separator comma → same conjunction as the split sign,
|
| 1849 |
so the next pass sees CMN1/CMV1/CCV more reliably (not SSMN).
|
| 1850 |
-
Skips
|
|
|
|
|
|
|
|
|
|
| 1851 |
"""
|
| 1852 |
if not sent or not coordinator:
|
| 1853 |
return sent
|
|
@@ -1856,12 +1859,21 @@ def rewrite_residual_list_comma(sent, coordinator="and"):
|
|
| 1856 |
return sent
|
| 1857 |
|
| 1858 |
s = sent.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1859 |
m = re.search(r",\s+(?!\d\b)([^,]+?)(\s*[.!?])?\s*$", s)
|
| 1860 |
if not m:
|
| 1861 |
return s
|
| 1862 |
|
| 1863 |
-
head = s[: m.start()].rstrip()
|
| 1864 |
tail = m.group(1).strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1865 |
punct = (m.group(2) or "").strip() or "."
|
| 1866 |
out = f"{head} {coord} {tail}{punct}"
|
| 1867 |
out = re.sub(r"\s+", " ", out).strip()
|
|
|
|
| 1847 |
"""
|
| 1848 |
Last list-separator comma → same conjunction as the split sign,
|
| 1849 |
so the next pass sees CMN1/CMV1/CCV more reliably (not SSMN).
|
| 1850 |
+
Skips:
|
| 1851 |
+
- comma before a bare number (Smith, 43)
|
| 1852 |
+
- a comma that already introduces a coordinator
|
| 1853 |
+
(", and" / ", or" / ", but") — copying would produce "and and"
|
| 1854 |
"""
|
| 1855 |
if not sent or not coordinator:
|
| 1856 |
return sent
|
|
|
|
| 1859 |
return sent
|
| 1860 |
|
| 1861 |
s = sent.strip()
|
| 1862 |
+
|
| 1863 |
+
# already a well-formed list: ", and X" must be left alone
|
| 1864 |
+
if re.search(r",\s+(?:and|or|but)\b", s, flags=re.I):
|
| 1865 |
+
return s
|
| 1866 |
+
|
| 1867 |
m = re.search(r",\s+(?!\d\b)([^,]+?)(\s*[.!?])?\s*$", s)
|
| 1868 |
if not m:
|
| 1869 |
return s
|
| 1870 |
|
|
|
|
| 1871 |
tail = m.group(1).strip()
|
| 1872 |
+
# tail itself starts with a coordinator — do not double it
|
| 1873 |
+
if re.match(r"(?:and|or|but)\b", tail, flags=re.I):
|
| 1874 |
+
return s
|
| 1875 |
+
|
| 1876 |
+
head = s[: m.start()].rstrip()
|
| 1877 |
punct = (m.group(2) or "").strip() or "."
|
| 1878 |
out = f"{head} {coord} {tail}{punct}"
|
| 1879 |
out = re.sub(r"\s+", " ", out).strip()
|