the nlu module alexiei dingli. 2 the task so far … 1.identify relationships between people...

18
The NLU module Alexiei Dingli

Upload: shonda-osborne

Post on 31-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

The NLU moduleAlexiei Dingli

2 The task so far …

1. Identify relationships between people

2. Identify locations

3 The process

Gate

Annie

Dialogue Act Tagger

Syntactic Parser

Ontology Processing

Utterance

Syntactic and Semantic representation

4 Gate + DAT

I went to meet Lynne, my old flatmate, together with my sister Francesca.

PRP VBD TO VB NNP PRP$ JJ NN RB IN PRP$ NN NNP

Verb Phrases

Noun Chunks

5 Annie

I went to meet Lynne, my old flatmate, together with my sister Francesca.

Relationships

Persons

6 Syntactic Parser

Who is the sister and who is the flatmate?

I went to meet Lynne, my old flatmate, together with my friend Francesca.

((((I))((went)(((to)(meet)(Lynne)(,)(my)(old)(flatmate)(,))( (together))((with)( (my)(sister)(Francesca))))))(.)))

(((I)(went((to meet Lynne , my old flatmate,)( together)(with( my sister Francesca))))).))

(((I)(went((to meet Lynne , my old flatmate,)( together)(with( my sister Francesca))))).))

Syntactic bindings will help us identify that!

GATE annotations

A snippet output for the sentence: “Kate is the mother of Mary.”[AnnotationImpl: id=0; type=Token; features={category=NNP, kind=word, orth=upperInitial, length=4, string=Kate}; start=NodeImpl: id=0; offset=0; end=NodeImpl: id=1; offset=4, AnnotationImpl: id=1; type=SpaceToken; features={kind=space, length=1, string= }; start=NodeImpl: id=1; offset=4;end=NodeImpl: id=2; offset=5, AnnotationImpl: id=2; type=Token; features={category=VBZ, kind=word, orth=lowercase, length=2, string=is}; start=NodeImpl: id=2; offset=5; end=NodeImpl: id=3; offset=7, AnnotationImpl: id=3; type=SpaceToken; features={kind=space, length=1, string= }; start=NodeImpl: id=3; offset=7; end=NodeImpl: id=4; offset=8……]

Using Jape Rules• Location rules

– Where to, where from, location– to | into | onto ... the ...

• Speaker rules– Speaker name

• I am called ..., Call me ..., My name is ..., etc

• Relationship rules– X is the Y of Z, Tom is the brother of Jane– my X Y Z, my big fat brother Joe

8

Jape Rules : location

Macro: different_locations (({Lookup.majorType=="airport"}|{Lookup.majorType=="airports"}|{Lookup.majorType=="city_cap"}|{Lookup.majorType=="city"}|{Lookup.majorType=="country_abbrev"}|{Lookup.majorType=="country_cap"}|{Lookup.majorType=="country"}|{Lookup.majorType=="facility_key_ext"}|{Lookup.majorType=="facility_key"}|{Lookup.majorType=="facility"}|{Lookup.majorType=="loc_generalkey"}|{Lookup.majorType=="loc_key"}|{Lookup.majorType=="loc_prekey_lower"}|{Lookup.majorType=="loc_prekey"}|{Lookup.majorType=="mountain"}|{Lookup.majorType=="province"}|{Lookup.majorType=="region_cap"}|{Lookup.majorType=="region"}|{Lookup.majorType=="region_uk"}|{Lookup.majorType=="street"}|{Lookup.majorType=="location"} ):dif_locations )

Jape Rules: location

Macro: where_to_( ({Token.string == "to"} | {Token.string == "into" } | {Token.string == "onto" } | {Token.string == "toward" } | {Token.string == "towards" } | {Token.string == "against" }) ({Token.string=="the"})* different_locations )

Macro: where_through_across( ({Token.string == "across"} | {Token.string == "via" } | {Token.string == "through" } | {Token.string == "over" } | {Token.string == "throughout" } | {Token.string == "past" } | {Token.string == "along" } | {Token.string == "around" }) ({Token.string=="the"})* different_locations )

Macro: where_from( ({Token.string == "from"} | {Token.string == "of" } | {Token.string == "off" } | {Token.string == "out of" } | {Token.string == "away from" }) ({Token.string=="the"})* different_locations )

