API

class Answer

Answer wrapper.

Outputs OK or error messages to ROS.

Public Static Functions

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

Answer for ROS if no errors were detected.

Return
JSON object {status:”OK”} to ROS
Parameters
  • message: contains the success message with json data

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 = System.getenv(“ROS_MASTER_URI”) == null ? “http://localhost:11311/” : System.getenv(“ROS_MASTER_URI”)
final String org.roboy.memory.util.Config.ROS_HOSTNAME = System.getenv(“ROS_HOSTNAME”) == null ? “127.0.0.1” : System.getenv(“ROS_HOSTNAME”)
final String org.roboy.memory.util.Config.NEO4J_ADDRESS = System.getenv(“NEO4J_ADDRESS”) == null ? “bolt://localhost:7687” : System.getenv(“NEO4J_ADDRESS”)
final String org.roboy.memory.util.Config.NEO4J_USERNAME = System.getenv(“NEO4J_USERNAME”) == null ? “neo4j” : System.getenv(“NEO4J_USERNAME”)
final String org.roboy.memory.util.Config.NEO4J_PASSWORD = System.getenv(“NEO4J_PASSWORD”) == null ? “memory” : System.getenv(“NEO4J_PASSWORD”)
final String org.roboy.memory.util.Config.REDIS_URI = System.getenv(“REDIS_URI”) == null ? “redis://localhost:6379/0” : System.getenv(“REDIS_URI”)
final String org.roboy.memory.util.Config.REDIS_PASSWORD = System.getenv(“REDIS_PASSWORD”) == null ? “root” : System.getenv(“REDIS_PASSWORD”)
class

Data model for JSON parser.

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

Public Functions

String [] org.roboy.memory.models.Create.getFace()
boolean org.roboy.memory.models.Create.validate()

Private Members

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

Public Static Attributes

final HashSet<String> org.roboy.memory.util.Dictionary.LABEL_VALUES

= new HashSet<String>(Arrays.asList(

“Person”,

“Robot”,

“Company”,

“University”,

“City”,

“Country”,

“Hobby”,

“Occupation”,

“Object”,

“Location”,

“Organization”))

final HashSet<String> org.roboy.memory.util.Dictionary.RELATIONSHIP_VALUES

= new HashSet<String> (Arrays.asList(

“FRIEND_OF”,

“LIVE_IN”,

“FROM”,

“WORK_FOR”,

“STUDY_AT”,

“MEMBER_OF”,

“HAS_HOBBY”,

“KNOW”,

“IS”,

“PART_OF”,

“IS_IN”,

“OCCUPIED_AS”,

“CHILD_OF”,

“SIBLING_OF”))

class

Data model for JSON parser.

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

Public Functions

boolean org.roboy.memory.models.Get.validate()
class Header

Data model for JSON parser.

Creates objects, that contain the elements of the Header.

Public Functions

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

Private Members

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

Public Static Functions

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

Private Static Attributes

Logger org.roboy.memory.Main.logger = Logger.getLogger(Main.class.toString())
class MemoryOperations

This class replicates the behaviour of ros.ServiceLogic.

We make use of the exact same functions, just refactored to not be Services.

Public Static Functions

static String org.roboy.memory.util.MemoryOperations.create(String request)

Create a node.

Return
JSON containing the ID of the new node
Parameters
  • request: Query with data regarding the node. Ex: {“labels”:[“Organization”],”label”:”Organization”,”properties”:{“name”:”korn”}}

static String org.roboy.memory.util.MemoryOperations.get(String request)

Get the Node ID.

Return
JSON containing ID of node
Parameters
  • request: Query to specify Node to get. Ex: {“labels”:[“Person”],”label”:”Person”,”properties”:{“name”:”davis”}}

static String org.roboy.memory.util.MemoryOperations.update(String request)

Update Nodes.

Return
JSON establishing whether or not the connection was made or not
Parameters
  • request: Query to link two nodes together. Ex: {“labels”:[“Person”],”label”:”Person”,”properties”:{“name”:”davis”},”relationships”:{“FROM”:[369]},”id”:368}

static String org.roboy.memory.util.MemoryOperations.cypher(String request)

Cypher Method that is never called TODO: Implement this feature or refactor it out, it’s kind of here because there was a service.

Return
Parameters
  • request:

static String org.roboy.memory.util.MemoryOperations.delete(String request)

This method should contain the code of remove, to make things consistent. See SDE-60

static String org.roboy.memory.util.MemoryOperations.remove(String request)

Delete a Node.

Return
Whether or not deleting was successful or not
Parameters
  • request: JSON query to delete a specified node. Ex: {‘type’:’node’,’id’:361,’properties_list’: [‘sex’], ‘relationships’:{‘FRIEND_OF’:[426]}}

Private Static Attributes

Gson org.roboy.memory.util.MemoryOperations.parser = new Gson()
class Neo4j : public AutoCloseable

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.

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(Create create)

Method accepting JSON Create queries.

Return
result obtained by createNode method

static String org.roboy.memory.util.Neo4j.updateNode(Update update)

Method accepting JSON Update queries.

Return
result obtained by update method

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(Get get)
static String org.roboy.memory.util.Neo4j.remove(Remove remove)

Method accepting JSON Remove queries.

Return
result obtained by removeRelsProps method

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, Create create)

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

static void org.roboy.memory.util.Neo4j.saveToJedis(String[] face, String id)
static String org.roboy.memory.util.Neo4j.update(Transaction tx, Update update)

Method processing JSON Update queries.

