pykoi.chat.db package#
Submodules#
pykoi.chat.db.abs_database module#
abs database
- class pykoi.chat.db.abs_database.AbsDatabase(db_file: str, debug: bool = False)[source]#
Bases:
object
Base Database class
- create_table(query: str) None [source]#
Creates the table if it does not already exist in the database.
- Parameters:
query (str) – The SQL query to create the table.
- abstract insert(**kwargs) None [source]#
Inserts into the database.
- Parameters:
kwargs (dict) – The key-value pairs to insert into the database.
pykoi.chat.db.comparator_database module#
Comparator Database
- class pykoi.chat.db.comparator_database.ComparatorDatabase(db_file: str = '/Users/joseortiz/Coding/CambioML/pykoi/docs/comparator.db', debug: bool = False)[source]#
Bases:
AbsDatabase
ComparatorDatabase class.
- insert(**kwargs) None [source]#
Inserts a new row into the comparator table.
- Parameters:
kwargs (dict) – The key-value pairs to insert into the database.
- print_table(rows: List[Tuple]) None [source]#
Prints the comparator table.
- Parameters:
rows (list) – A list of tuples where each tuple represents a row in the table. Each tuple contains five elements: ID, Model, QID, Rank, Answer, Timestamp.
- class pykoi.chat.db.comparator_database.ComparatorQuestionDatabase(db_file: str = '/Users/joseortiz/Coding/CambioML/pykoi/docs/comparator.db', debug: bool = False)[source]#
Bases:
AbsDatabase
Comparator Question Database class
- insert(**kwargs) None [source]#
Inserts question, timestamp into the database.
- Parameters:
kwargs (dict) – The key-value pairs to insert into the database.
- Returns:
The ID of the newly inserted row.
- Return type:
int
- print_table(rows: List[Tuple]) None [source]#
Prints the contents of the table in a formatted manner.
- Parameters:
rows (list) – A list of tuples where each tuple represents a row in the table. Each tuple contains five elements: ID, Question.
pykoi.chat.db.constants module#
database constants
pykoi.chat.db.qa_database module#
Question answer database module
- class pykoi.chat.db.qa_database.QuestionAnswerDatabase(db_file: str = '/Users/joseortiz/Coding/CambioML/pykoi/docs/qd.db', debug: bool = False)[source]#
Bases:
object
Question Answer Database class
- create_table()[source]#
Creates the question_answer table if it does not already exist in the database. The table has four columns: id (primary key), question, answer, and vote_status. vote_status is a text field that can only have the values ‘up’, ‘down’, or ‘n/a’.
- insert_question_answer(question: str, answer: str)[source]#
Inserts a new question-answer pair into the database with the given question and answer. The vote_status field is set to ‘n/a’ by default. Returns the ID of the newly inserted row.
- Parameters:
question (str) – The question to insert.
answer (str) – The answer to insert.
- Returns:
The ID of the newly inserted row.
- Return type:
int
- print_table(rows)[source]#
Prints the contents of the table in a formatted manner.
- Parameters:
rows (list) – A list of tuples where each tuple represents a row in the table. Each tuple contains five elements: ID, Question, Answer, Timestamp, and Vote Status.
- retrieve_all_question_answers()[source]#
Retrieves all question-answer pairs from the database.
- Returns:
A list of tuples representing the question-answer pairs.
- Return type:
list
- retrieve_all_question_answers_as_pandas()[source]#
Retrieves all question-answer pairs from the database as a pandas dataframe.
- Returns:
A pandas dataframe.
- Return type:
DataFrame
- save_to_csv(csv_file_name='question_answer_votes.csv')[source]#
This method saves the contents of the question_answer table into a CSV file.
- Parameters:
csv_file_name (str, optional) – The name of the CSV file to which the data will be written.
"question_answer_votes.csv". (Defaults to) –
The CSV file will have the following columns: ID, Question, Answer, Vote Status. Each row in the CSV file corresponds to a row in the question_answer table.
This method first retrieves all question-answer pairs from the database by calling the retrieve_all_question_answers method. It then writes this data to the CSV file.
- update_vote_status(id, vote_status)[source]#
Updates the vote status of a question-answer pair with the given ID.
- Parameters:
id (int) – The ID of the question-answer pair to update.
vote_status (str) – The new vote status to set. Must be one of ‘up’, ‘down’, or ‘n/a’.
- Raises:
ValueError – If the question with the given ID does not exist.
pykoi.chat.db.ranking_database module#
This file contains the RankingDatabase class which is used to store and retrieve
- class pykoi.chat.db.ranking_database.RankingDatabase(db_file: str = '/Users/joseortiz/Coding/CambioML/pykoi/docs/ranking.db', debug: bool = False)[source]#
Bases:
object
Ranking Database class
- create_table()[source]#
Creates the ranking table if it does not already exist in the database. The table has four columns: id (primary key), question, up_ranking_answer, and low_ranking_answer.
- insert_ranking(question: str, up_ranking_answer: str, low_ranking_answer: str)[source]#
Inserts a new ranking entry into the database with the given question, up_ranking_answer, and low_ranking_answer.
- Parameters:
question (str) – The question of the ranking entry.
up_ranking_answer (str) – The higher ranked answer of the ranking entry.
low_ranking_answer (str) – The lower ranked answer of the ranking entry.
- Returns:
The ID of the newly inserted row.
- Return type:
int
- print_table(rows)[source]#
Prints the contents of the table in a formatted manner.
- Parameters:
rows (list) – A list of tuples where each tuple represents a row in the table. Each tuple contains four elements: ID, Question, Up_Ranking_Answer, Low_Ranking_Answer.
- retrieve_all_question_answers()[source]#
Retrieves all question-answer pairs from the database.
- Returns:
A list of tuples representing the question-answer pairs.
- Return type:
list
- retrieve_all_question_answers_as_pandas()[source]#
Retrieves pairs from the database as a pandas dataframe.
- Returns:
A pandas dataframe.
- Return type:
DataFrame
- save_to_csv(csv_file_name='ranking_data.csv')[source]#
Saves the contents of the ranking table into a CSV file.
- Parameters:
csv_file_name (str, optional) – The name of the CSV file to which the data will be written.
"ranking_data.csv". (Defaults to) –
The CSV file will have the following columns: ID, Question, Up_Ranking_Answer, Low_Ranking_Answer. Each row in the CSV file corresponds to a row in the ranking table.
This method retrieves all ranking entries from the database by calling the retrieve_all_question_answers method. It then writes this data to the CSV file.