API

class Answer

Answer wrapper.

Outputs OK or error messages to ROS.

Public Static Functions

static String org.roboy.memory.util.Answer.ok()

Answer for ROS if no errors were detected.

Return
JSON object {status:”OK”} to ROS

static String org.roboy.memory.util.Answer.error(String message)

Answer for ROS if an error occurred.

Return
JSON object containing status and message
Parameters
  • message: contains the error message according to the obstacle approached

Private Static Attributes

Logger org.roboy.memory.util.Answer.logger = Logger.getLogger(Answer.class.toString())
class Config

Configuration for ROS, Neo4J and Redis Server connectivity.

Public Static Attributes

final String org.roboy.memory.util.Config.ROS_MASTER_URI = "http://127.0.0.1:11311/"

ROS Configuration.

IP adress of the PC with roscore

final String org.roboy.memory.util.Config.ROS_HOSTNAME = "127.0.0.1"

IP address of the current PC in the network.

final String org.roboy.memory.util.Config.NEO4J_ADDRESS = "bolt://127.0.0.1:7687"

Neo4J Configuration.

Neo4j DB location

final String org.roboy.memory.util.Config.NEO4J_USERNAME = "***"

Neo4j instance username.

final String org.roboy.memory.util.Config.NEO4J_PASSWORD = "***"

Neo4j instance password.

final String org.roboy.memory.util.Config.REDIS_URI = "redis://127.0.0.1:6379/0"

Redis Configuration.

Redis storage location

final String org.roboy.memory.util.Config.REDIS_PASSWORD = "***"

Redis storage instance password.

final String [] org.roboy.memory.util.Config.LABEL_VALUES = new String[] { "Person","Robot","Company","University","City","Country","Hobby","Occupation","Object" }

KR Entries Configuration.

Available label types

final String [] org.roboy.memory.util.Config.RELATION_VALUES = new String[] { "FRIEND_OF","LIVE_IN","FROM","WORK_FOR","STUDY_AT","MEMBER_OF","HAS_HOBBY","KNOW","IS","PART_OF","IS_IN" }

Available reltionship types.

class Create

Data model for JSON parser.

Creates objects, that contain the elements of the Create queries.

Public Functions

String org.roboy.memory.models.Create.getLabel()
String org.roboy.memory.models.Create.getType()
Map<String, String> org.roboy.memory.models.Create.getProperties()
String [] org.roboy.memory.models.Create.getFace()

Private Members

String org.roboy.memory.models.Create.type

Currently only used to specify the type “node”.

String org.roboy.memory.models.Create.label

Specifies the type of node that shall be created, like “Person”.

String [] org.roboy.memory.models.Create.faceVector

JSON array containing facial features from vision module.

Map<String, String> org.roboy.memory.models.Create.properties

Contains the node properties.

class Get

Data model for JSON parser.

Creates objects, that contain the elements of the Get queries.

Public Functions

int org.roboy.memory.models.Get.getId()
String org.roboy.memory.models.Get.getLabel()
Map<String, String[]> org.roboy.memory.models.Get.getRelations()
Map<String, String> org.roboy.memory.models.Get.getProperties()

Private Members

String org.roboy.memory.models.Get.label

Specifies the type of node that shall be searched, like “Person”.

int org.roboy.memory.models.Get.id

The id of a node that shall be searched.

Map<String, String[]> org.roboy.memory.models.Get.relations

Contains the relationship type as key and an array of node IDs as value.

Map<String, String> org.roboy.memory.models.Get.properties

Contains the node properties.

class Header

Data model for JSON parser.

Creates objects, that contain the elements of the Header.

Public Functions

LocalDateTime org.roboy.memory.models.Header.getDateTime()
String org.roboy.memory.models.Header.getUser()

Private Members

String org.roboy.memory.models.Header.user

Contains the module which is sending the query, for example “vision”.

String org.roboy.memory.models.Header.datetime

Contains a timestamp in seconds since 1.1.1970.

class Main

Public Static Functions

static void org.roboy.memory.Main.main(String[] args)
class Neo4j

Contains the methods for running GET, CREATE, UPDATE, REMOVE and Cypher queries.

Talks to the Neo4j and Redis databases. Handles the result retrieved from Neo4j.

Inherits from AutoCloseable

Public Functions

void org.roboy.memory.util.Neo4j.close()

Public Static Functions

static Driver org.roboy.memory.util.Neo4j.getInstance()

