Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The neo4jrestclient supports both indexing and traversing the graph, but I think by using just indexing could be enoguh for your use case. However, I don't know if I understood properly your problem. Anyway, something like this could work:</p> <pre><code>&gt;&gt;&gt; from neo4jrestclient.client import GraphDatabase &gt;&gt;&gt; gdb = GraphDatabase("http://localhost:7474/db/data/") &gt;&gt;&gt; idx = gdb.nodes.indexes.create("urltags") &gt;&gt;&gt; url_node = gdb.nodes.create(url="http://foo.bar", type="URL") &gt;&gt;&gt; tag_node = gdb.nodes.create(tag="foobar", type="TAG") </code></pre> <p>We add the property <code>count</code> to the relationship to keep track the number of URLs <code>"http://foo.bar"</code> tagged with the tag <code>foobar</code>.</p> <pre><code>&gt;&gt;&gt; url_node.relationships.create(tag_node["tag"], tag_node, count=1) </code></pre> <p>And after that, we index the url node according the value of the URL.</p> <pre><code>&gt;&gt;&gt; idx["url"][url_node["url"]] = url_node </code></pre> <p>Then, when I need to create a new URL node tagged with a TAG node, we first query the index to check if that is yet indexed. Otherwise, we create the node and index it.</p> <pre><code>&gt;&gt;&gt; new_url = "http://foo.bar2" &gt;&gt;&gt; nodes = idx["url"][new_url] &gt;&gt;&gt; if len(nodes): ... rel = nodes[0].relationships.all(types=[tag_node["tag"]])[0] ... rel["count"] += 1 ... else: ... new_url_node = gdb.nodes.create(url=new_url, type="URL") ... new_url_node.relationships.create(tag_node["tag"], tag_node, count=1) ... idx["url"][new_url_node["url"]] = new_url_node </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload