summaryrefslogtreecommitdiff
path: root/src/en/en.dat
blob: 789a4052adea24867258a5256865cdcb8a7a0b3a (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# English sentence checking

# word-level rules (case-sensitive)

[word]

# basic syntax of the rules:
#
# pattern -> suggestion # warning message
# pattern <- condition -> suggestion # warning message
#

# duplicates

and and -> and # Did you mean:
or or -> or # Did you mean:
for for -> for # Did you mean:
the the -> the # Did you mean:

# word-level rules (case-insensitive)

[Word]

# multiword expressions

ying and yang -> yin and yang # Did you mean:

# multiple suggestions separated by "\n"

scot free -> scot-free\nscotfree # Did you mean:

# possessive pronouns

# Your's -> Yours
(your|her|our|their)['’]s -> \1s # Possessive pronoun: \n http://en.wikipedia.org/wiki/Possessive_pronoun

# a or an (rules for articles)#
###############################

[word]

# pattern "a" matches "a" or "A":
a [Aa]

# pattern "_" matches space and optional quotation marks:
_ [ ]['‘"“]?

# pattern "vow" matches words beginning with vowels:
vow [aeiouAEIOU]\w*

# pattern "con" matches words beginning with consonants:
con [bcdfghj-np-tv-zBCDFGHJ-NP-TV-Z]\w*

# pattern "etc" matches other word parts separated by hyphen, endash or apostrophes:
etc [-–'’\w]*

# rules ("aA", "aAN", "aB" sets are defined at the end of the file)

{a}n{_}{vow}{etc} <- {vow} in aA or {vow}.lower() in aA -> {a}{_}{vow}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

a{_}{vow}{etc} <- ({vow} != {vow}.upper()) and not ({vow} in aA or
	{vow}.lower() in aA) and spell({vow}) -> an{_}{vow}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

a{_}{con}{etc} <- {con} in aAN or {con}.lower() in aAN -> an{_}{con}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

{a}n{_}{con}{etc} <- ({con} != {con}.upper()) and not ({con} in aA or
	{con}.lower() in aAN) and not {con} in aB and spell({con}) -> {a}{_}{con}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

# rules for sentences beginning with "A"

^A{_}{vow}{etc} <- ({vow} != {vow}.upper()) and not ({vow} in aA or
	{vow}.lower() in aA) and spell({vow}) -> An{_}{vow}{etc} # Bad article? \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

^A{_}{con}{etc} <- {con} in aAN or {con}.lower() in aAN -> An{_}{con}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

# check numbers

nvow (8[0-9]*|1[18](000)*)(th)? # 8, 8th, 11, 11th, 18, 18th, 11000, 11000th...

a{_}{nvow}{etc} -> an{_}{nvow}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an
^A{_}{nvow}{etc} -> An{_}{nvow}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

ncon [0-79][0-9]*

{a}n{_}{ncon}{etc} <- not {ncon}[:2] in ["11", "18"] -> {a}{_}{ncon}{etc} # Did you mean: \n http://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an

# paragraph capitalization

[code]
# pattern matching for common English abbreviations
abbrev = re.compile("(?i)\b([a-z]|acct|approx|appt|apr|apt|assoc|asst|aug|ave|avg|co(nt|rp)?|ct|dec|defn|dept|dr|eg|equip|esp|est|etc|excl|ext|feb|fri|ft|govt?|hrs?|ib(id)?|ie|in(c|t)?|jan|jr|jul|lit|ln|mar|max|mi(n|sc)?|mon|Mrs?|mun|natl?|neg?|no(rm|s|v)?|nw|obj|oct|org|orig|pl|pos|prev|proj|psi|qty|rd|rec|rel|reqd?|resp|rev|sat|sci|se(p|pt)?|spec(if)?|sq|sr|st|subj|sun|sw|temp|thurs|tot|tues|univ|var|vs)\.")

# pattern for paragraph checking
paralcap = re.compile(u"(?u)^[a-z].*[.?!] [A-Z].*[.?!][)”]?$")

[word]

# condition: the paragraph begins with a lowercase letter and it contains real sentence boundaries.

low [a-z]+

(^){low} <- paralcap.search(TEXT) and not abbrev.search(TEXT) -> = {low}.capitalize() # Missing capitalization?

# optional sentence capitalization

^{low} <- option("cap") and not abbrev.search(TEXT) -> = {low}.capitalize() # Missing capitalization?

# punctuation

[code]

punct = { "?": "question mark", "!": "exclamation mark",
  ",": "comma", ":": "colon", ";": "semicolon",
  "(": "opening parenthesis", ")": "closing parenthesis",
  "[": "opening square bracket", "]": "closing square bracket",
  u"“": "opening quotation mark", u"”": "closing quotation mark"}

[char]

" ([.?!,:;)”\]])\b" -> "\1 " 	# Reversed space and punctuation?
" +[.]" <- LOCALE.Country == "US" -> . # Extra space before the period?
" +[.]" <- LOCALE.Country != "US" -> . # Extra space before the full stop?
" +([?!,:;)”\]])" -> \1	# = "Extra space before the " + punct[\1] + "?"
"([([“]) " -> \1	# = "Extra space after the " + punct[\1] + "?"

# ( item ) -> (item)
# A small - but important - example. -> A small – but important – example.

# En dash and em dash

\b(---?| --? )\b <- not option("ndash") and not option("mdash") -> " – \n—" # En dash or em dash:
\b(---?| --? |—)\b <- option("ndash") and not option("mdash") -> " – " # En dash:
\b(---?| --? | – )\b <- option("mdash") -> — # Em dash:

# multiplication sign

number \d+([.]\d+)?

{number}(x| x ){number} <- option("times") -> {number}×{number} # Multiplication sign. \n http://en.wikipedia.org/wiki/Multiplication_sign
# 800x600 -> 800×600

# missing space

abc [a-z]+
ABC [A-Z]+
Abc [a-zA-Z]+
pun [?!,:;%‰‱˚“”‘]

{Abc}{pun}{Abc} -> {Abc}{pun} {Abc}	# Missing space?
{abc}[.]{ABC} -> {abc}. {ABC}		# Missing space?
# missing,space -> missing, space
# missing.Space -> missing. Space

[)] <- option("pair") and not "(" in TEXT -> # Extra closing parenthesis?
[(] <- option("pair") and TEXT[-1] in u"?!;:”’" and not ")" in TEXT -> # Extra opening parenthesis?
(?<![0-9])” <- option("pair") and not u"“" in TEXT -> # Extra quotation mark?
(?<=[0-9])” <- option("apostrophe") and not u"“" in TEXT -> ″\n # Bad double prime or extra quotation mark?
“ <- option("pair") and TEXT[-1] in u"?!;:”’" and not u"”" in TEXT -> # Extra quotation mark?

"[.]{3}" <- option("ellipsis") -> "…"	# Ellipsis.

\b {2,3}(\b|$) <- option("spaces") -> "\1 " # Extra space.
# Extra  space -> Extra space
# End... -> End…

(^|\b|{pun}|[.]) {2,3}(\b|$) <- option("spaces2") -> "\1 " # Extra space.
# Extra  space -> Extra space
# End... -> End…

(^|\b|{pun}|[.]) {4,}(\b|$) <- option("spaces3") -> "\1 \n	" # Change multiple spaces to a single space or a tabulator:

# quotation

# Using typographic quotation marks is the

(?i)[\"“”‟„]({abc}[^\"“”‟„]*)[\"“‟] <- option("quotation") -> “\1” # Quotation marks.
(?i)[\"”‟„]({abc}[^\"“”‟„]*)[\"“”‟] <- option("quotation") -> “\1” # Quotation marks.

(?i)'{abc}' <- option("apostrophe") -> ‘{abc}’ # Quotation marks.
(?i)[\"”‟„]({abc}[^\"“”‟„]*)[\"“”‟] <- option("apostrophe") -> “\1” # Quotation marks.

# apostrophe

w \w*
(?i){Abc}'{w} <- option("apostrophe") -> {Abc}’{w}	# Replace typewriter apostrophe or quotation mark:
# o'clock -> o’clock
# singers' voices -> singers’ voices

(?<= )'{Abc} <- option("apostrophe") -> ‘{Abc}\n’{Abc} # Replace typewriter quotation mark or apostrophe:
^'{Abc} <- option("apostrophe") -> ‘{Abc}\n’{Abc} # Replace typewriter quotation mark or apostrophe:

# formats

# Thousand separators: 10000 -> 10,000  (common) or 10 000 (ISO standard)

# definitions
d	\d\d\d		# name definition: 3 digits
d2	\d\d		# 2 digits
D	\d{1,3}		# 1, 2 or 3 digits

# ISO thousand separators: space, here: narrow no-break space (U+202F)
\b{d2}{d}\b 	 <- option("numsep") -> {d2},{d}\n{d2} {d}			# Use thousand separator (common or ISO).
\b{D}{d}{d}\b 	 <- option("numsep") -> {D},{d},{d}\n{D} {d} {d}		# Use thousand separators (common or ISO).
\b{D}{d}{d}{d}\b <- option("numsep") -> {D},{d},{d},{d}\n{D} {d} {d} {d}	# Use thousand separators (common or ISO).
# 1234567890 -> 1,234,567,890\n1 234 567 890

# word duplication

[word]

{Abc} \1 <- option("dup") -> {Abc} # Word duplication?

# Optional grammar checking

([Tt])his {abc} <- option("grammar") and morph({abc}, "Ns") -> \1hese {abc}\n\1his, {abc} # Did you mean:

with it['’]s <- option("grammar") -> with its\nwith, it’s # Did you mean:

[Word]

(it|s?he) don['’]t <- option("grammar") -> \1 doesn’t # Did you mean:

################### measurements ##########################

[word]

# Temperature

([-−]?\d+(?:[,.]\d+)*) (°F|Fahrenheit) <- option("metric") -> = measurement(\1, "F", "C", u" °C", ".", ",") # Convert to Celsius:
([-−]?\d+(?:[,.]\d+)*) (°C|Celsius) <- option("nonmetric") -> = measurement(\1, "C", "F", u" °F", ".", ",") # Convert to Fahrenheit:

# Length

([-−]?\d+(?:[,.]\d+)*(?: 1/2| ?½)?) (ft|foot|feet)(?! [1-9]) <- option("metric") -> =
	measurement(\1, "ft", "cm", " cm", ".", ",") + "\n" +
	measurement(\1, "ft", "m", " m", ".", ",") # Convert to metric:

([-−]?\d+(?:[,.]\d+)*(?: 1/2| ?½)?) ft[.]? ([0-9]+(?: 1/2| ?½)?) in <- option("metric") -> =
	measurement(\1 + "*12+" + \2, "in", "cm", " cm", ".", ",") + "\n" +
	measurement(\1 + "*12+" + \2, "in", "m", " m", ".", ",") # Convert to metric:

([-−]?\d+(?:[,.]\d+)*(?: 1/2| ?½)?) in <- option("metric") -> =
	measurement(\1, "in", "mm", " mm", ".", ",") + "\n" +
	measurement(\1, "in", "cm", " cm", ".", ",") + "\n" +
	measurement(\1, "in", "m", " m", ".", ",") # Convert to metric:

([-−]?\d+(?:[,.]\d+)*) mm <- option("nonmetric") -> =
	measurement(\1, "mm", "in", " in", ".", ",") # Convert from metric:

([-−]?\d+(?:[,.]\d+)*) cm <- option("nonmetric") -> =
	measurement(\1, "cm", "in", " in", ".", ",") + "\n" +
	measurement(\1, "cm", "ft", " ft", ".", ",") # Convert from metric:

([-−]?\d+(?:[,.]\d+)*) (m|meter|metre) <- option("nonmetric") -> =
	measurement(\1, "m", "in", " in", ".", ",") + "\n" +
	measurement(\1, "m", "ft", " ft", ".", ",") + "\n" +
	measurement(\1, "m", "mi", " mi", ".", ",") # Convert from metric:

([-−]?\d+(?:[,.]\d+)*(?: 1/2| ?½)?) miles? <- option("metric") -> =
	measurement(\1, "mi", "m", " m", ".", ",") + "\n" +
	measurement(\1, "mi", "km", " km", ".", ",") # Convert to metric:

([-−]?\d+(?:[,.]\d+)*) km <- option("nonmetric") -> =
	measurement(\1, "km", "mi", " mi", ".", ",") # Convert to miles:

([-−]?\d+(?:,\d+)?) (yd|yards?) <- option("metric") -> = measurement(\1, "yd", "m", " m", ".", ",") # Convert to metric:

# Volume

([-−]?\d+(?:,\d+)?) (gal(lons?)?) <- option("metric") -> =
	measurement(\1, "gal", "l", " l", ".", ",") + "\n" + 
	measurement(\1, "uk_gal", "l", " l (in UK)", ".", ",") # Convert to metric:

([-−]?\d+(?:,\d+)?) (pint) <- option("metric") -> = 
	measurement(\1, "pt", "dl", " dl", ".", ",") + "\n" + 
	measurement(\1, "uk_pt", "dl", " dl (in UK)", ".", ",") + "\n" +
	measurement(\1, "pt", "l", " l", ".", ",") + "\n" + 
	measurement(\1, "uk_pt", "l", " l (in UK)", ".", ",") # Convert to metric:

([-−]?\d+(?:,\d+)?) (l|L|litres?|liters?) <- option("nonmetric") -> =
	measurement(\1, "l", "gal", " gal", ".", ",") + "\n" + 
	measurement(\1, "l", "gal", " gal (in UK)", ".", ",") # Convert to gallons:

# Weight

([-−]?\d+(?:[,.]\d+)*) lbs?[.]? <- option("metric") -> =
	measurement(\1, "lbm", "kg", " kg", ".", ",") # Convert to metric:
([-−]?\d+(?:[,.]\d+)*) kg[.]? <- option("nonmetric") -> =
	measurement(\1, "kg", "lbm", " lb", ".", ",") # Convert to pounds:

# Speed

([-−]?\d+(?:[,.]\d+)*) mph <- option("metric") -> = measurement(\1, "mph", "km/h", " km/h", ".", ",") # Convert to km/hour:
([-−]?\d+(?:[,.]\d+)*) km/h <- option("nonmetric") -> = measurement(\1, "km/h", "mph", " mph", ".", ",") # Convert to miles/hour:

[code]

aA = set(["eucalypti", "eucalyptus", "Eucharist", "Eucharistic",
"euchre", "euchred", "euchring", "Euclid", "euclidean", "Eudora",
"eugene", "Eugenia", "eugenic", "eugenically", "eugenicist",
"eugenicists", "eugenics", "Eugenio", "eukaryote", "Eula", "eulogies",
"eulogist", "eulogists", "eulogistic", "eulogized", "eulogizer",
"eulogizers", "eulogizing", "eulogy", "eulogies", "Eunice", "eunuch",
"eunuchs", "Euphemia", "euphemism", "euphemisms", "euphemist",
"euphemists", "euphemistic", "euphemistically", "euphonious",
"euphoniously", "euphonium", "euphony", "euphoria", "euphoric",
"Euphrates", "euphuism", "Eurasia", "Eurasian", "Eurasians", "eureka",
"eurekas", "eurhythmic", "eurhythmy", "Euridyce", "Euripides", "euripus",
"Euro", "Eurocentric", "Euroclydon", "Eurocommunism", "Eurocrat",
"eurodollar", "Eurodollar", "Eurodollars", "Euromarket", "Europa",
"Europe", "European", "Europeanisation", "Europeanise", "Europeanised",
"Europeanization", "Europeanize", "Europeanized", "Europeans", "europium",
"Eurovision", "Eustace", "Eustachian", "Eustacia", "euthanasia",
"Ewart", "ewe", "Ewell", "ewer", "ewers", "Ewing", "once", "one",
"oneness", "ones", "oneself", "onetime", "oneway", "oneyear", "u",
"U", "UART", "ubiquitous", "ubiquity", "Udale", "Udall", "UEFA",
"Uganda", "Ugandan", "ugric", "UK", "ukase", "Ukraine", "Ukrainian",
"Ukrainians", "ukulele", "Ula", "ululated", "ululation", "Ulysses",
"UN", "unanimity", "unanimous", "unanimously", "unary", "Unesco",
"UNESCO", "UNHCR", "uni", "unicameral", "unicameralism", "Unicef",
"UNICEF", "unicellular", "Unicode", "unicorn", "unicorns", "unicycle",
"unicyclist", "unicyclists", "unidimensional", "unidirectional",
"unidirectionality", "unifiable", "unification", "unified", "unifier",
"unifilar", "uniform", "uniformally", "uniformed", "uniformer",
"uniforming", "uniformisation", "uniformise", "uniformitarian",
"uniformitarianism", "uniformity", "uniformly", "uniformness", "uniforms",
"unify", "unifying", "unijugate", "unilateral", "unilateralisation",
"unilateralise", "unilateralism", "unilateralist", "unilaterally",
"unilinear", "unilingual", "uniliteral", "uniliteralism", "uniliteralist",
"unimodal", "union", "unionism", "unionist", "unionists", "unionisation",
"unionise", "unionised", "unionising", "unionization", "unionize",
"unionized", "unionizing", "unions", "unipolar", "uniprocessor",
"unique", "uniquely", "uniqueness", "uniquer", "Uniroyal", "unisex",
"unison", "Unisys", "unit", "Unitarian", "Unitarianism", "Unitarians",
"unitary", "unite", "united", "unitedly", "uniter", "unites", "uniting",
"unitize", "unitizing", "unitless", "units", "unity", "univ", "Univac",
"univalent", "univalve", "univariate", "universal", "universalisation",
"universalise", "universalised", "universaliser", "universalisers",
"universalising", "universalism", "universalist", "universalistic",
"universality", "universalisation", "universalization", "universalize",
"universalized", "universalizer", "universalizers", "universalizing",
"universally", "universalness", "universe", "universes", "universities",
"university", "univocal", "Unix", "uracil", "Urals", "uranium", "Uranus",
"uranyl", "urate", "urea", "uremia", "uremic", "ureter", "urethane",
"urethra", "urethral", "urethritis", "Urey", "Uri", "uric", "urinal",
"urinalysis", "urinary", "urinated", "urinating", "urination", "urine",
"urogenital", "urokinase", "urologist", "urologists", "urology",
"Uruguay", "Uruguayan", "Uruguayans", "US", "USA", "usability",
"usable", "usably", "usage",
"usages", "use", "used", "useful", "usefulness", "usefully", "useless",
"uselessly", "uselessness", "Usenet", "user", "users", "uses", "using",
"usual", "usually", "usurer", "usurers", "usuress", "usurial", "usurious",
"usurp", "usurpation", "usurped", "usurper", "usurping", "usurps",
"usury", "Utah", "utensil", "utensils", "uterine", "uterus", "Utica",
"utilitarian", "utilitarianism", "utilities", "utility", "utilizable",
"utilization", "utilize", "utilized", "utilizes", "utilizing", "utopia",
"utopian", "utopians", "utopias", "Utrecht", "Uttoxeter", "uvula",
"uvular"])

aAN = set(["f", "F", "FBI", "FDA", "heir", "heirdom", "heired",
"heirer", "heiress", "heiring", "heirloom", "heirship", "honest",
"honester", "honestly", "honesty", "honor", "honorable", "honorableness",
"honorably", "honorarium", "honorary", "honored", "honorer", "honorific",
"honoring", "honors", "honour", "honourable", "honourableness",
"honourably", "honourarium", "honourary", "honoured", "honourer",
"honourific", "honouring", "Honours", "hors", "hour", "hourglass", "hourlong",
"hourly", "hours", "l", "L", "LCD", "m", "M", "MBA", "MP", "mpg", "mph",
"MRI", "MSc", "MTV", "n", "N", "NBA", "NBC", "NFL", "NGO", "NHL", "r",
"R", "s", "S", "SMS", "sos", "SOS", "SPF", "std", "STD", "SUV", "x",
"X", "XML"])

aB = set(["H", "habitual", "hallucination", "haute", "hauteur", "herb", "herbaceous", "herbal",
"herbalist", "herbalism", "heroic", "hilarious", "historian", "historic", "historical",
"homage", "homophone", "horrendous", "hospitable", "horrific", "hotel", "hypothesis", "Xmas"])

def measurement(mnum, min, mout, mstr, decimal, remove):
    if min == "ft" or min == "in" or min == "mi":
        mnum = mnum.replace(" 1/2", ".5").replace(u" ½", ".5").replace(u"½",".5")
    m = calc("CONVERT_ADD", (float(eval(mnum.replace(remove, "").replace(decimal, ".").replace(u"−", "-"))), min, mout))
    a = list(set([str(calc("ROUND", (m, 0)))[:-2], str(calc("ROUND", (m, 1))), str(calc("ROUND", (m, 2))), str(m)])) # remove duplicated rounded items
    a.sort(lambda x, y: len(x) - len(y)) # sort by string length
    return (mstr + "\n").join(a).replace(".", decimal).replace("-", u"−") + mstr