Skip to content
Snippets Groups Projects
Commit 3052144e authored by Marc Feger's avatar Marc Feger
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
Showing
with 1096 additions and 0 deletions
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
.idea/
\ No newline at end of file
FROM python:3.7.2-alpine3.9
ENV PYTHONPATH /code
RUN apk update && \
apk upgrade && \
apk add bash && \
apk add asciidoctor && \
apk add ruby-rdoc && \
gem install concurrent-ruby && \
gem install tilt
COPY requirements.txt /code/api/requirements.txt
RUN pip3.7 install -U pip && \
pip3.7 install -r /code/api/requirements.txt
COPY . /code/api
= Cypher: A data exploration of D-BAS
== D-BAS
image::https://dbas.cs.uni-duesseldorf.de/static/images/logo/black.svg?x=1549315407[width=200,float=right]
https://dbas.cs.uni-duesseldorf.de[D-BAS] is a dialog-based argumentation system which presents its discussions within a graph structure.
The discussion graph is stored internally in the form of tables.
This presentation will convert the tabular representation of the data into a graph structure and explain suitable https://neo4j.com/developer/cypher-query-language/[Cypher] requests.
== Connect to the D-BAS database
:password: pass:a['<span value-key="password">FooBar</span>']
:table: pass:a['<span value-key="table">textversions</span>']
Since this tool is located in the same network as D-BAS, the containers **web** and **db** 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 https://neo4j-contrib.github.io/neo4j-apoc-procedures/[APOC] and the https://jdbc.postgresql.org/[PostgreSQL JDBC Driver] are provided.
The following example connects Neo4J to the D-BAS database **db**.
Please enter the password of **db**:
++++
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">
++++
[source, cypher,subs=attributes]
----
WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + {password} AS url
CALL apoc.load.jdbc(url, {table})
YIELD row
RETURN row
----
== Creating the statement nodes
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + {password} 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
----
== Filling the statement nodes with textversions
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
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
----
== Creating the user nodes
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + {password} AS url
CALL apoc.load.jdbc(url, 'users')
YIELD row
MERGE (a:User{uid:row.uid, public_nickname:row.public_nickname})
RETURN a
----
== Create relation between Users and Statements
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
WITH 'jdbc:postgresql://db/discussion?user=postgres&password=' + {password} 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
----
== Create issue nodes
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
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
----
== Connect statements with issues
:password: pass:a['<span value-key="password">FooBar</span>']
++++
Password: <input style="display:inline;width:30%;" value-for="password" class="form-control" value="FooBar" size="40">
++++
[source, cypher,subs=attributes]
----
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
----
== Every User who has written a Position likes it
:max_rating: pass:a['<span value-key="max_rating">2</span>']
++++
Rating between 0 and : <input style="display:inline;width:30%;" value-for="max_rating" class="form-control" value="2" size="40">
++++
[source, cypher,subs=attributes]
----
MATCH (a:User)-[:HAS_WRITTEN]->(b:Statement{is_position:True})
MERGE (a)-[r:LIKES{rating:toInt({max_rating})}]->(b)
RETURN a, b, r
----
== Every User who has written none gets a random rating for a Position
:max_rating: pass:a['<span value-key="max_rating">2</span>']
++++
Rating between 0 and : <input style="display:inline;width:30%;" value-for="max_rating" class="form-control" value="2" size="40">
++++
[source, cypher,subs=attributes]
----
MATCH (a:User)
WHERE NOT EXISTS((a)-[:LIKES]->())
MATCH (b:Statement)
WHERE b.is_position
MERGE (a)-[:LIKES{rating:round(rand()*toInt({max_rating}))}]->(b)
----
== Delete every Rating with 0.0
[source, cypher,subs=attributes]
----
MATCH ()-[r:LIKES{rating:0.0}]->()
DETACH DELETE r
----
== Get sub-graph
:max_number: pass:a['<span value-key="max_number">10</span>']
++++
Uid between 0 and : <input style="display:inline;width:30%;" value-for="max_number" class="form-control" value="10" size="40">
++++
[source, cypher,subs=attributes]
----
MATCH (a:User), (b:Statement{is_position:True})
WHERE a.uid in range(0, toInt({max_number}))
RETURN a,b
----
== Get k-nearest-neighbours with Pearson-Correlation
:k_neighbors: pass:a['<span value-key="k_neighbors">5</span>']
:user: pass:a['<span value-key="user">Björn</span>']
++++
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">
++++
[source, cypher,subs=attributes]
----
MATCH (p1:User {public_nickname: {user}})-[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({k_neighbors})
----
== Get two User and their connection
:user_a: pass:a['<span value-key="user_a">Björn</span>']
:user_b: pass:a['<span value-key="user_b">Christian</span>']
++++
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">
++++
[source, cypher,subs=attributes]
----
match (a:User{public_nickname:{user_a}}), (b:User{public_nickname:{user_b}}), (s:Statement)
WHERE (a)-[:LIKES]->(s) or (b)-[:LIKES]->(s)
return a,b,s
----
== Get Top-N Prediction for User with Pearson-Similarity + Weighted-Average + kNN
:k_neighbors: pass:a['<span value-key="k_neighbors">5</span>']
:top_n: pass:a['<span value-key="top_n">5</span>']
:user: pass:a['<span value-key="user">Björn</span>']
++++
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
++++
[source, cypher,subs=attributes]
----
MATCH (p1:User {public_nickname: {user}})-[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({k_neighbors})
WHERE similarity <> 0.0
MATCH (to)-[r:LIKES]->(s:Statement) WHERE NOT EXISTS((from)-[:LIKES]->(s))
return from , to, s, sum(similarity * r.rating)/sum(abs(similarity)) as prediction
ORDER BY prediction DESC LIMIT toInt({top_n})
----
\ No newline at end of file
#!/usr/bin/env bash
asciidoctor $1 -T ./templates -a leveloffset=+1 -o $2
\ No newline at end of file
<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>')
WHERE similarity <> 0.0
MATCH (to)-[r:LIKES]->(s:Statement) WHERE NOT EXISTS((from)-[:LIKES]->(s))
return from , to, s, sum(similarity * r.rating)/sum(abs(similarity)) as prediction
ORDER BY prediction DESC LIMIT toInt('<span value-key="top_n">5</span>')<!--/code--></pre>
</div>
</div>
</div>
</div>
</slide>
</carousel>
</article>
\ No newline at end of file
Flask==0.10.1
flask-cors==3.0.7
\ No newline at end of file
from flask import Flask, render_template
from flask_cors import CORS
app = Flask(__name__, template_folder='.')
CORS(app)
@app.route('/<file>')
def root(file):
return render_template('html/' + file)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=5000)
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['admonitionblock',(attr :name),role].compact * ' ' %>">
<table>
<tr>
<td class="icon"><%
if @document.attr? :icons, 'font' %>
<i class="fa icon-<%= attr 'name' %>" title="<%= @caption %>"></i><%
elsif @document.attr? :icons %>
<img src="<%= icon_uri(attr :name) %>" alt="<%= @caption %>"><%
else %>
<div class="title label"><%= @caption %></div><%
end %>
</td>
<td class="content"><%
if title? %>
<div class="title label"><%= title %></div><%
end %>
<%= content %>
</td>
</tr>
</table>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['audioblock',@style,role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= captioned_title %></div><%
end %>
<div class="content">
<audio src="<%= media_uri(attr :target) %>"<%
if option? :autoplay %> autoplay<% end
unless option? :nocontrols %> controls<% end
if option? :loop %> loop<% end %>>
Your browser does not support the audio tag.
</audio>
</div>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['colist',@style,role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end
if @document.attr? :icons
font_icons = @document.attr? :icons, 'font' %>
<table><%
items.each_with_index do |item, i|
num = i + 1 %>
<tr>
<td><%
if font_icons %><i class="conum" data-value="<%= num %>"></i><b><%= num %></b><%
else %><img src="<%= icon_uri %(callouts/#{num}) %>" alt="<%= num %>"><%
end %></td>
<td><%= item.text %></td>
</tr><%
end %>
</table><%
else %>
<ol><%
items.each do |item| %>
<li>
<p><%= item.text %></p>
</li><%
end %>
</ol><%
end %>
</div>
<%#encoding:UTF-8%><%
case @style
when 'qanda'
%><div<%= @id && %( id="#{@id}") %> class="<%= ['qlist','qanda',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<ol><%
items.each do |questions, answer| %>
<li><%
[*questions].each do |question| %>
<p><em><%= question.text %></em></p><%
end
unless answer.nil?
if answer.text? %>
<p><%= answer.text %></p><%
end
if answer.blocks? %>
<%= answer.content %><%
end
end %>
</li><%
end %>
</ol>
</div><%
when 'horizontal'
%><div<%= @id && %( id="#{@id}") %> class="<%= ['hdlist',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<table><%
if (attr? :labelwidth) || (attr? :itemwidth) %>
<colgroup>
<col<%= (attr? :labelwidth) ? %( style="width: #{(attr :labelwidth).chomp '%'}%;") : nil %>>
<col<%= (attr? :itemwidth) ? %( style="width: #{(attr :itemwidth).chomp '%'}%;") : nil %>>
</colgroup><%
end
items.each do |terms, dd| %>
<tr>
<td class="hdlist1<%= (option? :strong) ? ' strong' : nil %>"><%
terms = [*terms]
last_term = terms.last
terms.each do |dt| %>
<%= dt.text %><%
if dt != last_term %>
<br><%
end
end %>
</td>
<td class="hdlist2"><%
unless dd.nil?
if dd.text? %>
<p><%= dd.text %></p><%
end
if dd.blocks? %>
<%= dd.content %><%
end
end %>
</td>
</tr><%
end %>
</table>
</div><%
else
%><div<%= @id && %( id="#{@id}") %> class="<%= ['dlist',@style,role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<dl><%
items.each do |terms, dd|
[*terms].each do |dt| %>
<dt<%= !@style ? ' class="hdlist1"' : nil %>><%= dt.text %></dt><%
end
unless dd.nil? %>
<dd><%
if dd.text? %>
<p><%= dd.text %></p><%
end
if dd.blocks? %>
<%= dd.content %><%
end %>
</dd><%
end
end %>
</dl>
</div><%
end %>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['exampleblock',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= captioned_title %></div><%
end %>
<div class="content">
<%= content %>
</div>
</div>
<%#encoding:UTF-8%><%= %(<h#{@level + 1}#{@id && %[ id="#{@id}"]} class="#{[@style, role].compact * ' '}">#{title}</h#{@level + 1}>) %>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['imageblock',@style,role].compact * ' ' %>"<%
if (attr? :align) || (attr? :float)
%> style="<%= [("text-align: #{attr :align};" if attr? :align),("float: #{attr :float};" if attr? :float)].compact * ' ' %>"<%
end %>>
<div class="content"><%
if attr? :link %>
<a class="image" href="<%= attr :link %>"><img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"<%= (attr? :width) ? %( width="#{attr :width}") : nil %><%= (attr? :height) ? %( height="#{attr :height}") : nil %>></a><%
else %>
<img src="<%= image_uri(attr :target) %>" alt="<%= attr :alt %>"<%= (attr? :width) ? %( width="#{attr :width}") : nil %><%= (attr? :height) ? %( height="#{attr :height}") : nil %>><%
end %>
</div><%
if title? %>
<div class="title"><%= captioned_title %></div><%
end %>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['listingblock',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= captioned_title %></div><%
end %>
<div class="content"><%
nowrap = !(@document.attr? :prewrap) || (option? :nowrap)
if @style == 'source'
language = attr :language
code_class = language ? [language, %(language-#{language})] : []
pre_class = ['highlight']
pre_lang = language
case attr 'source-highlighter'
when 'coderay'
pre_class = ['CodeRay']
when 'pygments'
pre_class = ['pygments','highlight']
when 'prettify'
pre_class = ['prettyprint']
pre_class << 'linenums' if attr? :linenums
pre_class << language if language
pre_class << %(language-#{language}) if language
code_class = []
when 'html-pipeline'
pre_lang = language
pre_class = code_class = []
nowrap = false
end
pre_class << "pre-scrollable"
pre_class << "programlisting"
pre_class << "cm-s-neo"
pre_class << "code"
pre_class << "runnable"
pre_class << "standalone-example"
pre_class << "ng-binding"
pre_class << 'nowrap' if nowrap %>
<pre mode="cypher" <%= pre_class.empty? ? nil : %( class="#{pre_class * ' '}") %><%= pre_lang && %( data-lang="#{pre_lang}") %><%= pre_lang && %( lang="#{pre_lang}") %>><!--code<%= code_class.empty? ? nil : %( class="#{code_class * ' '}") %>--><%= content %><!--/code--></pre><%
else %>
<pre<%= nowrap ? ' class="nowrap"' : nil %>><%= content %></pre><%
end %>
</div>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['literalblock',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<div class="content">
<pre<%= !(@document.attr? :prewrap) || (option? :nowrap) ? ' class="nowrap"' : nil %>><%= content %></pre>
</div>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['mathblock',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<div class="content"><%
open, close = Asciidoctor::BLOCK_MATH_DELIMITERS[@style.to_sym]
equation = content.strip
if (@subs.nil? || @subs.empty?) && !(attr? 'subs')
equation = sub_specialcharacters equation
end
unless (equation.start_with? open) && (equation.end_with? close)
equation = %(#{open}#{equation}#{close})
end
%>
<%= %(#{equation}\n) %>
</div>
</div>
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> class="<%= ['olist',@style,role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<ol class="<%= @style %>"<%= (attr? :start) ? %( start="#{attr :start}") : nil %><%= (keyword = list_marker_keyword) && %( type="#{keyword}") %>><%
items.each do |item| %>
<li>
<p><%= item.text %></p><%
if item.blocks? %>
<%= item.content %><%
end %>
</li><%
end %>
</ol>
</div>
<%#encoding:UTF-8%><%
if @style == 'abstract'
if @parent == @document && @document.doctype == 'book'
puts 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
else
%><div<%= @id && %( id="#{@id}") %> class="<%= ['quoteblock','abstract',role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<blockquote>
<%= content %>
</blockquote>
</div><%
end
elsif @style == 'partintro' && (@level != 0 || @parent.context != :section || @document.doctype != 'book')
puts 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a book part. Excluding block content.'
else
%><div<%= @id && %( id="#{@id}") %> class="<%= ['openblock',(@style == 'open' ? nil : @style),role].compact * ' ' %>"><%
if title? %>
<div class="title"><%= title %></div><%
end %>
<div class="content">
<%= content %>
</div>
</div><%
end %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment