Skip to content

A chatbot for knowledge base question answeing using pattern matching method

Notifications You must be signed in to change notification settings

MangoPomelo/PatternMatchingQA

Repository files navigation

Pattern Matching QA

This project is a pattern matching question answering script demo, which is simple enough to consider as a baseline approach or a tutorial.

How does it work

  1. Take the sentence from command line
  2. Every word in the sentence will be scanned by a list of EntityKeywordDictionaries and RelationshipKeywordDictionaries, which then triggers the classification strategy to transform it into labels
    • For example, sentence like "What is Amantadine used to treat?" would trigger the Cure keyword (as Relationship) and Drug keyword (as Entity)
    • According to the classification strategy, this sentence will be transformed into a drug_disease relationship label and Amantadine entity label
  3. Since the entity and relationship have been determined, the query will be constructed and send to a database or even a file to get the answer
  4. Prompt the answer back to the command line
sequenceDiagram
    Actor User
    User->>+Chatbot: raw sentence
    Chatbot->>+Classifier: raw sentence
    Classifier->>+RelationshipPicker: raw sentence
    RelationshipPicker-->>-Classifier: relationships
    Classifier->>+EntityPicker: raw sentence
    EntityPicker-->>-Classifier: entities
    Classifier-->>Chatbot: question type (inferred from relationships)
    Classifier-->>-Chatbot: entity dict (entities)
    Chatbot->>+SQLParser: question type and entity dict
    SQLParser-->>-Chatbot: parsed SQL command
    Chatbot->>-User: parsed SQL command
Loading

How to run it

Run python3 .\Chatbot.py in command line only to start the integration test. To start a conversation, you have to add a while loop into the main function of Chatbot.py

Configuration

The way to adapt a specific database

There is no configuration file, any adaption must be done by modifying the Parser.py

The way to add more classification strategies

Add keyword dictionaries manually, then change the process in Classifier.py

About

A chatbot for knowledge base question answeing using pattern matching method

Topics

Resources

Stars

Watchers

Forks

Languages