All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gate.plugins.ANNIE.resources.NE.final.jape Maven / Gradle / Ivy

Go to download

Gate based component, that can process the Text units to extract informations using Gate's tools (such as grammars, gazetteers, tokenizer or POS Taggers). This project contains two versions, a simple component and webservice one.

There is a newer version: 2.0
Show newest version
/*
*  final.jape
*
* Copyright (c) 1998-2004, 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 11879 2009-11-03 13:24:55Z markagreenwood $
*/

//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 Title
Options: control = appelt


///////////////////////////////////////////////////////////////

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");
outputAS.add(personSet.firstNode(), personSet.lastNode(), "Person",
features);
outputAS.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");
//locate the first TempOrganization annotation
//(there will always be at least one)
gate.Annotation orgAnn = org.get("TempOrganization").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");
outputAS.add(org.firstNode(), org.lastNode(), "Organization",
features);
outputAS.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");
outputAS.add(org.firstNode(), org.lastNode(), "Organization",
features);
outputAS.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");
outputAS.add(loc.firstNode(), loc.lastNode(), "Location",
features);
outputAS.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");
outputAS.add(loc.firstNode(), loc.lastNode(), "Location",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.removeAll(date);
}


//Date Only Rules


Rule: DateOnlyFinal
Priority: 50
( 
 {Title}
)?
(
 {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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(time.firstNode(), date.lastNode(), "Date",
features2);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(date.firstNode(), date.lastNode(), "Date",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Address",
features);
outputAS.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");
outputAS.add(address.firstNode(), address.lastNode(), "Location",
features);
outputAS.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");
outputAS.add(ident.firstNode(), ident.lastNode(), "Identifier",
features);
outputAS.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();
outputAS.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");
//outputAS.add(person.firstNode(), person.lastNode(), "Person",
//features);
//outputAS.removeAll(person);
//}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy