/* * final.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, 10 Sep 2001 * * $Id: final.jape,v 1.1 2004/09/10 13:33:24 akshay Exp $ */ //note: organization should be included as part of the address ?? Phase: Final Input: Token Lookup Jobtitle TempPerson TempLocation TempOrganization TempDate TempTime TempYear TempZone Street Postcode Email Url Phone Ip TempIdentifier TempSpecs TempFacility Control Options: control = appelt /////////////////////////////////////////////////////////////// Rule: NotPersonFinal Priority: 200 ( INITIALS ):notfirstperson --> {} Rule: PersonFinal Priority: 30 ({JobTitle} )? ( {TempPerson.kind == personName} ) :person --> { gate.FeatureMap features = Factory.newFeatureMap(); gate.AnnotationSet personSet = (gate.AnnotationSet)bindings.get("person"); gate.Annotation person1Ann = (gate.Annotation)personSet.iterator().next(); gate.AnnotationSet firstPerson = (gate.AnnotationSet)personSet.get("TempPerson"); if (firstPerson != null && firstPerson.size()>0) { gate.Annotation personAnn = (gate.Annotation)firstPerson.iterator().next(); features.put("gender", personAnn.getFeatures().get("gender")); } features.put("rule1", person1Ann.getFeatures().get("rule")); features.put("rule", "PersonFinal"); annotations.add(personSet.firstNode(), personSet.lastNode(), "Person", features); annotations.removeAll(personSet); } Rule: OrgCountryFinal Priority: 50 // G M B Scotland // Scottish Electricity Board ( ({TempOrganization})? (({Lookup.majorType == country_adj}| {Lookup.majorType == location}) {TempOrganization} )| ({TempOrganization} ({Token.position == startpunct})? ({Lookup.majorType == country_adj}| {Lookup.majorType == location}) ({Token.position == endpunct})? ) ({TempOrganization})? ({Lookup.majorType == org_ending})? ) :org --> { //removes TempOrg annotation, gets the rule feature and adds a new Org annotation gate.AnnotationSet org = (gate.AnnotationSet)bindings.get("org"); gate.Annotation orgAnn = (gate.Annotation)org.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("orgType", orgAnn.getFeatures().get("orgType")); features.put("rule1", orgAnn.getFeatures().get("rule")); features.put("rule2", "OrgCountryFinal"); annotations.add(org.firstNode(), org.lastNode(), "Organization", features); annotations.removeAll(org); } //note - move this rule to after final Rule: OrgFinal Priority: 10 ( {TempOrganization} ) :org --> { //removes TempOrg annotation, gets the rule feature and adds a new Org annotation gate.AnnotationSet org = (gate.AnnotationSet)bindings.get("org"); gate.Annotation orgAnn = (gate.Annotation)org.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("orgType", orgAnn.getFeatures().get("orgType")); features.put("rule1", orgAnn.getFeatures().get("rule")); features.put("rule2", "OrgFinal"); annotations.add(org.firstNode(), org.lastNode(), "Organization", features); annotations.removeAll(org); } Rule: PersonLocFinal Priority: 100 // George Airport // later we might change this to any facility, rather than just airports ( {TempPerson} ({Token.string == "airport"} | {Token.string == "Airport"}) ) :loc --> { //removes TempLoc annotation, gets the rule feature and adds a new Loc annotation gate.AnnotationSet loc = (gate.AnnotationSet)bindings.get("loc"); gate.Annotation locAnn = (gate.Annotation)loc.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", locAnn.getFeatures().get("rule")); features.put("rule2", "PersonLocFinal"); annotations.add(loc.firstNode(), loc.lastNode(), "Location", features); annotations.removeAll(loc); } Rule: LocFinal Priority: 10 ( {TempLocation} ) :loc --> { //removes TempLoc annotation, gets the rule feature and adds a new Loc annotation gate.AnnotationSet loc = (gate.AnnotationSet)bindings.get("loc"); gate.Annotation locAnn = (gate.Annotation)loc.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("locType",locAnn.getFeatures().get("locType")); features.put("rule1", locAnn.getFeatures().get("rule")); features.put("rule2", "LocFinal"); annotations.add(loc.firstNode(), loc.lastNode(), "Location", features); annotations.removeAll(loc); } ////////////////////////////////////////////////////////////// // Rules from Timex Rule: DateTimeFinal Priority: 20 // Friday 10 January 2000 2pm ( {TempDate} ( ({Token.string == ","})? {TempDate})? ({Token.string == ":"})? {TempTime} ({TempYear})? ({TempZone})? ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); //features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "DateTimeFinal"); features.put("kind", "dateTime"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: SeasonYearFinal Priority: 15 ( ({Token.string == "spring"} | {Token.string == "Spring"}) {TempYear.kind == positive} ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "SeasonYearFinal"); features.put("kind", "date"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: DateYearFinal Priority: 10 ( {TempDate} ( ({Token.string == ","})? {TempDate})? {TempYear} ({TempDate})? ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "DateYearFinal"); features.put("kind", "date"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: TimeDateFinal Priority: 10 // 2pm 10 January 2000 // 2pm 10 January 2000 +0400 ( {TempTime} ({Token.string == ":"})? {TempDate} ({TempYear})? ({TempZone})? ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); //features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "TimeDateFinal"); features.put("kind", "dateTime"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: TimeYearFinal Priority: 10 // 21:00:00 2000 +0400 ( {TempTime} ({Token.string == ":"})? ({TempYear}) ({TempZone})? ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); //features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "TimeYearFinal"); features.put("kind", "dateTime"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } //Date Only Rules Rule: DateOnlyFinal Priority: 10 ( {TempDate} ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "DateOnlyFinal"); features.put("kind", "date"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } //fix this later Rule: TimeContextFinal Priority: 10 // Wednesday [mdash ] 8-15 ( ({TempTime}|{TempDate}):date {Token.string == "["} {Token.string == "mdash"} {Token.string == "]"} ) ( {TempTime.kind == temp} ):time --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule", "TimeContextFinal"); features.put("kind", "date"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); //removes TempTime annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet time = (gate.AnnotationSet)bindings.get("time"); gate.Annotation timeAnn = (gate.Annotation)time.iterator().next(); gate.FeatureMap features2 = Factory.newFeatureMap(); features2.put("rule1", timeAnn.getFeatures().get("rule")); features2.put("rule", "TimeContextFinal"); features2.put("kind", "time"); annotations.add(time.firstNode(), date.lastNode(), "Date", features2); annotations.removeAll(time); } Rule: TimeWordsContextFinal Priority: 50 //seven to nine o'clock ( {TempTime.kind == timeWords} {Token.string == "to"} {TempTime.kind == positive} ) :date --> { //removes TempTime annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "TimeWordsContextFinal"); features.put("kind", "time"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: YearOnlyFinal Priority: 10 ( {TempYear.kind == positive} ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "YearOnlyFinal"); features.put("kind", "date"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } Rule: TimeOnlyFinal Priority: 10 ( {TempTime.kind == positive} ) :date --> { //removes TempDate annotation, gets the rule feature and adds a new Date annotation gate.AnnotationSet date = (gate.AnnotationSet)bindings.get("date"); gate.Annotation dateAnn = (gate.Annotation)date.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", dateAnn.getFeatures().get("rule")); features.put("rule2", "TimeOnlyFinal"); features.put("kind", "time"); annotations.add(date.firstNode(), date.lastNode(), "Date", features); annotations.removeAll(date); } //////////////////////////////////////////////////////////// Rule: AddressFull Priority: 100 ( ({Street} {Token.string == ","})? ({TempLocation} ({Token.string == ","})? )+ ({Postcode}) ({Token.string == ","})? ({TempLocation})* ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "AddressFull"); features.put("kind", "complete"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: EmailFinal Priority: 50 ( {Email} ) :address --> { //removes Email annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "EmailFinal"); features.put("kind", "email"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: PhoneFinal Priority: 50 ( {Phone} ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "PhoneFinal"); features.put("kind", "phone"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: PostcodeFinal Priority: 50 ( {Postcode} ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "PostcodeFinal"); features.put("kind", "postcode"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: IpFinal Priority: 50 ( {Ip} ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "IpFinal"); features.put("kind", "ip"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: UrlFinal Priority: 50 ( {Url} ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "UrlFinal"); features.put("kind", "url"); annotations.add(address.firstNode(), address.lastNode(), "Address", features); annotations.removeAll(address); } Rule: StreetFinal //make streets locations Priority: 50 ( {Street} ) :address --> { //removes TempAddress annotation, gets the rule feature and adds a new Address annotation gate.AnnotationSet address = (gate.AnnotationSet)bindings.get("address"); gate.Annotation addressAnn = (gate.Annotation)address.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", addressAnn.getFeatures().get("rule")); features.put("rule2", "StreetFinal"); annotations.add(address.firstNode(), address.lastNode(), "Location", features); annotations.removeAll(address); } //////////////////////////////////////////////////////////// Rule: IdentifierFinal Priority: 10 ( {TempIdentifier} ) :ident --> { //removes TempIdent annotation, gets the rule feature and adds a new Identifier annotation gate.AnnotationSet ident = (gate.AnnotationSet)bindings.get("ident"); gate.Annotation identAnn = (gate.Annotation)ident.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", identAnn.getFeatures().get("rule")); features.put("rule2", "IdentifierFinal"); annotations.add(ident.firstNode(), ident.lastNode(), "Identifier", features); annotations.removeAll(ident); } // this gets used when specs rule for emails is fired (in eml-final.jape) Rule: SpecsFinal Priority: 1000 ( {TempSpecs} ):spec --> { //removes TempSpecs annotation gate.AnnotationSet spec = (gate.AnnotationSet)bindings.get("spec"); //gate.FeatureMap features = Factory.newFeatureMap(); annotations.removeAll(spec); } ////////////////////////////////////////////////////// Rule: UnknownPerson Priority: 5 ( {Token.category == NNP} ((SPACE|{Token.string == "-"}) {Token.category == NNP})? (SPACE {Token.category == NNP})? (SPACE {Token.category == NNP})? ):unknown (SPACE) ( {TempPerson} ):person --> :unknown.Unknown = {kind = "PN", rule = UnknownTempPerson}, { //removes TempPerson annotation, gets the rule feature and adds a new Person annotation gate.AnnotationSet person = (gate.AnnotationSet)bindings.get("person"); gate.Annotation personAnn = (gate.Annotation)person.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("gender", personAnn.getFeatures().get("gender")); features.put("rule1", personAnn.getFeatures().get("rule")); features.put("rule2", "UnknownPerson"); annotations.add(person.firstNode(), person.lastNode(), "Person", features); annotations.removeAll(person); } Rule: FacilityFinal Priority: 10 ( {TempFacility} ) :fac --> { //removes TempFac annotation, gets the rule feature and adds a new Fac annotation gate.AnnotationSet fac = (gate.AnnotationSet)bindings.get("fac"); gate.Annotation facAnn = (gate.Annotation)fac.iterator().next(); gate.FeatureMap features = Factory.newFeatureMap(); features.put("rule1", facAnn.getFeatures().get("rule")); features.put("rule2", "FacilityFinal"); annotations.add(fac.firstNode(), fac.lastNode(), "Location", features); //annotations.removeAll(fac); }