Skip to content

Instantly share code, notes, and snippets.

@peterneubauer
Last active December 23, 2015 08:38
Show Gist options
  • Save peterneubauer/6608600 to your computer and use it in GitHub Desktop.
Save peterneubauer/6608600 to your computer and use it in GitHub Desktop.

Revisions

  1. peterneubauer revised this gist Sep 20, 2013. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions Subcategories.adoc
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,13 @@ Now, let's find the German captions of products that are attached to the categor

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2), sub_cat<-[caption]-(product)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE' AND cap2.lang='DE'
    RETURN bev_caption.caption as search_term,cap2.caption as search_term_DE,caption.caption as found_cat, product.name
    MATCH
    (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption),
    bev-[:CAPTION]->(cap2),(caption)<-[:TAGGED]-(product)
    WHERE
    bev_caption.caption = 'beverages' AND
    caption.lang='DE' AND cap2.lang='DE'
    RETURN bev_caption.caption AS search_term,cap2.caption AS search_term_DE,caption.caption AS found_cat, product.name
    ----

    //table
  2. peterneubauer revised this gist Sep 20, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Subcategories.adoc
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,9 @@ Now, let's find the German captions of products that are attached to the categor

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2)
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2), sub_cat<-[caption]-(product)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE' AND cap2.lang='DE'
    RETURN bev_caption.caption as search_term,cap2.caption as search_term_DE,caption.caption as found_cat
    RETURN bev_caption.caption as search_term,cap2.caption as search_term_DE,caption.caption as found_cat, product.name
    ----

    //table
  3. peterneubauer revised this gist Sep 20, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Subcategories.adoc
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,9 @@ Now, let's find the German captions of products that are attached to the categor

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2)
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE' AND cap2.lang='DE'
    RETURN bev_caption.caption,cap2 ,caption.caption
    RETURN bev_caption.caption as search_term,cap2.caption as search_term_DE,caption.caption as found_cat
    ----

    //table
  4. peterneubauer revised this gist Sep 20, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Subcategories.adoc
    Original file line number Diff line number Diff line change
    @@ -31,9 +31,9 @@ Now, let's find the German captions of products that are attached to the categor

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption, caption.caption
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]->(caption), bev-[:CAPTION]->(cap2)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE' AND cap2.lang='DE'
    RETURN bev_caption.caption,cap2 ,caption.caption
    ----

    //table
  5. peterneubauer revised this gist Sep 20, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions Subcategories.adoc
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    = Vienna is cool
    = A case of nested subcategories

    //console

    In many multilingual systems, there are hierarchis of categories, connected to different products that need to be searched by customers with different language preferences. Here is a possible approach, inspired by the http://wordnetweb.princeton.edu/perl/webwn?o2=&o0=1&o8=1&o1=1&o7=&o5=&o9=&o6=&o3=&o4=&s=drink[Wordnet Project].
    In many multilingual systems, there are nested hierarchis of categories, connected to different products that need to be searched by customers with different language preferences. Here is a possible approach, inspired by the http://wordnetweb.princeton.edu/perl/webwn?o2=&o0=1&o8=1&o1=1&o7=&o5=&o9=&o6=&o3=&o4=&s=drink[Wordnet Project].

    == The setup

    @@ -27,6 +27,8 @@ CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)

    == Find English things that are beverages

    Now, let's find the German captions of products that are attached to the category or one of its subcategories of the one that has an English caption `beverages`.

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
  6. peterneubauer renamed this gist Sep 18, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. peterneubauer renamed this gist Sep 18, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Vienna.adoc → Sbucategories.adoc
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,9 @@

    //console

    == First, let's rock
    In many multilingual systems, there are hierarchis of categories, connected to different products that need to be searched by customers with different language preferences. Here is a possible approach, inspired by the http://wordnetweb.princeton.edu/perl/webwn?o2=&o0=1&o8=1&o1=1&o7=&o5=&o9=&o6=&o3=&o4=&s=drink[Wordnet Project].

    == The setup


    //setup
  8. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
    CREATE (alc)-[:CAPTION]->(alc_de{caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    CREATE ({name:"Wein"})-[:TAGGED]->(acl_de)
    CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)
    ----

    //graph
  9. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
    CREATE (alc)-[:CAPTION]->(alc_de{caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)
    CREATE ({name:"Wein"})-[:TAGGED]->(acl_de)
    ----

    //graph
    @@ -27,9 +27,9 @@ CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)<-[:TAGGED]-(product)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption, caption.caption, cat, product.name
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption, caption.caption
    ----

    //table
  10. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
    CREATE (alc)-[:CAPTION]->(alc_de{caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    CREATE ({name:"Wein"})-[:TAGGED]->(acl_de)
    CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)
    ----

    //graph
    @@ -27,9 +27,9 @@ CREATE ({name:"Wein"})-[:TAGGED]->(acl_de)

    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption, caption.caption
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)<-[:TAGGED]-(product)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption, caption.caption, cat, product.name
    ----

    //table
  11. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,9 @@ CREATE (alc{name:'C2'})
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr)
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
    CREATE (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (alc)-[:CAPTION]->(alc_de{caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    CREATE ({name:"Wein"})-[:TAGGED]->(acl_de)
    ----

    //graph
  12. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ CREATE (getr)<-[:IS_A]-(alc)
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption.caption, caption.caption
    RETURN bev_caption.caption, caption.caption
    ----

    //table
  13. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -30,3 +30,5 @@ MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption.caption, caption.caption
    ----

    //table
  14. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,11 @@ CREATE (getr)<-[:IS_A]-(alc)
    //table


    == Query 2
    == Find English things that are beverages

    [source,]
    [source,cypher]
    ----
    MATCH (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(cat)-[:CAPTION]-(caption)
    WHERE bev_caption.caption = 'beverages' AND caption.lang='DE'
    RETURN bev_caption.caption.caption, caption.caption
    ----
  15. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ CREATE (getr{name:'C1'})
    CREATE (alc{name:'C2'})
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr)
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(c2)
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
    CREATE (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----
  16. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,12 @@
    //setup
    [source,cypher]
    ----
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'}),
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'}),
    CREATE (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'}),
    CREATE (getr{name:'C1'})
    CREATE (alc{name:'C2'})
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr)
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(c2)
    CREATE (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----

  17. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,10 @@
    //setup
    [source,cypher]
    ----
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'}),
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'}),
    CREATE (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'}),
    CREATE (getr)<-[:IS_A]-(alc)
    ----

  18. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,10 @@
    //setup
    [source,cypher]
    ----
    CREATE
    ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'}),
    (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'}),
    (getr)<-[:IS_A]-(alc)
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----

    //graph
  19. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,12 @@
    //setup
    [source,cypher]
    ----
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    CREATE
    ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'}),
    ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'}),
    (alc)-[:CAPTION]->({caption:'Alkoholika', lang:'DE'}),
    (getr)<-[:IS_A]-(alc)
    ----

    //graph
  20. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@
    [source,cypher]
    ----
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----
  21. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    //setup
    [source,cypher]
    ----
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getränke', lang:'DE'})
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----
  22. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,16 @@
    //setup
    [source,cypher]
    ----
    CREATE (n{name:'Hi there'})
    RETURN n
    CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr{name:'C1'})-[:CAPTION]->({caption:'Getränke', lang:'DE'})
    CREATE ({caption:'alcoloic stuff', lang:'EN'})<-[:CAPTION]-(alc{name:'C2'})-[:CAPTION]->({caption:'Alkoholika', lang:'DE'})
    CREATE (getr)<-[:IS_A]-(alc)
    ----

    //graph

    //table


    == Query 2

    [source,]
  23. peterneubauer revised this gist Sep 18, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@

    == First, let's rock


    //setup
    [source,cypher]
    ----
    CREATE (n{name:'Hi there'})
  24. peterneubauer created this gist Sep 18, 2013.
    16 changes: 16 additions & 0 deletions Vienna.adoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    = Vienna is cool

    //console

    == First, let's rock

    [source,cypher]
    ----
    CREATE (n{name:'Hi there'})
    RETURN n
    ----

    //graph

    //table