nicolewhite/RNeo4j

getOrCreate / getUniqueNode multiple labels

ch-ricardor opened this issue · 0 comments

Following one of your examples I tried to create a retweet with two labels, due the retweet is a copy of a tweet I want to have it in two different "categories".
https://nicolewhite.github.io/2014/05/30/demo-of-rneo4j-part1.html

I tested manually the use of multiple labels following:
https://neo4j.com/developer/kb/how-do-i-report-on-nodes-with-multiple-labels/

Then I tried to replicate the same functionality in R.

createNode has the possibility to create multiple labels:
createNode(theGraph,c("Tweet","ReTweet"), ...)

Is it valid getOrCreateNode(theGraph,c("Tweet","ReTweet"), ...)
and
getUniqueNode(graph, c("Tweet","ReTweet"), name = "Alice") ?

Maybe "I'm confused!" and I have to use two different statements for each label to create the nodes, but which would be the best option to retrieve unique nodes with multiple labels?

In the code I have something like:

  addConstraint(twGraph, "Tweet", "id")
  addConstraint(twGraph, "ReTweet", "id")

  getOrCreateNode(theGraph,c("Tweet","ReTweet"), ...) 

I checked the code on getOrCreate and calls

  node = try(createNode(graph, .label, ...), TRUE)

createNode has the possibility to create multiple labels:

  createNode.graph = function(graph, .label = character(), ...) {
    query = "CREATE (n"
      **if(length(.label) > 0) {
      for(i in 1:length(.label)) {
        query = paste0(query, ":", .label[i])
      }**
    }

but the call failed in getOrCreateNode:

  getOrCreateNode.graph = function(graph, .label, ...) {
    **if(!(names(props)[[1]] %in% getConstraint(graph, .label)$property_keys)) {
      stop("The first key = value pair listed in ... must be uniquely constrained for the given node label.")
    }**

"I'm confused!"