Importing columns from another sheet and joining - google-sheets

I have a master sheet and I would like to import to another sheet all rows but only columns D, I, J, K, L, M, N, P, Q, S, T, U, V, W. But I would also like to join some of these columns.
I'd like to join the following:
D, I & J
K, L, M & N
P, Q, S, T & U
V & W.
I'd also like to have the information continue to feed through as more gets added to the master sheet. Is this actually possible?

Related

Get end nodes when using *

Lets say I have points a, b, c, d and a->b->c->d is related with next. Below is merge command for it.
merge (a:point{id:'a'})-[:next]-(b:point{id:'b'})-[:next]-(c:point{id:'c'})-[:next]-(d:point{id:'d'}) return a, b, c, d
Neo4j image of the merge
What I am looking for is a way to get all the points between a and d. Using below query I get the relationships, but how can I get list that contains b, c?
match p=(start:point)-[:next*]-(end:point)
with *, relationships(p) as r
where start.id ='a' and end.id = 'd'
return start, r, end
You can do
RETURN nodes(p)[1..-1]
to get the nodes except the first and last one.

In Neo4J, how to match all nodes that are relted to nodes that all relate to a specific node?

Suppose I have Red, Blue and Green nodes (R, B, G) and the relationships might look like this:
As you can see, R points to B and G also points to B. I want to match all R nodes where all the B nodes they point to are also related to a specific G node. How would I do this?
You can set this up on your own database by running something like this:
CREATE
(R1:Test_R),
(B1:Test_B),
(G:Test_G),
(R2:Test_R),
(B2:Test_B),
(R1)-[:TEST_LINK]->(B1),
(R1)-[:TEST_LINK]->(B2),
(R2)-[:TEST_LINK]->(B1),
(G)-[:TEST_LINK]->(B1)
RETURN
R1, R2, B1, B2, G
You can then query them by running something like this:
MATCH
(R:Test_R)-[:TEST_LINK]->(B:Test_B)
OPTIONAL MATCH
(B)<-[:TEST_LINK]-(G:Test_G)
RETURN
R,B,G
You can do it using a query something like the following:
MATCH
(R:Test_R)-[:TEST_LINK]->(B:Test_B)
WITH
{R: R, B: COLLECT(B) } AS d
MATCH
(G:Test_G)
WHERE
ID(G) = 5770 // Match our specific G node
AND ALL(b IN d.B WHERE (b)<-[:TEST_LINK]-(G) )
RETURN d.R
The ALL function will return true if all items in the list return true for the predicate specified:
ALL(<variable> IN <list> WHERE <predicate)

How to find the similarity between two graphs in neo4j

In below graphs A, B, C, D, E, G, H, I, J, K is main graph and L, M, N, O, P, Q, R is sub graph. First I am trying to get the sub graph exist in main graph so, I got the sub graph like D, E, G, H. Now I want apply the cosine similarity between L, M, N, O, P, Q, R graph and D, E, G, H.
Code for creating the graph :
MERGE (a:Node {name:'A', score:1})
MERGE (b:Node {name:'B', score:2})
MERGE (c:Node {name:'C', score:3})
MERGE (d:Code {name:'D', score:4})
MERGE (e:Code {name:'E', score:5})
MERGE (g:Code {name:'G', score:7})
MERGE (h:Code {name:'H', score:8})
MERGE (i:Node {name:'I', score:9})
MERGE (j:Node {name:'J', score:10})
MERGE (k:Node {name:'K', score:11})
MERGE (a)-[:Connects {score:1}]->(b)
MERGE (a)-[:Connects {score:2}]->(c)
MERGE (a)-[:Connects {score:3}]->(d)
MERGE (b)-[:Connects {score:4}]->(c)
MERGE (b)-[:Connects {score:5}]->(d)
MERGE (b)-[:Connects {score:6}]->(j)
MERGE (c)-[:Connects {score:7}]->(d)
MERGE (c)-[:Connects {score:8}]->(e)
MERGE (d)-[:Connects {score:10}]->(g)
MERGE (d)-[:Connects {score:11}]->(h)
MERGE (e)-[:Connects {score:14}]->(g)
MERGE (e)-[:Connects {score:15}]->(h)
MERGE (g)-[:Connects {score:20}]->(h)
MERGE (g)-[:Connects {score:21}]->(i)
MERGE (g)-[:Connects {score:22}]->(j)
MERGE (i)-[:Connects {score:23}]->(j)
MERGE (i)-[:Connects {score:24}]->(k)
MERGE (j)-[:Connects {score:25}]->(k)
CREATE (l:Test {name:'L', score:4})
CREATE (m:Test {name:'M', score:5})
CREATE (n:Test {name:'N', score:6})
CREATE (o:Test {name:'O', score:7})
CREATE (p:Test {name:'P', score:8})
CREATE (q:Test {name:'Q', score:12})
CREATE (r:Test {name:'R', score:13})
CREATE (l)-[:Connects {score:10}]->(o)
CREATE (l)-[:Connects {score:11}]->(p)
CREATE (l)-[:Connects {score:12}]->(n)
CREATE (m)-[:Connects {score:13}]->(n)
CREATE (m)-[:Connects {score:14}]->(o)
CREATE (m)-[:Connects {score:15}]->(p)
CREATE (n)-[:Connects {score:16}]->(o)
CREATE (n)-[:Connects {score:17}]->(p)
CREATE (n)-[:Connects {score:26}]->(q)
CREATE (n)-[:Connects {score:27}]->(r)
CREATE (o)-[:Connects {score:20}]->(p)
I am new to neo4j cypher query, Please suggest How to apply cosine similarity between graphs (L, M, N, O, P, Q, R graph and D, E, G, H).
To get the sub graph I used below cypher query :
MATCH (n) where n.score IN [4,5,6,7,8,12,13] AND NONE(l IN labels(n) WHERE l=~'Tes.*')
MATCH path = (n)-[l]->(m) where m.score IN [4,5,6,7,8,12,13]
UNWIND nodes(path) as node
RETURN node
I got the sub graph like below
Please suggest How to apply cosine similarity between graphs (L, M, N, O, P, Q, R graph and D, E, G, H).
You are almost there in getting the cosine similarity. You just need to collect the distinct scores. For reference, also look at this website. https://neo4j.com/docs/graph-algorithms/current/algorithms/similarity-cosine/
MATCH (n) where n.score IN [4,5,6,7,8,12,13] AND NONE(l IN labels(n) WHERE l=~'Tes.*')
MATCH (t: Test)
MATCH path = (n)-[l]->(m) where m.score IN [4,5,6,7,8,12) AS similarity,13]
UNWIND nodes(path) as node
RETURN algo.similarity.cosine(
collect(node.score), collect(m.score)) AS similarity
Result:
similarity
0.9733970633316996

