<style type="text/css" media="screen"> /* .nodes-image { margin:-100; } */ @import url("//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"); .imageblock .content img, .image img {max-width: 900px;max-height: 300px;} .deck h3, .deck h4 {display: block !important;margin-bottom:8px;margin-top:5px;} .listingblock {margin:8px;} .pull-bottom {position:relative;bottom:1em;} .admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default} .admonitionblock td.icon .icon-note:before{content:"\f05a";color:#19407c} .admonitionblock td.icon .icon-tip:before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111} .admonitionblock td.icon .icon-warning:before{content:"\f071";color:#bf6900} .admonitionblock td.icon .icon-caution:before{content:"\f06d";color:#bf3400} .admonitionblock td.icon .icon-important:before{content:"\f06a";color:#bf0000} .admonitionblock.note.speaker { display:none; } </style> <style type="text/css" media="screen"> /* #editor.maximize-editor .CodeMirror-code { font-size:24px; line-height:26px; } */ </style> <article class="guide" ng-controller="AdLibDataController"> <carousel class="deck container-fluid"> <!--slide class="row-fluid"> <div class="col-sm-3"> <h3>Cypher: A data exploration of D-BAS</h3> <p class="lead">Information</p> <!dl> </dl> </div> <div class="col-sm-9"> <figure> <img style="width:300px" src=""/> </figure> </div> </slide--> <h4>Cypher: A data exploration of D-BAS</h4> <slide class="row-fluid"> <div class="col-sm-12"> <h3>D-BAS</h3> <br/> <div> <div class="imageblock" style="float: right;"> <div class="content"> <img src="https://dbas.cs.uni-duesseldorf.de/static/images/logo/black.svg?x=1549315407" alt="black" width="200"> </div> </div> <div class="paragraph"> <p><a href="https://dbas.cs.uni-duesseldorf.de">D-BAS</a> is a dialog-based argumentation system which presents its discussions within a graph structure.</p> </div> <div class="paragraph"> <p>The discussion graph is stored internally in the form of tables.</p> </div> <div class="paragraph"> <p>This presentation will convert the tabular representation of the data into a graph structure and explain suitable <a href="https://neo4j.com/developer/cypher-query-language/">Cypher</a> requests.</p> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Connect to the D-BAS database</h3> <br/> <div> <div class="paragraph"> <p>Since this tool is located in the same network as D-BAS, the containers <strong>web</strong> and <strong>db</strong> can be addressed. Therefore, queries can be sent directly to the D-BAS database. So that Neo4j can submit the requests to PostgreSQL, the plugins <a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/">APOC</a> and the <a href="https://jdbc.postgresql.org/">PostgreSQL JDBC Driver</a> are provided.</p> </div> <div class="paragraph"> <p>The following example connects Neo4J to the D-BAS database <strong>db</strong>.</p> </div> <div class="paragraph"> <p>Please enter the password of <strong>db</strong>:</p> </div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> Table: <input style="display:inline;width:30%;" value-for="table" class="form-control" value="textversions" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + '<span value-key="password">FooBar</span>' AS url CALL apoc.load.jdbc(url, '<span value-key="table">textversions</span>') YIELD row RETURN row<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Creating the statement nodes</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + '<span value-key="password">FooBar</span>' AS url CALL apoc.load.jdbc(url, 'statements') YIELD row MERGE (a:Statement{uid:row.uid, is_position:row.is_position, is_disabled:row.is_disabled}) RETURN a<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Filling the statement nodes with textversions</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + 'FooBar' AS url CALL apoc.load.jdbc(url, 'textversions') YIELD row MATCH (a:Statement{uid:row.statement_uid}) WHERE NOT EXISTS(a.content) SET a += {content:row.content} RETURN a<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Creating the user nodes</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + '<span value-key="password">FooBar</span>' AS url CALL apoc.load.jdbc(url, 'users') YIELD row MERGE (a:User{uid:row.uid, public_nickname:row.public_nickname}) RETURN a<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Create relation between Users and Statements</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + '<span value-key="password">FooBar</span>' AS url CALL apoc.load.jdbc(url, 'textversions') YIELD row MATCH (a:User), (b:Statement) WHERE a.uid = row.author_uid AND b.uid = row.statement_uid MERGE (a)-[r:HAS_WRITTEN]->(b) RETURN a, b, r<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Create issue nodes</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + 'FooBar' AS url CALL apoc.load.jdbc(url, 'issues') YIELD row MERGE (a:Issue{uid:row.uid, title:row.title}) RETURN a<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Connect statements with issues</h3> <br/> <div> Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + 'FooBar' AS url CALL apoc.load.jdbc(url, 'statement_to_issue') YIELD row MATCH (a:Statement{uid:row.statement_uid}), (b:Issue{uid:row.issue_uid}) MERGE (a)-[r:WRITTEN_IN]->(b) RETURN a,b,r<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Every User who has written a Position likes it</h3> <br/> <div> Rating between 0 and : <input style="display:inline;width:30%;" value-for="max_rating" class="form-control" value="2" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (a:User)-[:HAS_WRITTEN]->(b:Statement{is_position:True}) MERGE (a)-[r:LIKES{rating:toInt('<span value-key="max_rating">2</span>')}]->(b) RETURN a, b, r<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Every User who has written none gets a random rating for a Position</h3> <br/> <div> Rating between 0 and : <input style="display:inline;width:30%;" value-for="max_rating" class="form-control" value="2" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (a:User) WHERE NOT EXISTS((a)-[:LIKES]->()) MATCH (b:Statement) WHERE b.is_position MERGE (a)-[:LIKES{rating:round(rand()*toInt('<span value-key="max_rating">2</span>'))}]->(b)<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Delete every Rating with 0.0</h3> <br/> <div> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH ()-[r:LIKES{rating:0.0}]->() DETACH DELETE r<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get sub-graph</h3> <br/> <div> Uid between 0 and : <input style="display:inline;width:30%;" value-for="max_number" class="form-control" value="10" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (a:User), (b:Statement{is_position:True}) WHERE a.uid in range(0, toInt('<span value-key="max_number">10</span>')) RETURN a,b<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get k-nearest-neighbours with Pearson-Correlation</h3> <br/> <div> Find top <input style="display:inline;width:30%;" value-for="k_neighbors" class="form-control" value="5" size="40">-neighbors for <input style="display:inline;width:30%;" value-for="user" class="form-control" value="Björn" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:User {public_nickname: '<span value-key="user">Björn</span>'})-[l:LIKES]->(statement) WITH p1, algo.similarity.asVector(statement, l.rating) AS p1Vector MATCH (p2:User)-[l:LIKES]->(statement) WHERE p2 <> p1 WITH p1, p2, p1Vector, algo.similarity.asVector(statement, l.rating) AS p2Vector RETURN p1.public_nickname AS from, p2.public_nickname AS to, algo.similarity.pearson(p1Vector, p2Vector, {vectorType: "maps"}) AS similarity ORDER BY similarity DESC LIMIT toInt('<span value-key="k_neighbors">5</span>')<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get two User and their connection</h3> <br/> <div> User A: <input style="display:inline;width:30%;" value-for="user_a" class="form-control" value="Björn" size="40"> User B: <input style="display:inline;width:30%;" value-for="user_b" class="form-control" value="Christian" size="40"> <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->match (a:User{public_nickname:'<span value-key="user_a">Björn</span>'}), (b:User{public_nickname:'<span value-key="user_b">Christian</span>'}), (s:Statement) WHERE (a)-[:LIKES]->(s) or (b)-[:LIKES]->(s) return a,b,s<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get Top-N Prediction for User with Pearson-Similarity + Weighted-Average + kNN</h3> <br/> <div> Find Top-<input style="display:inline;width:30%;" value-for="top_n" class="form-control" value="5" size="40"> Predictions for <input style="display:inline;width:30%;" value-for="user" class="form-control" value="Björn" size="40"> in the <input style="display:inline;width:30%;" value-for="k_neighbors" class="form-control" value="5" size="40">-NN <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:User {public_nickname: '<span value-key="user">Björn</span>'})-[l:LIKES]->(statement) WITH p1, algo.similarity.asVector(statement, l.rating) AS p1Vector MATCH (p2:User)-[l:LIKES]->(statement) WHERE p2 <> p1 WITH p1, p2, p1Vector, algo.similarity.asVector(statement, l.rating) AS p2Vector WITH p1 AS from, p2 AS to, algo.similarity.pearson(p1Vector, p2Vector, {vectorType: "maps"}) AS similarity ORDER BY similarity DESC limit toInt('<span value-key="k_neighbors">5</span>') MATCH (to)-[r:LIKES]->(s:Statement) WHERE NOT EXISTS((from)-[:LIKES]->(s)) RETURN from , to, s, sum(similarity * r.rating)/FILTER(x in [sum(abs(similarity)), 1] WHERE NOT x=0)[0] AS prediction ORDER BY prediction DESC LIMIT toInt('<span value-key="top_n">5</span>')<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get Top-N Prediction for User with Pearson-Similarity + Mean-Centering + kNN</h3> <br/> <div> Find Top-<input style="display:inline;width:30%;" value-for="top_n" class="form-control" value="5" size="40"> Predictions for <input style="display:inline;width:30%;" value-for="user" class="form-control" value="Björn" size="40"> in the <input style="display:inline;width:30%;" value-for="k_neighbors" class="form-control" value="5" size="40">-NN <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:User {public_nickname: '<span value-key="user">Björn</span>'})-[l:LIKES]->(statement) WITH p1, algo.similarity.asVector(statement, l.rating) AS p1Vector, avg(l.rating) as u1_avg MATCH (p2:User)-[l:LIKES]->(statement) WHERE p2 <> p1 WITH p1, p2, u1_avg, p1Vector, algo.similarity.asVector(statement, l.rating) AS p2Vector, avg(l.rating) as u2_avg WITH p1 AS from, p2 AS to, algo.similarity.pearson(p1Vector, p2Vector, {vectorType: "maps"}) AS similarity, u1_avg, u2_avg ORDER BY similarity DESC limit toInt('<span value-key="k_neighbors">5</span>') MATCH (to)-[r:LIKES]->(s:Statement) WHERE NOT EXISTS((from)-[:LIKES]->(s)) RETURN from , to, s, u1_avg + sum(similarity * (r.rating-u2_avg))/FILTER(x in [sum(abs(similarity)), 1] WHERE NOT x=0)[0] AS prediction ORDER BY prediction DESC LIMIT toInt('<span value-key="top_n">5</span>')<!--/code--></pre> </div> </div> </div> </div> </slide> <slide class="row-fluid"> <div class="col-sm-12"> <h3>Get Top-N Prediction for User with Pearson-Similarity + Z-Score-Normalization + kNN</h3> <br/> <div> Find Top-<input style="display:inline;width:30%;" value-for="top_n" class="form-control" value="5" size="40"> Predictions for <input style="display:inline;width:30%;" value-for="user" class="form-control" value="Björn" size="40"> in the <input style="display:inline;width:30%;" value-for="k_neighbors" class="form-control" value="5" size="40">-NN <div class="listingblock"> <div class="content"> <pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:User {public_nickname: '<span value-key="user">Björn</span>'})-[l:LIKES]->(statement) WITH p1, algo.similarity.asVector(statement, l.rating) AS p1Vector, avg(l.rating) as u1_avg, stDev(l.rating) as u1_std MATCH (p2:User)-[l:LIKES]->(statement) WHERE p2 <> p1 WITH p1, p2, u1_avg, u1_std, p1Vector, algo.similarity.asVector(statement, l.rating) AS p2Vector, avg(l.rating) as u2_avg, stDev(l.rating) as u2_std WITH p1 AS from, p2 AS to, algo.similarity.pearson(p1Vector, p2Vector, {vectorType: "maps"}) AS similarity, u1_avg, u1_std, u2_avg, u2_std ORDER BY similarity DESC limit toInt('<span value-key="k_neighbors">5</span>') MATCH (to)-[r:LIKES]->(s:Statement) WHERE NOT EXISTS((from)-[:LIKES]->(s)) RETURN from , to, s, u1_avg + u1_std* sum(similarity*(r.rating-u2_avg)/u2_std)/FILTER(x in [sum(abs(similarity)), 1] WHERE NOT x=0)[0] AS prediction ORDER BY prediction DESC LIMIT toInt('<span value-key="top_n">5</span>')<!--/code--></pre> </div> </div> </div> </div> </slide> </carousel> </article>