Cannot use method 'updateProp' in RNeo4j package - r

I'm using RNeo4j package together with igraph to calculate betweenness centrality and write back to Neo4j database.
It can calculate perfectly without any problem connecting with Neo4j. After I'd got vector named with id of its node and contained its betweenness centrality value, I tried to update only one node and I got problem with 'updateProp' method.
The error I got is this.
Error in UseMethod("updateProp") :
no applicable method for 'updateProp' applied to an object of class "list"
And this is some part of my code that stuck.
...
bet <- betweenness(g)
alice = getLabeledNodes(neo4j, "User", id = as.integer(names(bet[1])))
# returned valid node
# following line got the mentioned error.
alice = updateProp(alice,betweenness_centrality = as.numeric(bet[[1]]))
I also tried other way like this without any luck.
(Also hardcoded the value to be 0 but it didn't work either)
newProp = list(betweenness_centrality = bet[[1]])
alice = updateProp(alice,newProp)
p.s. for my reference website http://rpackages.ianhowson.com/cran/RNeo4j/man/updateProp.html .
Thank you in advance.

updateProp expects the first argument to be a node. You're passing it a list. It should work if you access the first node of that list.
bet <- betweenness(g)
alice = getLabeledNodes(neo4j, "User", id = as.integer(names(bet[1])))
alice = alice[[1]]
# returned valid node
# following line got the mentioned error.
alice = updateProp(alice, betweenness_centrality = as.numeric(bet[[1]]))

Related

NetworkMapCache is empty in MockNetwork tests

I'm writing some lightweight flow tests with mocked everything and I ran into error that on all nodes NetworkMapService contains only the node itself. Identity service from the other hand contains all 3 nodes participating in a test.
net = MockNetwork()
issuer = net.createNode(legalName = CHARLIE.name)
alice = net.createNode(legalName = ALICE.name)
bob = net.createNode(legalName = BOB.name)
issuer.registerInitiatedFlow(IssueClaimFlow.Issuer::class.java)
alice.registerInitiatedFlow(VerifyClaimFlow.Prover::class.java)
MockServices.makeTestDatabaseAndMockServices(createIdentityService = { InMemoryIdentityService(listOf(ALICE_IDENTITY, BOB_IDENTITY, CHARLIE_IDENTITY), emptySet(), DEV_TRUST_ROOT) } )
net.registerIdentities()
net.runNetwork()
In this case flow goes well until first sendAndRecieve() call. There I get:
12:28:12.832 [Mock network] WARN net.corda.flow.[8f685c46-9ab6-4d64-b3f2-6b7476813c3b] - Terminated by unexpected exception
java.lang.IllegalArgumentException: Don't know about party C=ES,L=Madrid,O=Alice Corp
Funny thing that test is still finishes green (no useful work done thou). But its probably topic for another question.
I can overcome it with setting up cache manually like this:
alice.services.networkMapCache.addNode(issuer.info)
bob.services.networkMapCache.addNode(alice.info)
But is this correct way to go? I don't see something like this in samples or wherever.
If you look at the definition of MockNetwork.createNode, the networkMapAddress defaults to null.
Instead, you should use MockNetwork.createSomeNodes, which creates a network map node for you, then sets that node as the network map for every subsequent node it creates.
Here's an example from the CorDapp Example:
network = MockNetwork()
val nodes = network.createSomeNodes(2)
a = nodes.partyNodes[0]
b = nodes.partyNodes[1]
You can see the full example here: https://github.com/corda/cordapp-example/blob/release-V2/kotlin-source/src/test/kotlin/com/example/flow/IOUFlowTests.kt.

Client error: (405) Method Not Allowed while trying to use Neo4j syntax in R

I'm trying to use Neo4j in RStudio for the first time. I'm just trying this tutorial https://github.com/nicolewhite/RNeo4j
But when I try a query like this one:
nicole = createNode(graph, "Person", name="Nicole", age=24)
I got this error:
Client error: (405) Method Not Allowed
Is there any way to solve this problem? Thank you in advance for your time.
Your error can happen if you accidentally leave some information out of your startGraph() call. Make sure you have /db/data/ on the end of your graph's url. (If this isnt the case then please post your startGraph command you used).
with /db/data
library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
nicole = createNode(graph, "Person", name="Nicole", age=24)
nicole
# Person
#
# $name
# [1] "Nicole"
#
# $age
# [1] 24
without
graph = startGraph("http://localhost:7474")
nicole = createNode(graph, "Person", name="Nicole", age=24)
Error: Client error: (405) Method Not Allowed

Unable to build inline segments in RSiteCatalyst package in R

I am trying to build the inline segment to filter the pages (ex. to separate the pages for blogs and games) using the function BuildClassificationValueSegment() to get the data from Adobe Analytics API,
I have tried some thing like
report.data.visits <- QueueTrended(reportsuite.id,date.from,date.to,metrics,elements,
segment.inline = BuildClassificationValueSegment("evar2","blog","OR")).
Got error like :
Error in ApiRequest(body = report.description, func.name = "Report.Validate") :
ERROR: segment_invalid - Segment "evar2" not valid for this company
In addition: Warning message:
In if (segment.inline != "") { :
the condition has length > 1 and only the first element will be used
Please help on the same.Thanks in advance...
I recommend you to declare the InlineSegment in advance and store it in a variable. Then pass it to the QueueTrended function.
I've been using the following syntax to generate an inline segment:
InlineSegment <- list(container=list(type=unbox("hits"),
rules=data.frame(
name=c("Page Name(eVar48)"),
element=c("evar48"),
operator=c("equals"),
value=c(as.character("value1","value2"))
))
You can change the name and element arguments in order to personalize the query.
The next step is to pass the InlineSegment to the QueueRanked function:
Report <- as.data.frame(QueueRanked("reportsuite",
date.from = dateStart,
date.to = dateEnd,
metrics = c("pageviews"),
elements = c("element"),
segment.inline = InlineSegment,
max.attempts=500))
I borrowed that syntax from this thread some time ago: https://github.com/randyzwitch/RSiteCatalyst/issues/129
Please note that there might be easier ways to obtain this kind of report without using InlineSegmentation. Maybe you can use the selected argument from the QueueRanked function in order to narrow down the scope of the report.
Also, I'm purposefully avoiding the BuildClassificationValueSegment function as I found it a bit difficult to understand.
Hope this workaround helps...

Titan Graph Queries taking too long to execute

I have a problem with the executing speed of Titan queries.
To be more specific:
I created a property file for my graph using BerkeleyJe which is looking like this:
storage.backend=berkeleyje
storage.directory=/finalGraph_script/graph
Afterwards, i opened the Gremlin.bat to open my Graph.
I set up all the neccessary Index Keys for my nodes:
m = g.getManagementSystem();
username = m.makePropertyKey('username').dataType(String.class).make()
m.buildIndex('byUsername',Vertex.class).addKey(username).unique().buildCompositeIndex()
m.commit()
g.commit()
(all other keys are created the same way...)
I imported a csv file containing about 100 000 lines, each line is producing at least 2 nodes and some edges. All this is done via Batchloading.
That works without a Problem.
Then i execute a groupBy query which is looking like that:
m = g.V.has("imageLink").groupBy{it.imageLink}{it.in("is_on_image").out("is_species")}{it._().species.groupCount().cap.next()}.cap.next()
With this query i want for every node with the property key "imageLink" the number of the different "species". "Species" are also nodes, and can be called by going back the edge "is_on_image" and following the edge "is_species".
Well this is also working like a charm, for my recent nodes. This query is taking about 2 minutes on my local PC.
But now to the problem.
My whole dataset is a csv with 10 million entries. The structure is the same as above, and each line is also creating at least 2 nodes and some edges.
With my local PC i cant even import this set, causing an Memory Exception after 3 days of loading.
So I tried the same on a server with much more RAM and memory. There the Import works, and takes about 1 day. But the groupBy failes after about 3 days.
I actually dont know if the groupBy itself fails, or just the Connection to the Server after that long time.
So my first Question:
In my opinion about 15 million nodes shouldn't be that big deal for a graph database, should it?
Second Question:
Is it normal that it takes so long? Or is there anyway to speed it up using indices? I configured the indices as listet above :(
I don't know which exact information you need for helping me, but please just tell me what you need in addition to that.
Thanks a lot!
Best regards,
Ricardo
EDIT 1: The way im loading the CSV in the Graph:
I'm using this code, i deleted some unneccassry properties, which are also set an property for some nodes, loaded the same way.
bg = new BatchGraph(g, VertexIDType.STRING, 10000)
new File("annotation_nodes_wNothing.csv").eachLine({ final String line ->def (annotationId,species,username,imageLink) = line.split('\t')*.trim();def userVertex = bg.getVertex(username) ?: bg.addVertex(username);def imageVertex = bg.getVertex(imageLink) ?: bg.addVertex(imageLink);def speciesVertex = bg.getVertex(species) ?: bg.addVertex(species);def annotationVertex = bg.getVertex(annotationId) ?: bg.addVertex(annotationId);userVertex.setProperty("username",username);imageVertex.setProperty("imageLink", imageLink);speciesVertex.setProperty("species",species);annotationVertex.setProperty("annotationId", annotationId);def classifies = bg.addEdge(null, userVertex, annotationVertex, "classifies");def is_on_image = bg.addEdge(null, annotationVertex, imageVertex, "is_on_image");def is_species = bg.addEdge(null, annotationVertex, speciesVertex, "is_species");})
bg.commit()
g.commit()

RNeo4j cypher - retrieving paths

I'm trying to extract a sub-graph from a global network (sub-networks of specific nodes to a specific depth).
The network is composed of nodes labeled as Account with a property of iban and relationships of TRANSFER_TO_AGG.
The cypher syntax is as followed:
MATCH (a:Account { iban :'FR7618206004274157697300156' }),(b:Account),
p = allShortestPaths((a)-[:TRANSFER_TO_AGG*..3]-(b))
RETURN p limit 250
This works perfectly on the Neo4J web interface. However, when trying to save the results to an R object using the command cypher I get the following error:
"Error in as.data.frame.list(value, row.names = rlabs) :
supplied 92 row names for 1 rows"
I believe this is due to the fact that if returning data, you can only query for tabular results. That is, this method has no current functionality for Cypher results containing array properties, collections, nodes, or relationships.
Can anyone offer a solution ?
I've recently added functionality for returning pathways as R objects. First, uninstall / reinstall RNeo4j. Then, see:
?getSinglePath
?getPaths
?shortestPath
?allShortestPaths
?nodes
?rels
?startNode
?endNode
For your query specifically, you would use getPaths():
library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")
query = "
MATCH (a:Account { iban :'FR7618206004274157697300156' }),(b:Account),
p = allShortestPaths((a)-[:TRANSFER_TO_AGG*..3]-(b))
RETURN p limit 250
"
p = getPaths(graph, query)
p is a list of path objects. See the docs for examples of using the apply family of functions with a list of path objects.

Resources