Topological sort in Gremlin

Using the Gremlin/TinkerPop query language, is there a way to compute the topological ordering of a directed acyclic graph?
For example, given a graph with the following edges
a -> b, a -> d, b -> c, c -> d, e -> c
I would like to obtain one of the following topological orderings: a, b, e, c, d, or a, e, b, c, d, or e, a, b, c, d.
Alright, let's create your sample graph first:
g = TinkerGraph.open().traversal()
g.addV(id, "a").as("a").
addV(id, "b").as("b").
addV(id, "c").as("c").
addV(id, "d").as("d").
addV(id, "e").as("e").
addE("link").from("a").to("b").
addE("link").from("a").to("d").
addE("link").from("b").to("c").
addE("link").from("c").to("d").
addE("link").from("e").to("c").iterate()
And this is Kahn's algorithm implemented in Gremlin:
gremlin> g.V().not(__.inE()).store("x").
repeat(outE().store("e").inV().not(inE().where(without("e"))).store("x")).
cap("x")
==>[v[a],v[b],v[e],v[c],v[d]]

Cypher: Exclude shared nodes?

I have what feels like a fairly simple Cypher question.
I have the following data, where I have two A nodes and 3 B nodes with b1 being related to a1, b2 related to a2, and b3 is shared and related to both a1 and a2. My goal is write a Cypher statement that, given a particular A node, will return the B nodes that are connected only to it and are not related with any other A node. For example, when given node a1 the query should return b1 and when given node a2, b2 should be returned. The b3 node, which is relate to both a1 and a2, should never be returned from this query regardless of which A node is specified. Said differently, I am trying to find the B nodes that are unique to a given A node, in that the resulting B nodes are not related to any other A node other than the one specified in my match.
This example data will (hopefully) make my goal more clear:
CREATE (n:A { code: 'a1' })
CREATE (n:A { code: 'a2' })
CREATE (n:B { code: 'b1' })
CREATE (n:B { code: 'b2' })
CREATE (n:B { code: 'b3' })
match (a:A), (b:B) where a.code = 'a1' and b.code = 'b1' create (a)<-[r:A_AND_B]-(b) return a, r, b
match (a:A), (b:B) where a.code = 'a2' and b.code = 'b2' create (a)<-[r:A_AND_B]-(b) return a, r, b
match (a:A), (b:B) where a.code = 'a1' and b.code = 'b3' create (a)<-[r:A_AND_B]-(b) return a, r, b
match (a:A), (b:B) where a.code = 'a2' and b.code = 'b3' create (a)<-[r:A_AND_B]-(b) return a, r, b
If I were willing to include the shared b3 node, the query would be straight forward and be:
match (a:A)-[r:A_AND_B]-(b:B) where a.code = 'a1' return b
This returns b1 and b2. However, given that I do want to include any B nodes that are relate to a different A node (b2 should not be returned in this case), I'm struggling to come up with the right approach and syntax.
I've explored explored Cypher's WITH and OPTIONAL MATCH with so far no luck. I am also able to accomplish what I want if I use two separate queries, which is a bit of a cheat and sidesteps the learning opportunity.
Can someone provide a boost?
How about something like this:
match (a:A)-[:A_AND_B]-(b:B)
where a.code = 'a1'
match (b)-[r:A_AND_B]-(:A)
with b, count(r) as c
where c = 1
return b

Resources