Jape Rules : locationRule: where_Priority:100(where_to_ | where_through_across | where_from):where_ --> { // Get reference to locationgate.AnnotationSet where1 = (gate.AnnotationSet)bindings.get("dif_locations"); gate.Annotation where_1 = (gate.Annotation)where1.iterator().next();

// Create a new feature mapgate.FeatureMap features = Factory.newFeatureMap();

// Get a handle to the original documentString mydocContent = doc.getContent().toString();

// Get the location from the textint begOffset = where_1.getStartNode().getOffset().intValue(); int endOffset = where_1.getEndNode().getOffset().intValue(); String locationString = mydocContent.substring(begOffset, endOffset);

// Create the featuresetfeatures.put("location", locationString);features.put("rule", "dif_locations");

// Save the annotationsgate.AnnotationSet locationName = (gate.AnnotationSet)bindings.get("dif_locations"); outputAS.add(locationName.firstNode(), locationName.lastNode(), "dif_locations", features);

}

Jape Rules : user nameMacro: speaker_name1 ( {Token.string == "I"} {Token.string == "am"} {Token.string == "called"} ({Lookup.majorType=="person_first"}):per1)

Macro: speaker_name2 ( {Token.string == "call"} {Token.string == "me"} ({Lookup.majorType=="person_first"}):per1)

Macro: speaker_name3 ( ({Token.string == "my"} | {Token.string == "My" }) {Token.string == "name"} {Token.string == "is"} ({Lookup.majorType=="person_first"}):per1)

Jape Rules : user nameRule: speaker_namePriority:100(speaker_name1|speaker_name2|speaker_name3):speaker_name --> { // Get reference to person 1gate.AnnotationSet per1 = (gate.AnnotationSet)bindings.get("per1"); gate.Annotation person1 = (gate.Annotation)per1.iterator().next();

// Create a new feature mapgate.FeatureMap features = Factory.newFeatureMap();

// Get a handle to the original documentString mydocContent = doc.getContent().toString();

// Get the second person from the textint begOffset = person1.getStartNode().getOffset().intValue(); int endOffset = person1.getEndNode().getOffset().intValue(); String person1String = mydocContent.substring(begOffset, endOffset);

// Create the featuresetfeatures.put("speaker", person1String);features.put("rule", "speaker_name");

// Save the annotationsgate.AnnotationSet speakerName = (gate.AnnotationSet)bindings.get("speaker_name"); outputAS.add(speakerName.firstNode(), speakerName.lastNode(), "speaker_name", features);

}

14 Ontology Processing (1)• The Relationships Ontology

15 Ontology Processing (2)• Allows us to infer new knowledge

– Sister(My) = Francesca– Flatmate(My) = Lynne

– If we have in the ontology:• Mother(My) = Mary

– We can infer through the properties of the Sister relationship that

• Mother(Francesca) = Mary• Daughter(Mary) = Francesca

16 Knowledgebase• Relationships Ontology

– Almost 40 person classes (mother, father, etc)– Almost 40 relationships (has friend, etc)

Will be adding more …

• Locations Ontology– Most continents, countries, regions, cities– Plus

• several places of interests per region• top 10 things to do in cities

Will be adding more …

•<City rdf:about="# Oxford"> •<hasTo_Do rdf:resource="#Botanic Gardens"/> •<hasTo_Do rdf:resource="#Christ Church"/> •<hasTo_Do rdf:resource="#Bridge of Sighs"/> •<hasTo_Do><To_Do rdf:about="#University Church of St Mary"/> </hasTo_Do> •<hasTo_Do rdf:resource="#Museums"/> •<hasTo_Do rdf:resource="#Radcliffe Camera"/> •<hasTo_Do> <To_Do rdf:ID="Punting"/> </hasTo_Do> <hasTo_Do> <To_Do rdf:about="#Bodleian Library"/> </hasTo_Do> <hasTo_Do rdf:resource="#Sheldonian Theatre"/> <hasTo_Do> <To_Do rdf:about="#Oxford University Colleges"/> </hasTo_Do> •</City>

Location ontology example

Creating an Instance in the Ontology

// Create the instance OWLNamedClass personClass = owlModel.getOWLNamedClass("Person"); OWLIndividual personInstance = owlModel.getOWLIndividual(personName);

// If it was already created, then just return it if (personInstance != null) return personInstance;

personInstance = personClass.createOWLIndividual(personName);

// Create a name property if (personName.trim().length() > 0) { OWLProperty hasNameProperty = owlModel.getOWLDatatypeProperty("hasName"); personInstance.setPropertyValue(hasNameProperty, personName); }

// Create an isSpeaker property if (isSpeaker) { OWLProperty isSpeakerProperty = owlModel.getOWLDatatypeProperty("isSpeaker"); personInstance.setPropertyValue(isSpeakerProperty, isSpeaker); }

// Create a gender property if (personGender.trim().length() > 0) { OWLProperty hasSexProperty = owlModel.getOWLProperty("hasSex"); personInstance.setPropertyValue(hasSexProperty, owlModel.getOWLIndividual(personGender)); }