User:Zappernapper/AWB convert
Appearance
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.
Rule 1
[edit]Remove endash
{{convert}} cannot handle the HTML entities that create dashes, they must be entered literally
- New Rule: "remove ndash and mdash"
- Find:
- ([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
- Replace:
- $1-$5 $7
Rule 2
[edit]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"
- New Subule: "one"
- Find:
- \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
- Replace:
- 1$2$3$4$5
- New Subrule: "two"
- Find:
- 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
- Replace:
- 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
- New Subrule: "three"
- Find:
- 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
- Replace:
- 3$1$2$3$4
- New Subrule: "four"
- Find:
- 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
- Replace:
- 4$1$2$3$4
- New Subrule: "five"
- Find:
- 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
- Replace:
- 5$1$2$3$4
- New Subrule: "six"
- Find:
- 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
- Replace:
- 6$1$2$3$4
- New Subrule: "seven"
- Find:
- 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
- Replace:
- 7$1$2$3$4
- New Subrule: "eight"
- Find:
- 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
- Replace:
- 8$1$2$3$4
- New Subrule: "nine"
- Find:
- 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
- Replace:
- 9$1$2$3$4
Rule 3
[edit]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"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(centimeter(s)?)
- Replace:
- $1$3cm
- New subrule: "convert in"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?inch(es)?
- Replace:
- $1$3in
- New subrule: "convert km"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?kilomet(er|re)(s)?
- Replace:
- $1$3km
- New subrule: "convert m"
- Find:
- ([0-9]+.?[0-9]*)(\s| )?(-)?(\s| )?met(er|re)(s)?
- Replace:
- $1$3m
- New subrule: "convert mm"
- Find:
- ([0-9]+.?[0-9]*)(\s| )?(-)?(\s| )?millimet(er|re)(s)?
- Replace:
- $1$3mm
- New subrule: "convert ft"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(feet|foot)
- Replace:
- $1$3ft
- New subrule: "convert mi"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?mile(s)?
- Replace:
- $1$3mi
- New subrule: "convert kg"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?kilo(gram(me)?)?(s)?
- Replace:
- $1$3kg
- New subrule: "convert g"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?gram(me)?(s)?
- Replace:
- $1$3g
- New subrule: "convert lb"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?(lbs|pound)(s)?
- Replace:
- $1$3lb
- New subrule: "convert mg"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?milligram(me)?(s)?
- Replace:
- $1$3mg
- New subrule: "convert oz"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?(-)?(\s| )?ounce(s)?
- Replace:
- $1$3oz
Rule four
[edit]Apply convert
Now convert is ready to process the article.
- First convert needs to be applied to measurement ranges (e.g. 2-4 mi).
- New subrule: "convert 2"
- Find:
- ([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)?\)?)?
- Replace:
- {{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)
- New subrule: "convert"
- Find:
- ([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\)
- Replace:
- {{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"
- Find:
- ([0-9]+\.?[0-9]*)(\s| )?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b
- Replace:
- {{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"
- Find:
- ([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\))?
- Replace:
- {{convert|$1|$4|adj=on}}