Giter VIP home page Giter VIP logo

unique_paths's Introduction

Unique Paths

Stored Procedure to find unique nodes.

This project requires Neo4j 3.2.x

Instructions

This project uses maven, to build a jar-file with the procedure in this project, simply package the project with maven:

mvn clean package

This will produce a jar-file, target/matcher-1.0-SNAPSHOT.jar, that can be copied to the plugin directory of your Neo4j instance.

cp target/unique-1.0-SNAPSHOT.jar neo4j-enterprise-3.2.3/plugins/.

Edit your Neo4j/conf/neo4j.conf file by adding this line:

dbms.security.procedures.unrestricted=com.maxdemarzi.*    

Restart your Neo4j Server.

Create the Schema by running this stored procedure:

    CALL com.maxdemarzi.schema.generate

Let's create some test data. First the root of our traversal:

    CREATE (u:PRODUCT {id:"1-Root"})

Next we will create a few layers of non PRODUCT labeled nodes:

    WITH ["PlayStation","Lipitor","Corolla","Star Wars","iPad","Mario Bros. Franchise","Michael Jackson’s Thriller","Harry Potter",
    "iPhone","Rubik’s Cube"] AS products
    MATCH (product:PRODUCT) WHERE product.id STARTS WITH "1-"
    WITH range(1,2) as children, product, products
    FOREACH (id in children | CREATE (product)-[:NEEDS]->(:Item {id:"2-" + 
    products[id% size(products)]+id(product)}) );
    
    WITH ["PlayStation","Lipitor","Corolla","Star Wars","iPad","Mario Bros. Franchise","Michael Jackson’s Thriller","Harry Potter",
        "iPhone","Rubik’s Cube"] AS products
    MATCH (item:Item) WHERE item.id STARTS WITH "2-"
    WITH range(1,2) as children, item, products
    FOREACH (id in children | CREATE (item)-[:NEEDS]->(:Item {id:"3-" + 
    products[id% size(products)]+id(item)}) );
    
    WITH ["PlayStation","Lipitor","Corolla","Star Wars","iPad","Mario Bros. Franchise","Michael Jackson’s Thriller","Harry Potter",
        "iPhone","Rubik’s Cube"] AS products
    MATCH (item:Item) WHERE item.id STARTS WITH "3-"
    WITH range(1,2) as children, item, products
    FOREACH (id in children | CREATE (item)-[:NEEDS]->(:Item {id:"4-" + 
    products[id% size(products)]+id(item)}) );

Finally we will create the PRODUCT labeled nodes:

    WITH ["PlayStation","Lipitor","Corolla","Star Wars","iPad","Mario Bros. Franchise","Michael Jackson’s Thriller","Harry Potter",
        "iPhone","Rubik’s Cube"] AS products
    MATCH (item:Item) WHERE item.id STARTS WITH "4-"
    WITH range(1,2) as children, item, products
    FOREACH (id in children | CREATE (item)-[:NEEDS]->(:PRODUCT {id:"5-" + 
    products[id% size(products)]+id(item)}) );

Now call the stored procedure:

    CALL com.maxdemarzi.unique('1-Root') yield node return node.id

Try the alternate Cypher query:

    MATCH (p:PRODUCT {id: "1-Root"})-[:NEEDS*..10000]->(d:PRODUCT)         
    RETURN distinct d.id;

unique_paths's People

Contributors

maxdemarzi avatar

Stargazers

Livne berebi avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.