http://imageshack.us/photo/my-images/707/graphpw.png/
I would like to know how I can get the number of leaf node from certain node using method or something in neo4j ?
Example.
At Node A --> contains 12 leaf nodes
At Node B --> contains 6 leaf nodes
Thanks in advance.
I would model the intermediate relationships as contains and the leaf relationships as leaf, see http://console.neo4j.org/r/ulo3yc
Then, you can do
With a setup of
create (f1{name:'folder1'}), ({name:'root'})-[:contains]->(f1)-[:leaf]-> (f2{name:'folder2'}), f1-[:leaf]->({name:'folder3'})
you can do something like
start root=node(1)
match root-[:contains*0..]->()-[:leaf]->leaf
return leaf
returning
+-------------------------+
| leaf |
+-------------------------+
| Node[2]{name:"folder2"} |
| Node[3]{name:"folder3"} |
+-------------------------+
Related
Why in the get subgraph statement, I can't use the vertex in the format of tagName.propName like in the go statement.
(root#nebula) [subgraph]> GET SUBGRAPH 6 STEPS FROM "player101" WHERE $$.player.age>50 YIELD VERTICES AS nodes, EDGES AS relationships;
+---------------------------+---------------+
| nodes | relationships |
+---------------------------+---------------+
| [("player101" :player{})] | [] |
+---------------------------+---------------+
Got 1 rows (time spent 5803/7091 us)
Thu, 20 Oct 2022 03:45:11 UTC
(root#nebula) [subgraph]> GET SUBGRAPH 6 STEPS FROM "player101" WHERE player.age>50 YIELD VERTICES AS nodes, EDGES AS relationships;
[ERROR (-1005)]: EdgeName `player' is nonexistent
(root#nebula) [subgraph]> GO FROM "player100" OVER follow WHERE follow.degree > 90 YIELD dst(edge);
+-----------+
| dst(EDGE) |
+-----------+
+-----------+
In the GET SUBGRAPH statement, you cannot use the vertex in the format of tagName.propName because the WHERE clause of the GET SUBGRAPH statement operates on the vertices and edges within the subgraph, rather than on the starting vertex or edge that you specify in the FROM clause.
Therefore, you should specify the vertex or edge properties directly in the WHERE clause using a reference symbol such as &&, rather than using the tagName.propName syntax.
To put it in a simple way, NebulaGraph does not support such a way of use.
I was asked to find the asymptotic complexity of the given function using recursion tree
but I'm struggling to find the correct complexity at each level
Let's draw out the first two levels of the recursion tree:
+------------------+
| Input size n |
| Work done: n^2 |
+------------------+
/ \
+--------------------+ +--------------------+
| Input size: 3n/4 | | Input size: n/3 |
| Work done: 9n^2/16 | | Work done: n^2/9 |
+--------------------+ +--------------------+
Once we've done that, let's sum up the work done by each layer. That top layer does n2 work. That next layer does
(9/16)n2 + (1/9)n2 = (43/48)n2
total work. Notice that the work done by this second level is (43/48)ths of the work done in the level just above it. If you expand out a few more levels of the recursion tree, you'll find that the next level does (43/48)2n2 work, the level below that does (43/48)3n2 work, and that more generally the work done by level l in the tree is (43/48)ln2. (Convince yourself of this - don't just take my word for it!)
From there, you can compute the total amount of work done by recursion tree by summing up the work done per level across all the levels of the tree. As a hint, you're looking at the sum of a geometric sequence that decays from one term to the next - does this remind you of any of the cases of the Master Theorem?
I have a problem with my Cypher query. I have some nodes called :SENTENCE and some other called :WORD. :SENTENCE nodes have relationships :CONTAINS to :WORD nodes.
I want to find :SENTENCE nodes, that are connected to :WORD nodes, that are used from more than 3 other :SENTENCE nodes. All :WORD nodes have to comply this criterion.
I tried something like this:
MATCH p=(s1:SENTENCE)-[:CONTAINS]-(w:WORD)-[:CONTAINS]-(s2:SENTENCE)
WITH s1,w, COUNT(s2) as num
WHERE num > 3
RETURN s1
LIMIT 25
But the result contains :SENTENCE nodes, where one and not all :WORD nodes have a degree of minimum 3.
Some other try:
MATCH p=(s1:SENTENCE)-[:CONTAINS]-(w:WORD)-[:CONTAINS]-(s2:SENTENCE)
WHERE SIZE((:SENTENCE)-[:CONTAINS]-(w:WORD)) > 3
RETURN s1
LIMIT 25
But this does not hold for any :WORD nodes that is contained in an Sentence. It only holds for 1.
So my question is: How can I make a query that the condition hold for all nodes and not only for one.
This kind of requirement usually requires collecting nodes and using the all() function to ensure some predicate holds true for all elements of the collection:
MATCH (s1:SENTENCE)-[:CONTAINS]-(w:WORD)
WITH s1, collect(w) as words
WHERE all(word in words WHERE size((word)-[:CONTAINS]-()) > 3)
RETURN s1
LIMIT 25
I have model implemented in titan graph database with relations presented below:
[A] ---(e1)---> [B] <---(e2)--- [C] ---(e3)---> [D]
| | | | | | |
prop:id | prop:number | | label:e3 |
| | prop:id |
label:e1 label:e2 prop:number
prop:prop1
A and B are "main vertices" (for example users), vertices B and C are "less important vertices" describing some data connected with users.
The input for the query algorithm is property id of vertex A.
I want to find all such vertices D, that are connected with A in the manner shown above. What's more I want to remember the property prop1 of the edge e1 between A and B.
More precisely, I want to efficiently retrieve pairs (prop1, numberD) where prop1 is the property of edge between A -> B (if the edge has this property), and numberD is the property number from D.
I don't know how to efficiently implement this query.
It is easy to retrieve only vertices D (using GremlinPipes):
pipe
.start(startVertex)
.outE("e1")
.inV().hasProperty("number")
.inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number");
But problems occur when I need to get also edges e1 and match them with vertices D.
I tried to compute all these steps separately, but is seems to be very inefficient.
Do you have any suggestions how to implement this (maybe using several queries) using gremlin-java or gremlin-groovy?
Thanks!
Take a look at the Pattern Match Pattern described here:
https://github.com/tinkerpop/gremlin/wiki/Pattern-Match-Pattern
startVertex.outE('e1').as('e')
.inV().hasProperty('number').inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number").as('d')
.table(t)
This should give an iterator of maps
[e:e1, d:D]
From each of these maps, you can easily extract the properties you are interested in.
I have a grid that's display using a control that inherits from QTableView. Right now the grid is displayed left-to-right and then as things overflow, it goes to the next row like this
-----------
| 1 | 2 | 3 |
|------------
| 4 | | |
|------------
| | | |
-----------
but I want it to go top-to-bottom first and then as things overflow, it should go to next column like this
-----------
| 1 | 4 | |
|------------
| 2 | | |
|------------
| 3 | | |
-----------
I'm mostly a .Net developer and it's pretty trivial with .net winforms controls, but how do I get QTableView to do this?
Thanks
The data displayed is a function of your model. The best way to change the behavior is to create a proxy QAbstractTableModel that swaps the rows and the columns. How complicated this will be will be dependent on your current model. It almost sounds like you have a linear model and that the view just presents it in a table-like fashion in which case you're probably using the wrong model.
If you really do have a linear model, consider using QAbstractListModel and QListView. The QListView then has a flow property that will allow you to choose between left-to-right and top-to-bottom.