{"id":135,"date":"2019-11-05T04:17:24","date_gmt":"2019-11-05T03:17:24","guid":{"rendered":"https:\/\/blog.wofuer.com\/?p=135"},"modified":"2019-11-05T12:58:26","modified_gmt":"2019-11-05T11:58:26","slug":"neo4j-learning-accelerator","status":"publish","type":"post","link":"https:\/\/blog.wofuer.com\/?p=135","title":{"rendered":"Neo4j learning accelerator"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Neo4j is a graph database and queried via CYPHER. An Commercial Version incl. the Neo4j-Browser you can download <a href=\"https:\/\/neo4j.com\/download\/\">here<\/a>.  Neo4j Enterprise as open source under the AGPLv3 open source license created by the Free software foundation you can find <a href=\"https:\/\/igovsol.com\/downloads.html\">here<\/a>.<\/p>\n\n\n\n<p>Further Examples are described on Windows platform.<\/p>\n\n\n\n<p>Start &#8220;Neo4j Desktop&#8221; and just great a new graph. The APOC procedures makes the world much more easy and just has to be downloaded from GitHub <a href=\"https:\/\/github.com\/neo4j-contrib\/neo4j-apoc-procedures\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Helpful Queries<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Playing with e-Mails<\/h3>\n\n\n\n<p>Find all nodes, cut the relationships and delete them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (n) DETACH DELETE n;<\/code><\/pre>\n\n\n\n<p>Create a node &#8211; relationship &#8211; node with properties.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE (m:Instance {name: \"Sven\"})-[n:SENT {subject: \"Likes\"}]->(o:Instance {name: \"Anna\"});<\/code><\/pre>\n\n\n\n<p>Delete a node where a certain property does not exist.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (n) WHERE NOT exists(n.name) DETACH DELETE n;<\/code><\/pre>\n\n\n\n<p>Delete a special constellation (sender\/receiver according subject without direction of the mail).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (m)--(n:SENT)--(o) where n.subject=\"Hates\" DETACH DELETE m,n,o<\/code><\/pre>\n\n\n\n<p>Import data from an CSV-File (to be stored in the import folder) and create some relations. In the following example and export of Outlook Inbox. The sender\/receiver is created with the label &#8220;Instance&#8221; and the property &#8220;name&#8221;. The relationship is created with the label &#8220;SENT&#8221; and the property &#8220;subject&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LOAD CSV FROM 'file:\/\/\/Inbox.csv' as line \nCREATE (:Instance {name: line[1]})-[:SENT {subject: line[0]}]->(:Instance {name: line[2]});<\/code><\/pre>\n\n\n\n<p>Find all nodes with the label &#8220;Instance&#8221; with the property &#8220;name&#8221; and build nodelist that will gone through until there is only one node remaining. Before that all nodes with the same node-property &#8220;name&#8221; are merged into one. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (n:Instance) WITH n.name AS name, COLLECT(n) AS nodelist, COUNT(*) AS count WHERE count > 1\nCALL apoc.refactor.mergeNodes(nodelist) YIELD node RETURN node;<\/code><\/pre>\n\n\n\n<p>Split a node according the string of an property and create multiple nodes out of it with the same relationship (point out every receiver of a mail individually).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (l)-[m]->(n:Instance) WHERE n.name CONTAINS \";\" WITH l,m,n, SPLIT(n.name, \";\") as oneInstance\nUNWIND RANGE (0,SIZE(oneInstance)-1) as i MERGE (p:Instance {name: l.name})-[q:SENT {subject: m.subject}]->(o:Instance {name: oneInstance[i]}) RETURN p,q,n,o;<\/code><\/pre>\n\n\n\n<p>Delete nodes that contain a certain substring within the property &#8220;name&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (n) where n.name CONTAINS \";\" DETACH DELETE n;<\/code><\/pre>\n\n\n\n<p>Finally as one executable block:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MATCH (n) DETACH DELETE n;\nLOAD CSV FROM 'file:\/\/\/Inbox.csv' as line \nCREATE (:Instance {name: line[1]})-[:SENT {subject: line[0]}]->(:Instance {name: line[2]});\nMATCH (l)-[m]->(n:Instance) WHERE n.name CONTAINS \";\" WITH l,m,n, SPLIT(n.name, \";\") as oneInstance\nUNWIND RANGE (0,SIZE(oneInstance)-1) as i MERGE (p:Instance {name: l.name})-[q:SENT {subject: m.subject}]->(o:Instance {name: oneInstance[i]}) RETURN p,q,n,o;\nMATCH (n:Instance) WITH n.name AS name, COLLECT(n) AS nodelist, COUNT(*) AS count WHERE count > 1\nCALL apoc.refactor.mergeNodes(nodelist) YIELD node RETURN node;\nMATCH (n) where n.name CONTAINS \";\" DETACH DELETE n;\nMATCH (n) WHERE NOT exists(n.name) DETACH DELETE n;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Neo4j is a graph database and queried via CYPHER. An Commercial Version incl. the Neo4j-Browser you can download here. Neo4j Enterprise as open source under the AGPLv3 open source license created by the Free software foundation you can find here. Further Examples are described on Windows platform. Start &#8220;Neo4j Desktop&#8221; and just great a &#8230; <a title=\"Neo4j learning accelerator\" class=\"read-more\" href=\"https:\/\/blog.wofuer.com\/?p=135\" aria-label=\"Read more about Neo4j learning accelerator\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[20,21],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-software","tag-cypher","tag-neo4j"],"_links":{"self":[{"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135"}],"version-history":[{"count":5,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":142,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions\/142"}],"wp:attachment":[{"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wofuer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}