From 1b68e726570d23da076f87561f7f4b9d5638a37c Mon Sep 17 00:00:00 2001 From: Tanja Bergmann Date: Fri, 5 Jul 2019 11:06:41 +0200 Subject: [PATCH] Fix issues from test run. --- .gitignore | 5 +++++ README.md | 4 +++- actions.py | 14 +++++++++++--- constants.py | 6 ------ data/stories.md | 2 +- graph_database.py | 20 +++----------------- requirements.txt | 4 ++-- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 894a44c..9e327a4 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,8 @@ venv.bak/ # mypy .mypy_cache/ + +# rasa +models +rasa.db +tracker.db/ diff --git a/README.md b/README.md index 3ab12aa..4d7aad4 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,11 @@ pip install -r requirements.txt Our knowledge base is represented by a graph database. In this repository [Grakn](https://grakn.ai/) is used as a graph database. +However, you can also use any other graph database or even write your domain knowledge into a dictionary in the python code directly. + +In order to use this code example, you need to install [Grakn](https://grakn.ai/). Please check the [installation instruction](https://dev.grakn.ai/docs/running-grakn/install-and-run) of Grakn in order to install it. - Once you installed Grakn, you need to start the Grakn server by executing ```bash grakn server start diff --git a/actions.py b/actions.py index 012c0f5..5a85f2c 100644 --- a/actions.py +++ b/actions.py @@ -210,7 +210,11 @@ def run(self, dispatcher, tracker, domain): if name is None or attribute is None: dispatcher.utter_template("utter_rephrase", tracker) - return [SlotSet(entity_type, None)] + return [ + SlotSet(entity_type, None), + SlotSet('mention', None), + SlotSet('attribute', None) + ] # query knowledge base key_attribute = schema[entity_type]["key"] @@ -228,8 +232,12 @@ def run(self, dispatcher, tracker, domain): f"Did not found a valid value for attribute {attribute} for entity '{name}'." ) - # reset slot of entity type, because TODO - return [SlotSet(entity_type, None)] + # reset slots + return [ + SlotSet(entity_type, None), + SlotSet('mention', None), + SlotSet('attribute', None) + ] class ActionCompareEntities(Action): diff --git a/constants.py b/constants.py index e435c1b..e190292 100644 --- a/constants.py +++ b/constants.py @@ -1,9 +1,3 @@ -from graph_database import GraphDatabase - - -me = GraphDatabase.get_random_person() - - schema = { "transaction": { "attributes": ["category", "execution-date", "amount", "reference"], diff --git a/data/stories.md b/data/stories.md index aa038a4..7172dc9 100644 --- a/data/stories.md +++ b/data/stories.md @@ -31,7 +31,7 @@ - action_compare_entities * query_attribute - action_query_attribute - - slot{"transactions": null} + - slot{"transaction": null} * query_attribute - action_query_attribute * bye diff --git a/graph_database.py b/graph_database.py index 25456f7..c1b63f9 100644 --- a/graph_database.py +++ b/graph_database.py @@ -4,8 +4,6 @@ import grakn -from constants import me - logger = logging.getLogger(__name__) @@ -13,7 +11,7 @@ class GraphDatabase: def __init__(self, uri: Text = "localhost:48555", keyspace: Text = "banking"): self.client = grakn.Grakn(uri=uri) self.keyspace = keyspace - self.me = me + self.me = "mitchell.gillis@t-online.de" def _thing_to_dict(self, thing): """ @@ -81,18 +79,6 @@ def _execute_relation_query( return relations - @staticmethod - def get_random_person(): - """ - Get a random person of the bank that represents 'me'. - - :return: a random person from the knowledge base - """ - - graph = GraphDatabase() - people = graph._execute_entity_query(f"match $x isa person; get;") - return people[random.randint(0, len(people) - 1)] - def _get_me_clause(self, entity_type: Text) -> Text: """ Construct the me clause. Needed to only list, for example, accounts that are @@ -107,9 +93,9 @@ def _get_me_clause(self, entity_type: Text) -> Text: # do not add the me clause to a query asking for banks or people as they are # independent of the accounts related to me - if self.me is not None and entity_type not in ["person", "bank"]: + if entity_type not in ["person", "bank"]: clause = ( - f"$person isa person, has email '{self.me['email']}';" + f"$person isa person, has email '{self.me}';" f"$contract(customer: $person, offer: $account, provider: $bank) isa contract;" ) return clause diff --git a/requirements.txt b/requirements.txt index c71cbd2..dd9b849 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -rasa-sdk~=1.1 -rasa~=1.1.4 +rasa-sdk==1.1 +rasa==1.1.4 grakn==1.4.2 \ No newline at end of file