Singleton for the Neo4j class.

Return
Neo4J Driver instance if the object of Neo4j class is initialized

static Value org.roboy.memory.util.Neo4j.parameters(Object... keysAndValues)

Wrapper for the Neo4j query parameters.

Return
Set of keys and values for parameters

static String org.roboy.memory.util.Neo4j.run(String query)

Method to channel a plain Cypher query to Neo4j.

Return
plain response from Neo4j
Parameters
  • query: formed in Cypher

static String org.roboy.memory.util.Neo4j.createNode(String label, String[] faceVector, Map< String, String > properties)

Method accepting JSON Create queries.

Return
result obtained by createNode method
Parameters
  • label: is denoting a type of the node to be created
  • faceVector: contains face features for a node of label “Person”. OPTIONAL
  • properties: is a dictionary containing properties of the node

static String org.roboy.memory.util.Neo4j.updateNode(int id, Map< String, String[]> relations, Map< String, String > properties)

Method accepting JSON Update queries.

Return
result obtained by update method
Parameters
  • id: is a unique pointer to the node in Neo4j DB
  • relations: is a dictionary containing relationships of the node with other nodes
  • properties: is a dictionary containing properties of the node

static String org.roboy.memory.util.Neo4j.getNodeById(int id)

Method accepting JSON Get by ID queries.

Return
result obtained by matchNodeById method
Parameters
  • id: is a unique pointer to the node in Neo4j DB

static String org.roboy.memory.util.Neo4j.getNode(String label, Map< String, String[]> relations, Map< String, String > properties)

Method accepting JSON Get IDs of nodes queries.

Return
result obtained by matchNode method
Parameters
  • label: is denoting a type of the nodes to be included
  • relations: is a dictionary containing relationships of the nodes with other nodes
  • properties: is a dictionary containing properties of the nodes

static String org.roboy.memory.util.Neo4j.remove(int id, Map< String, String[]> relations, String[] properties)

Method accepting JSON Remove queries.

Return
result obtained by removeRelsProps method
Parameters
  • id: of the node which relations and properties need to be removed
  • relations: is a dictionary containing relationships of the node with other nodes
  • properties: is a dictionary containing properties of the node

Private Functions

org.roboy.memory.util.Neo4j.Neo4j()
Driver org.roboy.memory.util.Neo4j.getDriver()

Getter for the Neo4j driver instance.

Return
Neo4J Driver instance

Private Static Functions

static String org.roboy.memory.util.Neo4j.createNode(Session session, Map< String, String > properties, String[] faceVector, String label)

Method processing JSON Create queries.

Return
ID of the node that was created in Neo4j DB
Parameters
  • session: is a session handler for transaction handling to query Neo4j DB
  • label: is denoting a type of the node to be created
  • faceVector: contains face features for a node of label “Person”. OPTIONAL
  • properties: is a dictionary containing properties of the node

static String org.roboy.memory.util.Neo4j.update(Transaction tx, int id, Map< String, String[]> relations, Map< String, String > properties)

Method processing JSON Update queries.

Return
response from Neo4j upon updating the node
Parameters
  • tx: is a transaction handler to query Neo4j DB
  • id: is a unique pointer to the node in Neo4j DB
  • relations: is a dictionary containing relationships of the node with other nodes
  • properties: is a dictionary containing properties of the node

static String org.roboy.memory.util.Neo4j.matchNodeById(Transaction tx, int id)

Method processing JSON Get by ID queries.

Return
a JSON object containing node labels, properties and relationships
Parameters
  • tx: is a transaction handler to query Neo4j DB
  • id: is a unique pointer to the node in Neo4j DB

static String org.roboy.memory.util.Neo4j.matchNode(Transaction tx, String label, Map< String, String[]> relations, Map< String, String > properties)

Method processing JSON Get IDs of nodes queries.

Return
JSON array of nodes’ IDs
Parameters
  • tx: is a transaction handler to query Neo4j DB
  • label: is denoting a type of the nodes to be included
  • relations: is a dictionary containing relationships of the nodes with other nodes
  • properties: is a dictionary containing properties of the nodes

static String org.roboy.memory.util.Neo4j.removeRelsProps(Transaction tx, int id, Map< String, String[]> relations, String[] properties)

Method processing JSON Remove queries.

