liveBook · Manning

Pattern-based approach

As explained in Natural Language Processing in Action, Second Edition

A conversational processing system whose behavior is determined primarily by matching predefined text patterns.

A pattern-based approach makes a conversational system respond by matching predefined character, word-sequence, or higher-level language patterns. A match triggers a scripted response or extracts useful information. section 1.5.2 section 1.4.2

The method is practical when inputs are predictable: regular expressions can recognize greetings, identify a name, and select an appropriate reply. Its brittleness appears when wording contains typos or variations that do not match the rules. section 1.4 section 1.5.2

A pattern-based system can:

  • Match character sequences with regular expressions. section 1.4
  • Recognize word sequences, parts of speech, and other higher-level patterns. section 1.5.2
  • Stay quiet or alter its response when rules detect who is being addressed. section 1.5.2

A greeting recognizer

A Python regular expression such as `(hi|hello|hey)[ ,:.!]*([a-z]*)` recognizes greetings and captures a following name. A more elaborate version handles phrases such as “Good morning Rosa,” “Good evening Rosa Parks,” and “yo Rosa,” while rejecting “Good Manning Rosa.”

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains regex matching, captured information, and rule limitations, while deferring deeper finite-state-machine theory and mathematics.
Examples
Uses Python greeting regexes, captured names, conversational addressing rules, and chatbot systems such as ELIZA, Will, and qary.
What it assumes
Assumes basic programming and text handling, while introducing regular expressions, finite-state machines, and pattern-based NLP incrementally.
What you can do after
Builds a small rule-driven chatbot that recognizes greetings, extracts names, and chooses responses with Python regular expressions.
How it connects
Connects regular expressions with finite state machines, regular grammars, tokenizers, stemmers, chatbots, and deep learning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.