SlideShare uma empresa Scribd logo
1 de 21
C# Natural LanguageEngine Ian Mercer, ian@abodit.com http://blog.abodit.com
Introduction This presentation outlines the C# Natural Language Engine used by the ‘Smartest House in the World’, a home automation system developed by the author If you are interested in using the C# Natural Language Engine presented here in a commercial product please contact the author.
C# Natural LanguageEngine Existing Natural LanguageEngines Have a large, STATIC dictionary data file Can parsecomplex sentence structure Hand back a tree of tokens (strings) Don’thandle conversations C# NLP Engine Definesstrongly-typedtokens in code Uses type inheritance to model ‘is a’ Defines sentences in code Rulesengineexecutes sentences Understandscontext (conversation history)
Sample conversation … Complex temporal expressions … Ask it to play music … become database queries Handles async conversations Understands names …
Goals Makeiteasy to definetokens and sentences (not XML) Safe, compile-time checkeddefinition of the syntax and grammar (not XML) Model real-world inheritancewith C# class inheritance:	‘a labrador’ is ‘a dog’ is ‘an animal’ is ‘a thing’ Handleambiguity, e.g.playsomethingin the air tonightin the kitchenremind me at 4pm to call johnat 5pm
C# NLP Engine Structure Token Definitions Sentence Definitions 1 1 Sentence ‘Executed’ Input Token Parser 2 6 State 3 4 5 Rules Engine
Tokens - TokenDefinition A hierarchy of Token-derived classes Uses inheritance, e.g. TokenOnis a TokenOnOffis a TokenStateis a Token This allows a single sentence rule to handle multiple cases, e.g. On and Off Derivedfrom base Token class Simple tokens are a set of words e.g. « is | are  » Complextokens have a parser e.g. TokenDouble
A Simple TokenDefinition 	publicclassTokenPersonalPronoun: TokenGenericNoun{     internalstaticstringwordz        { get { return"he,him,she,her,them"; } } }  Recognizesany of the wordsspecified Can use inheritance (as in thisexamplewhere a PersonalPronounismodelled as a subclass of GenericNoun)
A ComplexToken publicabstractclassTokenNumber: Token  { publicstaticIEnumerable<TokenResult> Initialize(string input) {  	…      Initializemethodparses input and returns one or more possible parses. TokenNumberis a good example: Parsesanynumeric value and returns one or more of TokenInt, TokenLong, TokenIntOrdinal, TokenDouble, or TokenPercentageresults.
The catch-all TokenPhrase publicclassTokenPhrase : Token  TokenPhrase matches anything, especiallyanything in quote marks add a remindercall Brunoat 4pm Sentence signature couldbe (…, TokenAdd, TokenReminder, TokenPhrase, TokenExactTime) This would match the ruletoo … add a reminderdiscuss 6pm conference call with Bruno at 4pm
TemporalTokens A complete set of tokens and related classes for representing time Point in time, e.g. todayat 5pm Approximate time, e.g. whocalledat 5pm today Finitesequence, e.g. every Thursday in May 2009 Infinitesequence, e.g. every Thursday Ambiguous time withcontext, e.g. remind me on Tuesday (contextmeansitisnext Tuesday) Null time Unknowable/incomprehensible time
TemporalTokens (Cont.) Code to merge any sequence of temporal tokens to the smallest canonical representation, e.g.  	the first thursday in may 2009 {TIMETHEFIRST the first} + {THURSDAY thursday} + {MAY in may} + {INT 2009 -> 2009} [TEMPORALSETFINITESINGLEINTERVAL [Thursday 5/7/2009] ]
TemporalTokens (Cont.) Finite TemporalClasses provide A way to enumerate the DateTimeRanges they cover All TemporalClasses provide A LINQ expression generator and Entity-SQL expression generator allowing them to be used to query a database
Existing Token Types Numbers (double, long, int, percentage, phone, temperature) File names, Directories URLs, Domain names Names, Companies, Addresses Rooms, Lights, Sensors, Sprinklers, … States (On, Off, Dim, Bright, Loud, Quiet, …) Units of Time, Weight, Distance Songs, albums, artists, genres, tags Temporal expressions Commands, verbs, nouns, pronouns, …
Rules - A simple rule ///<summary> /// Set a light to a given state  ///</summary>  privatestaticvoidLightState(NLPStatest, TokenLighttlight, TokenStateOnOffts) { if (ts.IsTrueState == true) tlight.ForceOn(st.Actor); if (ts.IsTrueState == false) tlight.ForceOff(st.Actor); st.Say("I turned it " + ts.LowerCased);  }  Any method matching this signature is a sentence rule:-  NLPState, Token* Rule matching respects inheritance, and variable repeats …  … (NLPStatest, TokenThingtt, TokenStatetokenState, TokenTimeConstraint[] constraints)
State - NLPState Every sentence method takes an NLPState first parameter State includes RememberedObject(s) allowing sentences to react to anything that happened earlier in a conversation Non-interactive uses can pass a dummy state State can be per-user or per-conversation for non-realtime conversations like email
User Interface Works with a variety of user interfaces Chat (e.g Jabber/Gtalk) Web chat Email Calendar (do X at time Y) Rich client application
Token and Rule Discovery No configuration needed: all Tokens and Rules are discovered using reflection Builds a recursive descent parser tree on startup to efficiently parse any token stream Dependency injection like code to call rules methods based on matching token sequences Parser can handle array parameters as well as single parameters for more flexibility
Summary Strongly-typednaturallanguageengine Compile time checking, inheritance, … Definetokens and sentences (rules) in C# Strongly-typedtokens: numbers, percentages, times, dates, file names, urls, people, business objects, … Builds an efficient parse graph Tracks conversation history
Future plans Expanded corpus of knowledge Companynames, locations, documents, … Performance improvements Onlytryparsingtokensvalid for currentparsetree state .NET 4 Optional Arguments Account for these in reflection code duringparsetreecreation GenerateiCal/GdataRecurrence FromTimeExpressions
For more information Visit http://blog.abodit.com Contact ian@abodit.com

Mais conteúdo relacionado

Mais procurados

Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way PresentationAmira ElSharkawy
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남Eunjeong (Lucy) Park
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at WorkErin Dees
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM CompilerErin Dees
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)KALAISELVI P
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's RevengeErin Dees
 

Mais procurados (20)

Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Rust Intro
Rust IntroRust Intro
Rust Intro
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남한국어와 NLTK, Gensim의 만남
한국어와 NLTK, Gensim의 만남
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python
PythonPython
Python
 
Python Programming Homework Help
Python Programming Homework HelpPython Programming Homework Help
Python Programming Homework Help
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
 
1. python programming
1. python programming1. python programming
1. python programming
 
Write Your Own JVM Compiler
Write Your Own JVM CompilerWrite Your Own JVM Compiler
Write Your Own JVM Compiler
 
Python programming msc(cs)
Python programming msc(cs)Python programming msc(cs)
Python programming msc(cs)
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
 

Semelhante a C# Natural Language Engine for Home Automation

About Tokens and Lexemes
About Tokens and LexemesAbout Tokens and Lexemes
About Tokens and LexemesBen Scholzen
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to knowRoy van Rijn
 
Generating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonGenerating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonTristan Penman
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - IJaganadh Gopinadhan
 
Csharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsCsharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsAbed Bukhari
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on SessionDharmesh Tank
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Beginning text analysis
Beginning text analysisBeginning text analysis
Beginning text analysisBarry DeCicco
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrencyAlex Navis
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel GeheugenDevnology
 
Introduction to Boost regex
Introduction to Boost regexIntroduction to Boost regex
Introduction to Boost regexYongqiang Li
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsqlafa reg
 

Semelhante a C# Natural Language Engine for Home Automation (20)

About Tokens and Lexemes
About Tokens and LexemesAbout Tokens and Lexemes
About Tokens and Lexemes
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
Antlr
AntlrAntlr
Antlr
 
NLP with TensorFlow.pdf
NLP with TensorFlow.pdfNLP with TensorFlow.pdf
NLP with TensorFlow.pdf
 
What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
 
Generating parsers using Ragel and Lemon
Generating parsers using Ragel and LemonGenerating parsers using Ragel and Lemon
Generating parsers using Ragel and Lemon
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
Elements of Text Mining Part - I
Elements of Text Mining Part - IElements of Text Mining Part - I
Elements of Text Mining Part - I
 
Csharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressionsCsharp4 strings and_regular_expressions
Csharp4 strings and_regular_expressions
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Beginning text analysis
Beginning text analysisBeginning text analysis
Beginning text analysis
 
Clojure concurrency
Clojure concurrencyClojure concurrency
Clojure concurrency
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
Introduction to Boost regex
Introduction to Boost regexIntroduction to Boost regex
Introduction to Boost regex
 
Eff Plsql
Eff PlsqlEff Plsql
Eff Plsql
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

C# Natural Language Engine for Home Automation

  • 1. C# Natural LanguageEngine Ian Mercer, ian@abodit.com http://blog.abodit.com
  • 2. Introduction This presentation outlines the C# Natural Language Engine used by the ‘Smartest House in the World’, a home automation system developed by the author If you are interested in using the C# Natural Language Engine presented here in a commercial product please contact the author.
  • 3. C# Natural LanguageEngine Existing Natural LanguageEngines Have a large, STATIC dictionary data file Can parsecomplex sentence structure Hand back a tree of tokens (strings) Don’thandle conversations C# NLP Engine Definesstrongly-typedtokens in code Uses type inheritance to model ‘is a’ Defines sentences in code Rulesengineexecutes sentences Understandscontext (conversation history)
  • 4. Sample conversation … Complex temporal expressions … Ask it to play music … become database queries Handles async conversations Understands names …
  • 5. Goals Makeiteasy to definetokens and sentences (not XML) Safe, compile-time checkeddefinition of the syntax and grammar (not XML) Model real-world inheritancewith C# class inheritance: ‘a labrador’ is ‘a dog’ is ‘an animal’ is ‘a thing’ Handleambiguity, e.g.playsomethingin the air tonightin the kitchenremind me at 4pm to call johnat 5pm
  • 6. C# NLP Engine Structure Token Definitions Sentence Definitions 1 1 Sentence ‘Executed’ Input Token Parser 2 6 State 3 4 5 Rules Engine
  • 7. Tokens - TokenDefinition A hierarchy of Token-derived classes Uses inheritance, e.g. TokenOnis a TokenOnOffis a TokenStateis a Token This allows a single sentence rule to handle multiple cases, e.g. On and Off Derivedfrom base Token class Simple tokens are a set of words e.g. « is | are  » Complextokens have a parser e.g. TokenDouble
  • 8. A Simple TokenDefinition publicclassTokenPersonalPronoun: TokenGenericNoun{     internalstaticstringwordz        { get { return"he,him,she,her,them"; } } } Recognizesany of the wordsspecified Can use inheritance (as in thisexamplewhere a PersonalPronounismodelled as a subclass of GenericNoun)
  • 9. A ComplexToken publicabstractclassTokenNumber: Token { publicstaticIEnumerable<TokenResult> Initialize(string input) { …     Initializemethodparses input and returns one or more possible parses. TokenNumberis a good example: Parsesanynumeric value and returns one or more of TokenInt, TokenLong, TokenIntOrdinal, TokenDouble, or TokenPercentageresults.
  • 10. The catch-all TokenPhrase publicclassTokenPhrase : Token TokenPhrase matches anything, especiallyanything in quote marks add a remindercall Brunoat 4pm Sentence signature couldbe (…, TokenAdd, TokenReminder, TokenPhrase, TokenExactTime) This would match the ruletoo … add a reminderdiscuss 6pm conference call with Bruno at 4pm
  • 11. TemporalTokens A complete set of tokens and related classes for representing time Point in time, e.g. todayat 5pm Approximate time, e.g. whocalledat 5pm today Finitesequence, e.g. every Thursday in May 2009 Infinitesequence, e.g. every Thursday Ambiguous time withcontext, e.g. remind me on Tuesday (contextmeansitisnext Tuesday) Null time Unknowable/incomprehensible time
  • 12. TemporalTokens (Cont.) Code to merge any sequence of temporal tokens to the smallest canonical representation, e.g. the first thursday in may 2009 {TIMETHEFIRST the first} + {THURSDAY thursday} + {MAY in may} + {INT 2009 -> 2009} [TEMPORALSETFINITESINGLEINTERVAL [Thursday 5/7/2009] ]
  • 13. TemporalTokens (Cont.) Finite TemporalClasses provide A way to enumerate the DateTimeRanges they cover All TemporalClasses provide A LINQ expression generator and Entity-SQL expression generator allowing them to be used to query a database
  • 14. Existing Token Types Numbers (double, long, int, percentage, phone, temperature) File names, Directories URLs, Domain names Names, Companies, Addresses Rooms, Lights, Sensors, Sprinklers, … States (On, Off, Dim, Bright, Loud, Quiet, …) Units of Time, Weight, Distance Songs, albums, artists, genres, tags Temporal expressions Commands, verbs, nouns, pronouns, …
  • 15. Rules - A simple rule ///<summary> /// Set a light to a given state ///</summary> privatestaticvoidLightState(NLPStatest, TokenLighttlight, TokenStateOnOffts) { if (ts.IsTrueState == true) tlight.ForceOn(st.Actor); if (ts.IsTrueState == false) tlight.ForceOff(st.Actor); st.Say("I turned it " + ts.LowerCased); } Any method matching this signature is a sentence rule:- NLPState, Token* Rule matching respects inheritance, and variable repeats … … (NLPStatest, TokenThingtt, TokenStatetokenState, TokenTimeConstraint[] constraints)
  • 16. State - NLPState Every sentence method takes an NLPState first parameter State includes RememberedObject(s) allowing sentences to react to anything that happened earlier in a conversation Non-interactive uses can pass a dummy state State can be per-user or per-conversation for non-realtime conversations like email
  • 17. User Interface Works with a variety of user interfaces Chat (e.g Jabber/Gtalk) Web chat Email Calendar (do X at time Y) Rich client application
  • 18. Token and Rule Discovery No configuration needed: all Tokens and Rules are discovered using reflection Builds a recursive descent parser tree on startup to efficiently parse any token stream Dependency injection like code to call rules methods based on matching token sequences Parser can handle array parameters as well as single parameters for more flexibility
  • 19. Summary Strongly-typednaturallanguageengine Compile time checking, inheritance, … Definetokens and sentences (rules) in C# Strongly-typedtokens: numbers, percentages, times, dates, file names, urls, people, business objects, … Builds an efficient parse graph Tracks conversation history
  • 20. Future plans Expanded corpus of knowledge Companynames, locations, documents, … Performance improvements Onlytryparsingtokensvalid for currentparsetree state .NET 4 Optional Arguments Account for these in reflection code duringparsetreecreation GenerateiCal/GdataRecurrence FromTimeExpressions
  • 21. For more information Visit http://blog.abodit.com Contact ian@abodit.com