Return
response from Neo4j upon removing the specified relations and properties
Parameters
  • tx: is a transaction handler to query Neo4j DB
  • id: of the node which relations and properties need to be removed
  • relations: is a dictionary containing relationships of the node with other nodes
  • properties: is a dictionary containing properties of the node

Private Static Attributes

Neo4j org.roboy.memory.util.Neo4j._instance

An instance of the class.

Driver org.roboy.memory.util.Neo4j._driver

An instance of Neo4j driver.

Jedis org.roboy.memory.util.Neo4j.jedis

An instance of Jedis for Redis handling.

Gson org.roboy.memory.util.Neo4j.parser = new Gson()

An instance of Gson parser for creating JSON response.

Logger org.roboy.memory.util.Neo4j.logger = Logger.getLogger(Neo4j.class.toString())

An instance of the logger.

class Remove

Data model for JSON parser.

Creates objects, that contain the elements of the Remove queries.

Public Functions

int org.roboy.memory.models.Remove.getId()
String [] org.roboy.memory.models.Remove.getProperties()
Map<String, String[]> org.roboy.memory.models.Remove.getRelations()

Private Members

int org.roboy.memory.models.Remove.id

The id of a node that shall be modified.

String org.roboy.memory.models.Remove.type

Currently only used to specify the type “node”.

String org.roboy.memory.models.Remove.label

Specifies the type of node that shall be removes, like “Person”.

Map<String, String[]> org.roboy.memory.models.Remove.relations

Contains the relationship type as key and an array of node IDs as value.

String [] org.roboy.memory.models.Remove.properties

Contains the node properties.

class RosNode

ROS Service for saving data object to DB.

Data is received as JSON object. JSON object is parsed using Parser and saved to neo4j.

Inherits from AbstractNodeMain

Public Functions

GraphName org.roboy.memory.ros.RosNode.getDefaultNodeName()
void org.roboy.memory.ros.RosNode.onStart(ConnectedNode connectedNode)

Initialising the ROS services and setting ROS services URIs.

Parameters
  • connectedNode: is the ROS node carrying the services.

Package Static Functions

static void org.roboy.memory.ros.RosNode.register(NodeConfiguration nodeConfiguration, NodeMainExecutor nodeMainExecutor)

Registers the ROS node.

Parameters
  • nodeConfiguration: is the ROS node configurator
  • nodeMainExecutor: is the ROS node executor

Private Static Attributes

String org.roboy.memory.ros.RosNode.name = "/roboy/cognition/memory"

URI for the ROS node.

class RosRun

This server is responsible for starting ros services.

Public Functions

org.roboy.memory.ros.RosRun.RosRun()

Constructor.

Initializes the ROS node.

void org.roboy.memory.ros.RosRun.start()

Registers the ROS node with services in the network.

void org.roboy.memory.ros.RosRun.stop()

Shutdowns the ROS node and terminates the services.

Private Members

NodeMainExecutor org.roboy.memory.ros.RosRun.nodeMainExecutor

ROS executor.

NodeConfiguration org.roboy.memory.ros.RosRun.nodeConfiguration

ROS node configurator.

class ServiceLogic

Contains service handlers to talk with ROS.

They parse the header and payload and check for invalid elements in the query. Then the functions to construct the cypher queries are excecuted and the answer returned.

Package Static Attributes

ServiceResponseBuilder<DataQueryRequest, DataQueryResponse> org.roboy.memory.ros.ServiceLogic.createServiceHandler = (request, response) -> { Header header = parser.fromJson(request.getHeader(), Header.class); Create create = parser.fromJson(request.getPayload(), Create.class); if (create.getFace() != null) { System.out.println("FaceVector: " + create.getFace().toString()); } if (create.getProperties() == null) { response.setAnswer(error("no properties")); return; } else if (!create.getProperties().containsKey("name")){ response.setAnswer(error("no name specified in properties : name required")); return; } else if (create.getLabel() != null && !labels.contains(create.getLabel().substring(0,1).toUpperCase() + create.getLabel().substring(1).toLowerCase())) { response.setAnswer(error("Label '" + create.getLabel() + "' doesn't exist in the DB")); return; } else { response.setAnswer(Neo4j.createNode(create.getLabel(), create.getFace(), create.getProperties())); } }

Create Service Handler.

Parses the header and payload into a create object with Gson and checks for invalid elements in the query. Calls createNode() method to query Neo4j and the answer is returned.

