Skip to content

Commit

Permalink
Fix issues from test run.
Browse files Browse the repository at this point in the history
  • Loading branch information
tabergma committed Jul 5, 2019
1 parent ebc4b75 commit 1b68e72
Showing 7 changed files with 25 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -102,3 +102,8 @@ venv.bak/

# mypy
.mypy_cache/

# rasa
models
rasa.db
tracker.db/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 11 additions & 3 deletions actions.py
Original file line number Diff line number Diff line change
@@ -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):
6 changes: 0 additions & 6 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from graph_database import GraphDatabase


me = GraphDatabase.get_random_person()


schema = {
"transaction": {
"attributes": ["category", "execution-date", "amount", "reference"],
2 changes: 1 addition & 1 deletion data/stories.md
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
- action_compare_entities
* query_attribute
- action_query_attribute
- slot{"transactions": null}
- slot{"transaction": null}
* query_attribute
- action_query_attribute
* bye
20 changes: 3 additions & 17 deletions graph_database.py
Original file line number Diff line number Diff line change
@@ -4,16 +4,14 @@

import grakn

from constants import me

logger = logging.getLogger(__name__)


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 = "[email protected]"

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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rasa-sdk~=1.1
rasa~=1.1.4
rasa-sdk==1.1
rasa==1.1.4
grakn==1.4.2

0 comments on commit 1b68e72

Please sign in to comment.