Skip to content

Instantly share code, notes, and snippets.

Avatar

Jacqui tekiegirl

View GitHub Profile
@tekiegirl
tekiegirl / uniqueId.adoc
Last active Mar 24, 2021
Using the graph to control unique id generation.
View uniqueId.adoc

Using the graph to control unique id generation

Introduction

This gist was prompted by Nigel Small’s tweet of a query to generate a unique id for a node (and is posted here with his agreement). It inspired me to think about how it could be used in a full example, unrestricted by Twitter’s 140 characters. I have also looked at how we could generate different sets of unique ids for different labels.

Auto-incrementing #Neo4j counter MERGE (x:Counter {name:'foo'}) ON CREATE SET x.count = 0 ON MATCH SET x.count = x.count + 1 RETURN x.count

— Nigel Small (@technige) December 16, 2013
@tekiegirl
tekiegirl / navigation.adoc
Last active Jun 3, 2019
A neo4j graph gist showing how satellite navigation mapping can be modelled in a graph.
View navigation.adoc

Roads, Nodes and Automobiles

or 'How a sat-nav could use a graph database'


View ImportDistinctDataWithRelationships.adoc

Import Distinct Data With Relationships

Import Distinct Data from a CSV file, and create relationships

Here is an example of importing distinct data from a CSV file, and creating relationships using that data.

Graph Population

This method is more efficient than just using MERGE. It never tries to match any duplicates from the csv file as they are filtered out beforehand. It still uses MERGE to ensure that duplicate nodes are not created, but in this situation this would only be required if the csv file was loaded more than once.

View ImportDistinctData.adoc

Import Distinct Data

Import Distinct Data from a CSV file

Here are two methods for importing only distinct data from a CSV file, without having to pre-process the CSV for duplicates. Method 2 is more efficient than Method 1.

Graph Population Method 1

View ClearDb.cs
private void ClearDb(IGraphClient client)
{
client.Cypher
.Match("(n)")
.DetachDelete("n")
.ExecuteWithoutResults();
}
@tekiegirl
tekiegirl / DropColumnIfExists.sql
Created Apr 5, 2016
Drop a column, using SQL, if it exists
View DropColumnIfExists.sql
IF exists( select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='myTable' and COLUMN_NAME='columnToDrop')
BEGIN
ALTER TABLE myTable drop COLUMN columnToDrop
END
@tekiegirl
tekiegirl / existing.sql
Created Mar 24, 2016
Adding a relationship constraint to an existing or new column in MS SQL
View existing.sql
ALTER TABLE [dbo].[MyTable]
ADD CONSTRAINT FK_MyTable_OtherTable FOREIGN KEY (OType)
REFERENCES [dbo].[OtherTable] (Ident)
ON DELETE CASCADE
ON UPDATE CASCADE
@tekiegirl
tekiegirl / merge.adoc
Last active Dec 30, 2015
Does MERGE work the same for relationships as CREATE UNIQUE did?
View merge.adoc
View fuzzy_match.adoc

Ranked rule-based subgraph matching

In order to rank possible matches by relevence I wish to return a score, with different matches addingg a different value to the score, and a list of the items that matched (a list of strings). More matches the higher the rank should be.

Setup of known data

@tekiegirl
tekiegirl / ContributorCommunity.adoc
Last active Dec 28, 2015
Initial tests for the Contributor Community graph
View ContributorCommunity.adoc

Contributor Community Graph

Developers using Neo4j are currently working alone when they should be working together, but they don’t know who is working on the same technologies. This graph aims to solve this by linking developers with similar interests, projects and events.

Setup of known data