From Wikipedia, the free encyclopedia
Okay, step 1 is to read through
Regular expressions , and the relevant
manual page .
Step 2: Open up AWB and the advanced Find and Replace settings.
Step 3: Creating rules and subrules
It's important to have these rules processed in the same order listed here to avoid conflicts with AWB trying to apply convert multiple times. Also, these are ALL regular expressions, so you need to be sure that the option IS ALWAYS checked in the bottom of the dialog box, and the option for "Case sensitive" IS NEVER checked.
Remember: False positives can and WILL happen, check EVERY edit.
Remove endash
{{
convert }} cannot handle the HTML entities that create dashes, they must be entered literally
New Rule: "remove ndash and mdash"
([0-9]+\.?[0-9]*)(\s| )?(–|—|—)(\s| )?([0-9]+\.?[0-9]*)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
$1-$5 $7
Text to numbers
{{
convert }} cannot handle numbers written as text, they must be converted. Most editors only write out the numbers 1-10.
New Rule: "Text to numbers"
\b(a(?:n)?|an|one)\b(\s| )?(-)?(\s| )?\b((centi|kilo|milli)?met(er|re)?|kilo|(kilo|milli)?gram(me)?|inch|mile|foot|pound|ounce)\b
1$2$3$4$5
two(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
2$1$2$3$4
Follow the example from Subrule "two" for "three"-"nine", creating a "ten" is optional. If you're unsure what to change, see the below examples.
More examples
three(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
3$1$2$3$4
four(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
4$1$2$3$4
five(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
5$1$2$3$4
six(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
6$1$2$3$4
seven(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
7$1$2$3$4
eight(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
8$1$2$3$4
nine(\s| )?(-)?(\s| )?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b
9$1$2$3$4
Longhand to short
{{
convert }} only accepts the abbreviated versions of measurments (e.g. ft, not feet).
New Rule: "Longhand to short"
New subrule: "convert cm"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(centimeter(s)?)
$1$3cm
New subrule: "convert in"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?inch(es)?
$1$3in
New subrule: "convert km"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?kilomet(er|re)(s)?
$1$3km
([0-9]+.?[0-9]*)(\s| )?(-)?(\s| )?met(er|re)(s)?
$1$3m
New subrule: "convert mm"
([0-9]+.?[0-9]*)(\s| )?(-)?(\s| )?millimet(er|re)(s)?
$1$3mm
New subrule: "convert ft"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(feet|foot)
$1$3ft
New subrule: "convert mi"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?mile(s)?
$1$3mi
New subrule: "convert kg"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?kilo(gram(me)?)?(s)?
$1$3kg
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?gram(me)?(s)?
$1$3g
New subrule: "convert lb"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(lbs|pound)(s)?
$1$3lb
New subrule: "convert mg"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?milligram(me)?(s)?
$1$3mg
New subrule: "convert oz"
([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?ounce(s)?
$1$3oz
Apply convert
Now convert is ready to process the article.
First convert needs to be applied to measurement ranges (e.g. 2-4 mi).
([0-9]+\.?[0-9]*)(\s| )?(to|-|and|by|x)(\s| )?([0-9]+\.?[0-9]*)(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b(\s| )?(\(([0-9]+\.?[0-9]*)(\s| )?(((c|k|m)?(m|g|i)n?|ft|lb|oz)\b)?(\s| )?(to|-|and)?(\s| )?([0-9]+\.?[0-9]*)(\s| )?(((c|k|m)?(m|g|i)n?|ft|lb|oz)\b)?\)?)?
{{convert|$1|$3|$5|$7|abbr=on}}
Now we can apply {{
convert }} to measurements with handwritten conversions, using the supplied output conversion instead of the default one (e.g. 3 inches (76 mm) will be written as {{convert|3|in|mm}} instead of {{convert|3|in}} which would default to converting inches to centimeters)
([0-9]+\.?[0-9]*)(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b(\s| )?\(([0-9]+\.?[0-9]*)(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b\)
{{convert|$1|$3|$9|abbr=on}}
The next conversions to be applied are those without handwritten conversions, for these we let {{
convert }} decide what's best.
New subrule: "force convert"
([0-9]+\.?[0-9]*)(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b
{{convert|$1|$3|abbr=on}}
The final step is to convert adjective forms of measurements (e.g. a 10-foot pole).
New subrule: "adj convert"
([0-9]+\.?[0-9]*)(\s| )?-(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b((\s| )?\(([0-9]+\.?[0-9]*)(\s| )?-?(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b\))?
{{convert|$1|$4|adj=on}}