Skip to content

Instantly share code, notes, and snippets.

View coolgarifTech's full-sized avatar

coolgarifTech

View GitHub Profile
@coolgarifTech
coolgarifTech / gist:5670877
Created May 29, 2013 14:51
Adding a print statement to script to illustrate the RAW node response format from Cypher Query (Print statement is removed in the final script - this is just for illustration purposes!!)
for node in querySquenceObject[1:]:
n = node.pop()
[...]
self = n.get('self')
print self
# RESPONSE IN THE CMD LINE FROM THE ABOVE PRINT STATEMENT
http://localhost:7475/db/data/node/1
@coolgarifTech
coolgarifTech / gist:5670807
Created May 29, 2013 14:42
iterating over the result of a Cypher Query and extracting node properties
for node in querySquenceObject[1:]:
n = node.pop()
data = n.get('data')
name = data.get('name')
description = data.get('description')
self = n.get('self')
self = urlparse(self)
uid = doRegEX(self)
@coolgarifTech
coolgarifTech / gist:5670791
Created May 29, 2013 14:40
Neo4j Cypher query to return all graph nodes
q = "START n=node(*) RETURN n"
params = {}
querySquenceObject = db.query(q, params=params, returns=RAW)
@coolgarifTech
coolgarifTech / gist:5670755
Created May 29, 2013 14:37
Graphdatabase connection and main function calls
db = GraphDatabase("http://localhost:7475/db/data")
nodes = getNodes(db)
rels = getRels(db)
@coolgarifTech
coolgarifTech / gist:5670732
Created May 29, 2013 14:34
Initiating the script and setting up the API route in Flask
from flask import Flask, Response, json, jsonify, request, Blueprint, render_template
app = Flask(__name__)
@app.route('/_api/hydraGraph')
def api_response():
@coolgarifTech
coolgarifTech / gist:5600500
Created May 17, 2013 17:07
Shutdown transaction command at the end of the script to close the DB connection - in Neo4j python embedded bindings
# Make sure to include or you will block the thread!
db.shutdown()
@coolgarifTech
coolgarifTech / gist:5600489
Created May 17, 2013 17:05
End of script housekeeping to print out the number of Nodes and Relationships created in that transaction! In Neo4j using python embedded bindings
# Might add some logic to count / print no of nodes/rels added :-)
number_of_nodes = len(db.nodes)
number_of_relationships = len(db.relationships)
print "Number of nodes created"
print number_of_nodes
print "Number of relationships created"
print number_of_relationships
@coolgarifTech
coolgarifTech / gist:5600472
Created May 17, 2013 17:02
creating more relationships using python embedded bindings and Neo4j
# dataProcessing
dataProcessing.relationships.create('includes', graphDB)
dataProcessing.relationships.create('includes', dataMining)
dataProcessing.relationships.create('includes', dataAnalysis)
dataProcessing.relationships.create('includes', nlp)
dataProcessing.relationships.create('includes', rdf)
@coolgarifTech
coolgarifTech / gist:5600462
Created May 17, 2013 17:01
Creating relationships between nodes using python embedded bindings in Neo4j
#Primary Relationship
coolgarifTech.relationships.create('implements_solutions_in', dataStorage)
coolgarifTech.relationships.create('implements_solutions_in', dataProcessing)
coolgarifTech.relationships.create('implements_solutions_in', dataVisualisation)
coolgarifTech.relationships.create('implements_solutions_in', dataPublishing)
@coolgarifTech
coolgarifTech / gist:5600444
Created May 17, 2013 16:57
Creating a single node using python embedded bindings in Neo4j
coolgarifTech = db.node(name = 'CoolgarifTech', description = 'Digital Agency focused on Data', established="Jan 2013", founders="Richie Barter & James Billot")
companyNameIndex['name']['CoolgarifTech'] = coolgarifTech
companyNameIndex['description']['Digital Agency focused on Data'] = coolgarifTech