Top Banner
Presented by Grant Paton-Simpson Word Puzzles with Neo4j and Py2neo
22

Word Puzzles with Neo4j and Py2neo

Apr 16, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Word Puzzles with Neo4j and Py2neo

Presented by Grant Paton-Simpson

Word Puzzles with Neo4j and Py2neo

Page 2: Word Puzzles with Neo4j and Py2neo

Overview

● Brief look at graph databases & Neo4j

● Introduction to word transformation game

● Getting suitable words

● Adding words and relationships into Neo4j

● Querying graph data to generate puzzles

Page 3: Word Puzzles with Neo4j and Py2neo

Graph Databases – a NoSQL option

http://neo4j.com/books/graph-databases/

Page 4: Word Puzzles with Neo4j and Py2neo

NoSQL – when is it a good fit?

● SQL has its origins in the 1970s

and may not be fresh and shiny

any more but ...

● … we shouldn't choose NoSQL

for reasons of fashion.

● Venerable SQL often a better

choice for standard hierarchies

e.g. countries that have cities

that have suburbs etc

Page 5: Word Puzzles with Neo4j and Py2neo

https://twitter.com/edd/status/400190499585544192

Page 6: Word Puzzles with Neo4j and Py2neo

Graph Databases● Graph databases much, much better for related data with:

– lots of different links between same nodes

– different numbers of links between nodes

e.g. 3 hops to one peer and 7 hops to another

– lots of peer-to-peer links

Page 7: Word Puzzles with Neo4j and Py2neo

Substantial Benefits

● Massive performance benefits (going exponential as number

of links grows)

● Structural harmony

– between structure of data and structure of data storage

(what you draw on the whiteboard might look very similar

to how you data is actually structured)

– between questions of data and query language used to

answer them

Page 8: Word Puzzles with Neo4j and Py2neo

Word transformations

● Start with one word and get to

the other by single-letter

tranformations word-by-word

● E.g. starting with “stores” get to

“slaked”

– BTW there are 96 alternative

ways 5 moves or less

stores

stored

stared

staked

slaked

Page 9: Word Puzzles with Neo4j and Py2neo

Puzzle taster

Get from 'sloven' to 'closed' in

no more than 5 steps

(there are 10 unique solutions)

sloven

?closed

Page 10: Word Puzzles with Neo4j and Py2neo

Getting a simple word list

● How hard could it be?

● Lesson #1 – scrabble lists and similar are useless – only want lists

with standard words otherwise puzzles too hard

● Lesson #2 – have to decide about taboo/profane words

● Lesson #3 – the number of words affects the number of

ONE_LETTER_DIFF relationships a lot

● Lesson #4 – clever optimisation not needed if restricting self to

ordinary words

SCOWL (Spell Checker Oriented Word Lists) http://wordlist.aspell.net/

Page 11: Word Puzzles with Neo4j and Py2neo

Filtering words

● Needed to turn é to e

● Needed to eliminate possessives e.g. cat's (as used in the phrase “the

cat's whiskers”)

● Needed to leave out capitalised words

Page 12: Word Puzzles with Neo4j and Py2neo

For each word, identifying words different by one letter onlyDisclaimer: the code worked but probably some super-smart optimisations

would be possible involving n-dimensional space or something

Page 13: Word Puzzles with Neo4j and Py2neo

Adding data to Neo4j

● Create nodes and relationships

● Lots of room for optimisations

● Only need to build database once so 15 minutes is not worth

reducing

● My Neo4j and Py2neo is beginner level but I was able to solve my

problem

Page 14: Word Puzzles with Neo4j and Py2neo

Py2neo and Cypher

Page 15: Word Puzzles with Neo4j and Py2neo

Cypher Syntax as ASCII Art (Really!)

Word WordONE_OFF

(Word) -[ONE_OFF]->(Word)

Page 16: Word Puzzles with Neo4j and Py2neo

Cypher Syntax as ASCII Art (Really!)

Word WordONE_OFF

(Word) -[ONE_OFF]->(Word)

How cool is this?

Page 17: Word Puzzles with Neo4j and Py2neo

Example Output

Page 18: Word Puzzles with Neo4j and Py2neo

Matching chart

Page 19: Word Puzzles with Neo4j and Py2neo

Live Demo – Suggestions for Start Word

Page 20: Word Puzzles with Neo4j and Py2neo

“sloven” to “closed” solution(s)

Page 21: Word Puzzles with Neo4j and Py2neo

Resources

● Neo4j

– http://neo4j.com/books/graph-databases/

– http://neo4j.com/graphacademy/

– http://graphgist.neo4j.com/#!/gists

– https://www.youtube.com/channel/UCvze3hU6OZBkB1vkhH2lH9Q

● Py2neo

– http://py2neo.org/2.0/

● SCOWL

– http://wordlist.aspell.net/

Page 22: Word Puzzles with Neo4j and Py2neo

About Catalyst