ServiceResponseBuilder<DataQueryRequest, DataQueryResponse> org.roboy.memory.ros.ServiceLogic.updateServiceHandler = (request, response) -> { Header header = parser.fromJson(request.getHeader(), Header.class); Update update = parser.fromJson(request.getPayload(), Update.class); if(update.getRelations() != null) { for (String rel : update.getRelations().keySet()) { if (!relations.contains(rel.toUpperCase())) { response.setAnswer(error("The relationship type '" + rel + "' doesn't exist in the DB")); return; } } } Neo4j.updateNode(update.getId(), update.getRelations(), update.getProperties()); response.setAnswer(ok()); }

Update Service Handler.

Parses the header and payload into an update object with Gson and checks for invalid relationship types in the query. Calls updateNode() method to query Neo4j and the answer is returned.

ServiceResponseBuilder<DataQueryRequest, DataQueryResponse> org.roboy.memory.ros.ServiceLogic.getServiceHandler = (request, response) -> { Header header = parser.fromJson(request.getHeader(), Header.class); Get get = parser.fromJson(request.getPayload(), Get.class); Gson gson = new GsonBuilder().setPrettyPrinting().create(); logger.info(gson.toJson(get)); if (get.getId() != 0) { response.setAnswer(Neo4j.getNodeById(get.getId())); } else { response.setAnswer(Neo4j.getNode(get.getLabel(), get.getRelations(), get.getProperties())); } }

Get Service Handler.

Parses the header and payload into a get object with Gson and checks whether node IDs or information about a node is queried. Calls getNodeById() or getNode() methods to query Neo4j and the answer is returned.

ServiceResponseBuilder<DataQueryRequest, DataQueryResponse> org.roboy.memory.ros.ServiceLogic.cypherServiceHandler = (request, response) -> { Header header = parser.fromJson(request.getHeader(), Header.class); logger.info(request.getPayload()); response.setAnswer(Neo4j.run(request.getPayload())); }

Cypher Service Handler.

Directly runs a plain Cypher query which is contained in the payload and returns the response.

ServiceResponseBuilder<DataQueryRequest, DataQueryResponse> org.roboy.memory.ros.ServiceLogic.removeServiceHandler = (request, response) -> { Header header = parser.fromJson(request.getHeader(), Header.class); Remove remove = parser.fromJson(request.getPayload(), Remove.class); Neo4j.remove(remove.getId(), remove.getRelations(), remove.getProperties()); response.setAnswer(ok()); }

Remove Service Handler.

Parses the header and payload into a remove object. Calls remove() method to query Neo4j and the answer is returned.

Private Static Attributes

Logger org.roboy.memory.ros.ServiceLogic.logger = Logger.getLogger(ServiceLogic.class.toString())

Logger.

Gson org.roboy.memory.ros.ServiceLogic.parser = new Gson()

Parses the JSON elements of the header and payload.

HashSet<String> org.roboy.memory.ros.ServiceLogic.labels = new HashSet<String>(Arrays.asList(LABEL_VALUES))

Contains available label types.

HashSet<String> org.roboy.memory.ros.ServiceLogic.relations = new HashSet<String>(Arrays.asList(RELATION_VALUES))

Contains available relationship types.

class Update

Data model for JSON parser.

Creates objects, that contain the elements of the Update queries.

Public Functions

int org.roboy.memory.models.Update.getId()
Map<String, String> org.roboy.memory.models.Update.getProperties()
Map<String, String[]> org.roboy.memory.models.Update.getRelations()

Private Members

int org.roboy.memory.models.Update.id

The id of a node that shall be modified.

String org.roboy.memory.models.Update.type

Currently only used to specify the type “node”.

String org.roboy.memory.models.Update.label

Specifies the type of node that shall be updated, like “Person”.

Map<String, String[]> org.roboy.memory.models.Update.relations

Contains the relationship type as key and an array of node IDs as value.

Map<String, String> org.roboy.memory.models.Update.properties

Contains the node properties.

namespace util
namespace org
namespace v1
namespace roboy
namespace memory
namespace models
namespace ros
namespace util
namespace Answer
namespace Config
namespace roboy_communication_cognition
file Main.java
file Create.java
file Get.java
file Header.java
file Remove.java
file Update.java
file RosNode.java
file RosRun.java
file ServiceLogic.java
file Answer.java
file Config.java
file Neo4j.java
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org/roboy/memory
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org/roboy/memory/models
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org/roboy
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org/roboy/memory/ros
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/docs/src/org/roboy/memory/util