Chatterbot: Integrating jinja2 templates into corpus

Created on 18 Dec 2016  路  9Comments  路  Source: gunthercox/ChatterBot

With reference #469 I felt introducing jinja2 template into corpus, A more useful to users and developers.

An example located here https://gist.github.com/sevennineteen/4400462

@gunthercox any comments/suggestion before implementing this feature?

Most helpful comment

Unfortunately I don't have a concise answer for either of your questions.

As a long-term solution, it might work well, or it might have unexpected
conflicts with a future item called Personas. Personas will be
representations of personality for both users and chat bots. I think some
of your recent comments and pull requests hint upon the necessity of this
functionality but unfortunately it is not a feature that I have had time to
fully plan out yet.

All 9 comments

I like the idea of having some kind of templateing functionality. However, I don't think that the corpus is the right place to have this feature. ChatterBot's corpus is intended to a be a source of raw data (examples of conversations, bits of factual information, etc.).

Agreed, By making another directory templates will make a separation from raw data,

|-- corpus/
|
|---- data/
|----- conversation.corups.json
|---- templates/
|----- conversation.temp.corpus.json
def read_corpus_from_template(self, template_file_name)

A separate directory definitely sounds better.

Got other ideas, Instead modifying everythin can write like this

Questions:

  1. Will it work as a long term solution?
  2. will address template mechanism?

I will document this, soon

{
    "conversations": [
        [
            "What's you name",
            "{{bot.name}}"
        ],
        [
            "How many years",
            "{{bot.years}}"
        ]   
    ]
}

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from jinja2 import Environment, FileSystemLoader
import json
import os

# Jinja2 corpus template
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
env = Environment(loader=FileSystemLoader(THIS_DIR), trim_blocks=True)
properties = {"name":"Chatterbot" , "years":2}
corpus_template = env.get_template('example.corpus.json').render(bot=properties)
print(corpus_template)
corpus_data = json.loads(corpus_template)

# Train chatterbot
chatterbot = ChatBot("Template Training Example")
chatterbot.set_trainer(ListTrainer)
for pair in corpus_data['conversations']:
    chatterbot.train(pair)

Unfortunately I don't have a concise answer for either of your questions.

As a long-term solution, it might work well, or it might have unexpected
conflicts with a future item called Personas. Personas will be
representations of personality for both users and chat bots. I think some
of your recent comments and pull requests hint upon the necessity of this
functionality but unfortunately it is not a feature that I have had time to
fully plan out yet.

@gunthercox Agreed totally with you, If above example will be useful others, i will add this example in example section.

I really liked Personas Any future plans on this.

I don't think the above example is needed in the example section right at the moment.

I don't think I've documented the idea for personas anywhere yet. I will be sure to do so soon.

Thank you

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuvalBor picture yuvalBor  路  3Comments

proguy627 picture proguy627  路  3Comments

decode007 picture decode007  路  4Comments

ArunSingh1 picture ArunSingh1  路  3Comments

decode007 picture decode007  路  3Comments