Return
response from Neo4j upon updating the node
Parameters
  • tx: is a transaction handler to query Neo4j DB

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 int [] org.roboy.memory.util.Neo4j.toIntArray(List< Integer > list)
static Node org.roboy.memory.util.Neo4j.createNode(int id, HashMap< String, String > properties, HashMap< String, int[]> relationships)
static String org.roboy.memory.util.Neo4j.matchNode(Transaction tx, Get get)
static String org.roboy.memory.util.Neo4j.remove(Transaction tx, Remove remove)

Method processing JSON Remove queries.

Return
response from Neo4j upon removing the specified relationships and properties
Parameters
  • tx: is a transaction handler to query Neo4j DB

Private Static Attributes

Neo4j org.roboy.memory.util.Neo4j._instance
Driver org.roboy.memory.util.Neo4j._driver
Jedis org.roboy.memory.util.Neo4j.jedis
Gson org.roboy.memory.util.Neo4j.gson = new Gson()
Logger org.roboy.memory.util.Neo4j.logger = Logger.getLogger(Neo4j.class.toString())
class Node

Subclassed by org.roboy.memory.models.RosNode

Public Functions

org.roboy.memory.models.Node.Node()
String org.roboy.memory.models.Node.getLabel()
void org.roboy.memory.models.Node.setLabel(String label)
Integer org.roboy.memory.models.Node.getId()
void org.roboy.memory.models.Node.setId(Integer id)
HashMap<String, String> org.roboy.memory.models.Node.getProperties()
void org.roboy.memory.models.Node.setProperties(HashMap< String, String > properties)
HashMap<String, int[]> org.roboy.memory.models.Node.getRelationships()
void org.roboy.memory.models.Node.setRelationships(HashMap< String, int[]> relationships)

Private Members

String org.roboy.memory.models.Node.label
Integer org.roboy.memory.models.Node.id
HashMap<String, String> org.roboy.memory.models.Node.properties
HashMap<String, int[]> org.roboy.memory.models.Node.relationships
class QueryBuilder

Public Functions

org.roboy.memory.util.QueryBuilder.QueryBuilder()
QueryBuilder org.roboy.memory.util.QueryBuilder.add(String text)
QueryBuilder org.roboy.memory.util.QueryBuilder.addParameters(HashMap< String, String > params)
String org.roboy.memory.util.QueryBuilder.getQuery()
QueryBuilder org.roboy.memory.util.QueryBuilder.matchById(int id, String letter)
QueryBuilder org.roboy.memory.util.QueryBuilder.set(HashMap< String, String > properties, String letter)
QueryBuilder org.roboy.memory.util.QueryBuilder.add(String text, Object... args)

Private Members

StringBuilder org.roboy.memory.util.QueryBuilder.builder
class

Data model for JSON parser.

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

Public Functions

HashSet<String> org.roboy.memory.models.Remove.getPropertiesList()
boolean org.roboy.memory.models.Remove.validate()

Private Members

HashSet<String> org.roboy.memory.models.Remove.properties_list
class

Subclassed by org.roboy.memory.models.Create, org.roboy.memory.models.Get, org.roboy.memory.models.Remove, org.roboy.memory.models.Update

Public Functions

String org.roboy.memory.models.RosNode.getError()
abstract boolean org.roboy.memory.models.RosNode.validate()

Protected Functions

void org.roboy.memory.models.RosNode.error(String text)

Private Members

transient String org.roboy.memory.models.RosNode.error
class RosNode : public AbstractNodeMain

ROS Service for saving data object to DB.

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

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.

Public 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.validate()) {

if (!create.getLabel().toUpperCase().equals(“OTHER”)) {

response.setAnswer(

Neo4j.createNode

(create));

} else {

response.setAnswer(create.getError());

}

} else {

response.setAnswer(create.getError());

}

}

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.validate()) {

if (!update.getLabel().toUpperCase().equals(“OTHER”)) {

response.setAnswer(ok(

Neo4j.updateNode

(update)));

} else {

response.setAnswer(error(update.getError()));

}

} else {

response.setAnswer(error(update.getError()));

}

}

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);

logger.info(“Request payload: ” + request.getPayload());

Get

get = parser.fromJson(request.getPayload(), Get.class);

if (get.getId() != null ) {

response.setAnswer(

Neo4j.getNodeById

(get.getId()));

} else {

if (!get.getLabel().toUpperCase().equals(“OTHER”)) {

response.setAnswer(Neo4j.getNode(get));

} else {

response.setAnswer(error(get.getError()));

}

}

}

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);

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);

if (remove.validate()) {

response.setAnswer(ok(

Neo4j.remove

(remove)));

} else {

response.setAnswer(error(remove.getError()));

}

}

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

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

Data model for JSON parser.

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

Public Functions

boolean org.roboy.memory.models.Update.validate()
namespace org
namespace v1
namespace roboy
namespace memory
namespace models
namespace ros
namespace util
namespace Config
file Main.java
file Create.java
file Get.java
file Header.java
file Node.java
file Remove.java
file RosNode.java
file RosNode.java
file Update.java
file RosRun.java
file ServiceLogic.java
file Answer.java
file Config.java
file Dictionary.java
file MemoryOperations.java
file Neo4j.java
file QueryBuilder.java
page deprecated

dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org/roboy/memory
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org/roboy/memory/models
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org/roboy
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org/roboy/memory/ros
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src
dir /home/docs/checkouts/readthedocs.org/user_builds/roboy-memory/checkouts/develop/src/org/roboy/memory/util