Skip to content

Commit

Permalink
Merge pull request #23 from DLR-SC/develop
Browse files Browse the repository at this point in the history
Working fine with the RasaNLU + RasaCore versions
  • Loading branch information
chmodsss authored Jun 27, 2019
2 parents e5b6c35 + 120bb15 commit ac5fd9f
Show file tree
Hide file tree
Showing 9 changed files with 1,029 additions and 1,029 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ This system take input as request/command and returns neo4j graph database query

This project is developed and tested in Ubuntu 16.04

For easier installation, clone this repository, create new ```python 3.6.5``` environment and execute: ```pip install -r requirements.txt```
For easier installation, clone this repository, create new `python 3.6.5` environment and execute: `pip install -r requirements.txt`

To install spacy language module: ```python -m spacy download en```
To install spacy language module: `python -m spacy download en`

To install neo4j follow: [Installation neo4j guidelines in Ubuntu 16.04](https://datawookie.netlify.com/blog/2016/09/installing-neo4j-on-ubuntu-16.04/)

## Steps

* First convert json to neo4j by executing ```neo4j/JsonToNeo4j.py``` (Remember to start the neo4j server and configure it)
* Navigate to SentenceToQuery directory, now in one terminal: Run ``` python train_rasa_module.py 'train-all' ``` to train and save the rasa nlu and core models
* Start neo4j server `service neo4j start`
* To convert json to neo4j
* `cd neo4j`
* `python JsonToNeo4j.py username password` (Use neo4j username and password)
* Navigate to SentenceToQuery directory and run `python train_rasa_module.py 'train-all'` to train and save the rasa nlu and core models
**If models are already saved, then this step is optional**
* In second terminal: Run action server using ``` python -m rasa_core_sdk.endpoint --actions actions ```
* In third terminal: Pass user messages and end points to rasa core using:
``` python -m rasa_core.run -d models/dialogue -u projects/default/default/Neo4jNlu --endpoints endpoints.yml ```
* Now you can pass the messages as [shown here](https://github.com/Pseipel/Island-Voiz#general-conversation-examples) to the bot and wait for the responses
* Now run action server using `python -m rasa_core_sdk.endpoint --actions actions`
* In another terminal, Pass user messages and end points to rasa core using:
`python train_rasa_module.py 'bot'` or `python -m rasa_core.run -d models/dialogue -u projects/default/default/Neo4jNlu --endpoints endpoints.yml`
* Now you can pass the messages as shown below

## Information about how sentences are converted to Neo4j query can be found here: ![SentenceToQuery](https://github.com/DLR-SC/RiQue/tree/master/SentenceToQuery)

Expand Down
75 changes: 56 additions & 19 deletions SentenceToQuery/actions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
from response_builder import ResponseBuilder
from query_generator import GenerateQuery
import json

response_builder = ResponseBuilder()


class DisplayGeneralQuery(Action):

Expand All @@ -13,13 +10,15 @@ def name(self):
return "action_give_project_information"

def run(self, dispatcher, tracker, domain):
response = dict()
query = None
intent = tracker.latest_message['intent']
error = None
if tracker.get_slot('project'):
response = response_builder.get_query(tracker)
query = GenerateQuery.get_project_information(tracker.get_slot('project'))
else:
response['error'] = "no project slot is filled inside action give project information action"
error = "no project slot is filled inside action give project information action"
response = ResponseBuilderUtils.build_response(query, intent, error)
dispatcher.utter_message(json.dumps(response))

return []


Expand All @@ -30,11 +29,15 @@ def name(self):
return "action_show_detail_info_bundles"

def run(self, dispatcher, tracker, domain):
response = dict()
if tracker.get_slot('bundles'):
response = response_builder.get_query(tracker)
query = None
intent = tracker.latest_message['intent']
error = None
if tracker.get_slot('bundle'):
query_aspect = tracker.get_slot('nodeType')
query = GenerateQuery.get_detailed_bundle_info_query(tracker.get_slot('bundle'), query_aspect)
else:
response['error'] = "no bundles slot filled inside show detailed bundle project info"
error = "no bundles slot filled inside show detailed bundle project info"
response = ResponseBuilderUtils.build_response(query, intent, error)
dispatcher.utter_message(json.dumps(response))

return []
Expand All @@ -52,7 +55,11 @@ def name(self):
return "action_show_largest_compilationUnit"

def run(self, dispatcher, tracker, domain):
response = response_builder.get_query(tracker)
intent = tracker.latest_message['intent']
bundle_name = tracker.get_slot('bundle')
order = tracker.get_slot('nodeType')
query = GenerateQuery.get_largest_compilation_unit_query(bundle_name, order)
response = ResponseBuilderUtils.build_response(query, intent)
dispatcher.utter_message(json.dumps(response))
return []

Expand All @@ -69,13 +76,21 @@ def name(self):
return "action_show_node_information"

def run(self, dispatcher, tracker, domain):
response = dict()
intent = tracker.latest_message['intent']
query = None
error = None
if tracker.get_slot('node'):
response = response_builder.get_query(tracker)
query = GenerateQuery.get_node_information_query(tracker.get_slot('node'))
elif tracker.get_slot('bundle'):
print("bundle:" + tracker.get_slot('bundle'))
query = GenerateQuery.get_node_information_query(tracker.get_slot('bundle'), 'bundles')
elif tracker.get_slot('compilationUnit'):
print("compilationunit:" + tracker.get_slot('compilationUnit'))
query = GenerateQuery.get_node_information_query(tracker.get_slot('compilationUnit'), 'compilationUnit')
else:
response['error'] = "no node slot filled inside action show node information"
error = "no node slot filled inside action show node information"
response = ResponseBuilderUtils.build_response(query, intent, error)
dispatcher.utter_message(json.dumps(response))

return []


Expand All @@ -91,7 +106,12 @@ def name(self):
return "action_show_all_nodes"

def run(self, dispatcher, tracker, domain):
response = response_builder.get_query(tracker)
intent = tracker.latest_message['intent']
if tracker.get_slot('nodeType'):
query = GenerateQuery.get_show_all_nodes_query(tracker.get_slot('nodeType'))
else:
query = GenerateQuery.get_show_all_nodes_query()
response = ResponseBuilderUtils.build_response(query, intent)
dispatcher.utter_message(json.dumps(response))
return []

Expand All @@ -108,7 +128,24 @@ def name(self):
return "action_count_all_nodes"

def run(self, dispatcher, tracker, domain):
response = response_builder.get_query(tracker)
intent = tracker.latest_message['intent']
if tracker.get_slot('nodeType'):
query = GenerateQuery.get_count_all_nodes_query(tracker.get_slot('nodeType'))
else:
query = GenerateQuery.get_count_all_nodes_query()
response = ResponseBuilderUtils.build_response(query, intent)
dispatcher.utter_message(json.dumps(response))
return []


class ResponseBuilderUtils:

@staticmethod
def build_response(query, intent, error=None):
response = dict()
if error:
response['error'] = error
response['query'] = query
response['intent'] = intent
return response

9 changes: 3 additions & 6 deletions SentenceToQuery/domain.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
slots:
bundles:
bundle:
type: text

packages:
package:
type: text

services:
type: text

project:
type: text
initial_value: 'remote component environment'
Expand All @@ -18,7 +15,7 @@ slots:
compilationUnit:
type: text

methods:
nodeType:
type: text


Expand Down
Loading

0 comments on commit ac5fd9f

Please sign in to comment.