Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-23-2018 07:05 AM
Hi All,
I am trying to show the top 10 node in the graph and below is the query I tried in neo4j browser,
MATCH (p1:Username)-[r:sent]->(p2:Username)
RETURN p1, count(*) AS count
ORDER BY count DESC LIMIT 10
As below image shows the top 10 nodes with their relationship
Similarly I am trying to show the graph using neovis.js and I can able to show the top 10 nodes in the visualization but not sure why the relationships are not showing in the graph.
Below is the response,
neovis javascript function,
function draw() {
var config = {
container_id: "viz",
server_url: "bolt://localhost:7687",
arrows: true,
labels: {
"Username": {
"caption": "mail_id",
"size": "pagerank",
"community": "partition"
}
},
relationships: {
"sent": {
"thickness": "count",
"caption": false
}
},
initial_cypher: "MATCH (p1:Username)-[r:sent]->(p2:Username) RETURN p1, count(*) AS count ORDER BY count DESC LIMIT 10"
};
viz = new NeoVis.default(config);
viz.render();
}
Please correct me If am doing anything wrong in the query and let me know your thoughts.
Regards,
Ganeshbabu R
10-23-2018 03:14 PM
You also have to return the relationships.
e.g.
MATCH (p1:Username)
with p1, size((p1)-[r:sent]->()) as count
order by count desc limit 10
match (p1)-[r]->()
RETURN p1, r
10-24-2018 07:10 AM
Thanks @michael.hunger
Yes it solved the problem..
Also similar problem I am facing now and we have two nodes (Username & Topics) and I am trying to show the top topics which discussed among the users and below is the query to load the data to neo4j
LOAD CSV WITH HEADERS FROM "file:///data_email.csv" AS row
WITH row WHERE row.message_subject <> 'none' AND row.keywords <> 'none'
MERGE (p1:Username {mail_id: row.sender_address}) ON CREATE SET p1.timestamp = row.date_time
MERGE (p2:Username {mail_id: row.recipient_address})
MERGE (p3:Topic {topic: row.keywords})
WITH p1, p2, p3, row, COUNT(*) AS count
MERGE (p1)-[r1:sent]->(p2) ON CREATE SET r1.time = row.date_time, r1.count = count
MERGE (p1)-[r2:sender_interest]->(p3)<-[r3:receiver_interest]-(p2) ON CREATE SET r2.sentcount = count, r3.receivecount = count
After I loaded the data to neo4j below is the query I tried to show the top 10 topics with the users in neo4j browser,
MATCH (p1:Username)-[r2:sender_interest]->(t:Topic)
WITH p1, t, count(r2) as count
RETURN p1.mail_id as sender, t.topic as topics, count
ORDER BY count DESC
LIMIT 10
Response of the query,
Now I am trying to show the top 10 topics using neovis.js but don't know why the data is not showing up and I wanted to show the thickness based on the relationship count.
**Below is the neovis javascript function,
**
var config = {
container_id: "viz",
server_url: "bolt://localhost:7687",
arrows: true,
labels: {
"Username": {
"caption": "mail_id",
"size": "pagerank",
"community": "partition"
},
"Topic": {
"caption": "topic"
}
},
relationships: {
"sender_interest": {
"thickness": "sentcount",
"caption": false
}
},
initial_cypher: "MATCH (p1:Username),(p3:Topic) with p1, p3, size((p1:Username)-[:senderinterest]-(p3:Topic)) as count order by count desc limit 10 MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r"
};
Also I am having less confident of the way I have set the count value for interest relationship.
Please correct me If I am doing anything wrong.
Regards,
Ganeshbabu R
10-25-2018 08:30 AM
Hi,
Try this query to get topic and total number of users discussed.
MATCH (t:Topic)-[:sender_interest]-(p)
WITH t, count(distinct p) as Cnt
MATCH (t)-[:receiver_interest]-(q)
WITH t, count(distinct q) + Cnt as Tot
RETURN t.topic, Tot;
Here is the result with your previously published data with one topic:
-Kamal
06-15-2022 07:54 AM
Then how/why does the neo4j browser show the relations even though they are not specified to be returned
10-24-2018 03:22 PM
To test it I recommend running these in neo4j browser and work step by step in your query.
Are you actually looking for users that have sent a lot or topics that got a lot
or the same topic and user that had most interactions?
You can simplify this:
MATCH (p1:Username)
with p1, size((p1)-[:senderinterest]->()) as count
order by count desc limit 10
MATCH (p1)-[r:senderinterest]->(p3) RETURN p1, p3, r
12-27-2018 09:39 PM
Hey babu
I want to know how do you get the similar color for the nodes .
I ran this code -
CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition',
weightProperty:'count'})
And this is my Neovis.js code. Please help.
I tried using the community label everywhere in my config variable but still no change in nodes
var config = {
container_id: "viz",
server_url: "bolt://localhost:11001/",
server_user: "neo4j",
server_password: "781",
labels: {
"ngoconnectionserviceimplhttpsoap11endpoint": {
"thickness": "weight",
"caption": true,
"community": "partition",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"ngoconnectionserviceimplhttpsoap12endpoint": {
"thickness": "weight",
"caption": true,
"community": "partition",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"connparams_2": {
"thickness": "weight",
"caption": true,
"community": "partition",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"connparams": {
"thickness": "weight",
"caption": true,
"community": "partition",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
},
relationships: {
"Parameter": {
"thickness": "weight",
"caption": true,
"community": "partition",
'
},
"Method": {
"thickness": "weight",
"caption": true,
"community": "partition"
},
"Department": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
},
cluster_labels: {
"Parameter": "community"
},
initial_cypher:cypherQuery ,
arrows: true,
hierarchical_layout:true,
hierarchical_sort_method:"directed",
};
Please help. I ain't getting any clustered uniform color.
Output -
01-08-2019 03:00 PM
@sucheta- can you verify that running label propagation identified several distinct communities or reasonable size (and not just that you end with many communities with few nodes in each)? For example, if you run
MATCH (n:connparams)
WITH COLLECT(id(n)) AS community, n.partition AS partition
RETURN partition, SIZE(community) AS num ORDER BY num DESC LIMIT 25
this will show you the size of the 25 largest communities.
01-08-2019 09:56 PM
@William_Lyon
Thanks for the reply.
I got this result -
How does it affect the color of my nodes in Neovis.js.
Does it mean that there are 21 nodes connected to connparams that have same color ?
Also ,
Is this definition correct -
"connparams": {
"thickness": "weight",
"caption": true,
"community": "partition",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
Kindly guide so that i get same color for a set of nodes.
01-08-2019 10:42 PM
you only have one community with size 1
your label propagation algorithm didn't run correctly.
01-09-2019 04:41 AM
Hi michael,
I ran the above query . Can you please point out what is wrong with it. I saw this query on the video of -
01-09-2019 04:52 AM
If it ran correctly you should see many more partitions.
Or at most a partition with size > 1
01-09-2019 05:03 AM
Thanks Michael. But i don't know where i am going wrong. Please suggest.
01-09-2019 01:57 PM
what does this output?
CALL algo.labelPropagation.stream(null,null,'OUTGOING')
you should see each node with its partition.
01-09-2019 01:57 PM
also can you show the tabular output of a
match (n) return n limit 10
in neo4j browser.
01-09-2019 09:05 PM
The output of this query -
CALL algo.labelPropagation.stream(null,null,'OUTGOING')
Output -
Error -
Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Map, Node or Relationship but was String (line 1, column 53 (offset: 52))
"CALL algo.labelPropagation.stream(null,null,'OUTGOING')"
^
And the output of -
match (n) return n limit 10
is -
{
"name": "abc",
"partition": 2
}
{
"name": "def",
"company": "abc",
"partition": 46
}
{
"name": "ghi",
"company": "abc",
"partition": 46
}
{
"name": "NGOConnectionServiceImpl",
"company": "abc",
"partition": 52
}
{
"name": "NGOConnectionServiceImplHttpSoap11Endpoint",
"company": "abc",
"partition": 10
}
{
"name": "disconnectCab",
"company": "abc",
"partition": 11
}
{
"name": "input",
"company": "abc",
"partition": 9
}
{
"name": "disconParams",
"company": "abc",
"partition": 9
}
{
"name": "cabinetName",
"company": "abc",
"partition": 8
}
{
"name": "userDbId",
"company": "abc",
"partition": 9
}
01-10-2019 03:30 AM
what was the cypher query for your neoviz? you did not show it up there.
it seems that some of your nodes have a partition property but not clear if those are the right labels you use in the visualization.
do your nodes have a single label or multiple labels?
match (n)
where n:ngoconnectionserviceimplhttpsoap11endpoint
or n:connparams
or n:ngoconnectionserviceimplhttpsoap12endpoint
or n:connparams_2
return n, labels(n)
limit 10
01-10-2019 05:58 AM
Hi Michael,
The original cypherQuery for my neovis is -
var cypherQuery = "MATCH (n)-[r]->(m) RETURN n,r,m;";
The output for the query you mentioned is -
var cypherQuery = `match (n)
where n:ngoconnectionserviceimplhttpsoap11endpoint
or n:connparams
or n:ngoconnectionserviceimplhttpsoap12endpoint
or n:connparams_2
return n, labels(n)
limit 10`
output -
The output for the cypherQuery is -
var cypherQuery = `match (n) -[r]->(m)
where n:ngoconnectionserviceimplhttpsoap11endpoint
or n:connparams
or n:ngoconnectionserviceimplhttpsoap12endpoint
or n:connparams_2
return n,r,m, labels(n)
limit 50`
output -
01-10-2019 01:43 PM
As you can see you only have one node for each label.
Did you understand the concept of labels in Neo4j?
They are like types or "tables" or "collections" in other databases.
So you should have hundreds or millions of nodes with the same lable, like "Person" or "Product" or "Location".
And for those labels the configuration in neovis holds the information on how to render them.
So in a real graph you would have a (:Person)-[:KNOWS]-(:Person)
Where people would form clusters/communities.
And you would configure neovis for the "Person" label to use the partition property to color those clusters.
01-14-2019 04:44 AM
Hi Michael,
I changed my queries to incorporate the labels. Here are a few query examples -
'Match (cabinet_2:Organization) where cabinet_2.name ="cabinet_2" and cabinet_2.company="cateina" Create (privileges_2: Department{name:\'privileges_2\',company:\'cateina\'}), (cabinet_2)-[:Department]->(privileges_2)' ,
'Match (disconnectcab:Method) where disconnectcab.name ="disconnectcab" and disconnectcab.company="cateina" Create (input:Request{name:\'input\',company:\'cateina\'}), (disconnectcab)-[:Request]->(input) ',
'Create (lockbyuser_2:Parameter{name:\'lockbyuser_2\',company:\'cateina\'}), (cabinet_2)-[:Parameter]->(lockbyuser_2) ',
'Match (cabinet_2:Parameter) where cabinet_2.name ="cabinet_2" and cabinet_2.company="cateina" Create (loginuserrights_2:Parameter{name:\'loginuserrights_2\',company:\'cateina\'}), (cabinet_2)-[:Parameter]->(loginuserrights_2) ',
...etc.
And then i ran this query ->
CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition', weightProperty:'count'})
And i configured my neovis.js as -
var config = {
container_id: "viz",
server_url: "bolt://localhost:11001/",
server_user: "neo4j",
server_password: "Virtuallib1",
labels: {
//"Character": "name",
"Organization": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"Parameter": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"Department": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
},
"Request": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"Response": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"Paths": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"API": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"System": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"Service": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"Operation": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
"Method": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
},
},
relationships: {
"Parameter": {
"thickness": "weight",
"caption": true,
"community": "partition",
"color":'red'
},
"Method": {
"thickness": "weight",
"caption": true,
"community": "Blue",
},
"Request": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
"Response": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
"Paths": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
"API": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
"Department": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
"System": {
"thickness": "weight",
"caption": true,
"community": "partition",
},
},
cluster_labels: {
"Parameter": "partition"
},
initial_cypher:cypherQuery ,
arrows: true,
hierarchical_layout:true,
hierarchical_sort_method:"directed",
};
this.viz = new NeoVis.default(config);
this.viz.render();
console.log(this.viz);
}
However, i get the same color for all the labels. Like -
But i want different color for every label. Please help
01-15-2019 05:33 AM
What are the different communities for your labels now?
match (n)
return head(labels(n)) as lab, n.partition as partition, count(*) as count
order by label, count desc;
01-16-2019 08:45 PM
Hi Michael,
The output for the query you mentioned is a Syntax error.
First i ran this cypher -
CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition', weightProperty:'count'})
O/p -
Then i ran this command -
match (n)
return head(labels(n)) as lab, n.partition as partition, count(*) as count
order by label, count desc;
o/p -
Please suggest
01-17-2019 03:46 AM
You should be able by now to fix it yourself
match (n)
return head(labels(n)) as label, n.partition as partition, count(*) as count
order by label, count desc;
01-17-2019 04:00 AM
Sorry michael, but i don't understand the result and how to interpret it so as to solve my issue of color.
O/p is -
Please help
01-17-2019 02:22 PM
01-18-2019 03:18 AM
I have mixed property name - partition vs. community . Because i entered -> partition in the below query -
CALL algo.labelPropagation(null,null,'OUTGOING',{write:true, partitionProperty:'partition', weightProperty:'count'})
And when i defined the config file -
"community" : "partition"
The nodes donot get the responsive color. However, when i entered "community" : "community" i get proper output for the label defined in config variable.
labels: {
"Parameter": {
"thickness": "weight",
"caption": "name",
"size": "pagerank",
"community": "community",
"sizeCypher": "MATCH (n) WHERE id(n) = {id} MATCH (n)-[r]-() RETURN sum(r.weight) AS c"
}
}
Please explain as to why i get same color for Nodes with label - Parameter, even though they also have count 1-2
label partition count
|"Operation"| 622| 1|
|"Organization"| 2| 1|
|"Parameter"| 640| 3|
|"Parameter"| 631| 3|
01-18-2019 11:08 AM
Probably a limit of colors.
I think you have a better way of trying a simple setup
Where you set (a few, e.g. two) labels and properties manually (partition, pagerank) on a few (e.g. 10-20 nodes) and see how they are rendered and take it from there. I think in your current graph you have too many moving parts that might be confusing.
You can also follow the example from neovis that uses the Game of Thrones graph interaction graph.
All the sessions of the conference are now available online