/* * number.jape * * Copyright (c) 1998-2001, The University of Sheffield. * * This file is part of GATE (see http://gate.ac.uk/), and is free * software, licenced under the GNU Library General Public License, * Version 2, June 1991 (in the distribution as file licence.html, * and also available at http://gate.ac.uk/gate/licence.html). * * Diana Maynard, 02 Aug 2001 * * $Id: number.jape,v 1.1 2004/09/10 13:33:24 akshay Exp $ */ Phase: Number Input: Token Lookup Control Options: control = appelt /////////////////////////////////////////////////////////////// //Money Rules Macro: MILLION_BILLION ({Token.string == "m"}| {Token.string == "million"}| {Token.string == "b"}| {Token.string == "billion"}| {Token.string == "bn"}| {Token.string == "k"}| {Token.string == "K"} ) Macro: NUMBER_WORDS // two hundred and thirty five // twenty five ( (({Lookup.majorType == number} ({Token.string == "-"})? )* {Lookup.majorType == number} {Token.string == "and"} )* ({Lookup.majorType == number} ({Token.string == "-"})? )* {Lookup.majorType == number} ) Macro: AMOUNT_NUMBER // enables commas, decimal points and million/billion // to be included in a number (({Token.kind == number} (({Token.string == ","}| {Token.string == "."} ) {Token.kind == number} )* | (NUMBER_WORDS) ) ({Token.string == "."})? (MILLION_BILLION)? ) Rule: MoneyCurrencyUnit // 30 pounds ( (AMOUNT_NUMBER) ({Lookup.majorType == currency_unit}) ) :number --> :number.Money = {kind = "number", rule = "MoneyCurrencyUnit"} Rule: MoneySymbolUnit // $30 // $30 US // not $1$21 // $20US ( ({Token.symbolkind == currency}| {Lookup.majorType == currency_unit}) (AMOUNT_NUMBER) ( {Lookup.majorType == currency_unit} )? ) :number --> :number.Money = {kind = "number", rule = "MoneySymbolUnit"} ////////////////////////////////////////////////////////////// // Percentage Rules Macro: PERCENT ( {Lookup.majorType == percent} ) Rule: PercentBasic // +20% // minus 10 percent // two point four percent ( ({Token.string == "+"}| {Token.string == "-"}| {Token.string == "minus"} )? (AMOUNT_NUMBER|NUMBER_WORDS)* ({Token.string == "point"})? (AMOUNT_NUMBER|NUMBER_WORDS) (PERCENT) ) :number --> :number.Percent = {rule = "PercentBasic"} Rule: NotPercentSpan // four-fold to 10% (four-fold gets wrongly recognised as AMOUNT_NUMBER) ( {Lookup.majorType == number_fold} ({Token.string == "-"} | {Token.string == "to"}) ) ( (AMOUNT_NUMBER|NUMBER_WORDS) (PERCENT) ) :number --> :number.Percent = {rule = "NotPercentSpan"} Rule: PercentSpan // 20-30% // two to four percent ( (AMOUNT_NUMBER|NUMBER_WORDS) ({Token.string == "-"} | {Token.string == "to"}) (AMOUNT_NUMBER|NUMBER_WORDS) (PERCENT) ) :number --> :number.Percent = {rule = "PercentSpan"}