Describing a Cypher Query for multi-level relationship in Neo4j? - graph

I'm developing a small affiliate structure to understand the concept of graph databases better, as well learn Neo4J and see what it can offer me. I've been with RDBMS for years now and Cypher is pretty rough. I'm trying to build a very simple affiliate system:
Affiliate Joe has referred Mary, Bob and Mark. So, i create all their nodes and create the "referred" relationship. Now Mary refers Julie, Jessica and Joan. Bob refers Billy and Baxter. Mark refers Michael and Marx. And their referrals keep referring people.
For each referral that one of Joe's original referrals, Joe earns a "generation". His first generation is Mary, Bob and Mark. His second generation is Julie, Jessica, Joan, Billy, Baxter, Michael and Marx.
Now, with a Cypher query, how can i discover his generations and, of course, discover their number? Their place in the tree? How can i know who is from his 3rd or 4th generation, and who they are?
My mind is twisting here, hope you guys can help.

Vinny,
look at http://tinyurl.com/7vryzwz, is this what you are lookad for, basically
START referrer=node(1)
MATCH path=referrer-[:referred*1..]->refferee
RETURN referrer,refferee, length(path) as generation
ORDER BY length(path) asc

Related

How to read a list of values into a data table in a sandbox?

I have a list of data. It's all a single column, each row is a comment from a post asking for book recommendations. Here's an example, containing the first 2 entries:
"My recommendations from books I read this year:<p>Bad Blood : Man, this book really does read like a Hollywood movie screenplay. The rise and fall of Theranos, documented through interviews with hundreds of ex-employees by the very author who came up with the first expose of Theranos. Truly shows the flaws in the "fake it before you make it" mindset and how we glorify "geniuses".<p>Shoe Dog : Biography of the founder of Nike. Really liked how it's not just a book glorifying the story of Nike, but tells the tale of how much effort, balance and even pure luck went into making the company the household name it is today.<p>Master Algorithm : It's a book about the different fields of Machine learning (from Bayesian to Genetic evolution algos) and talks about the pros and cons of each and how these can play together to create a "master algorithm" for learning. It's a good primer for people entering the field and while it's not a DIY, it shows the scope of the problem of learning as a whole.<p>Three Body Problem: Finally, after years of people telling me to read this (on HN and off), I read the trilogy (Remembrance of Earth's Past), and I must say, the series does live up to the hype. Not only is it fast paced and deeply philosophical, but it's presented in a format very accessible to casual readers as well (unlike many hard sci-fi books which seem to revel in complexity). If I had to describe this series in a single line, it's "What would happen if China was the country that made first contact with an alien race?"","A selection:<p>Sapiens (Yuval Noah Harari, 2014 [English]) - A bit late to the party on this one. Mostly enjoyed it, especially the early ancient history stuff, but I felt it got a bit contrived in the middle - like the author was forcing it. Overall a good read though.<p>How to Invent Everything (Ryan North, 2018) - First book I've pre-ordered in a long time. A look at the history of civilization and technology through a comedic lens. Pretty funny and enjoyable.<p>The Rise of Theodore Roosevelt (Edmund Morris, 1979) - Randomly happened across this book while browsing a used bookstore for some stuff to read on a summer vacation. Loved it. It's big, but reads pretty quick for a biography. I've been a fan of TR since I first really learned about him in High School and I would recommend this for anyone interested in TR/The West/Americana.<p>Jaws (Peter Benchley, 1974) - Quite a bit darker than the movie.<p>Sharp Objects (Gillian Flynn, 2006) - I enjoyed Gone Girl (book and film) so I wanted to read this before the HBO series. To be honest...not my cup of tea. It was <i>okay</i>.<p>The Art of Racing in the Rain (Garth Stein, 2008) - Made me cry on an airplane. Thankfully my coworkers were on a different flight."
(Notice, comments are separated by ",")
I'm trying to load this list into a data table in an R sandbox (rapporter.net). But because of browser security, I can't load a local file (fread, read.table).
How can I read raw data into a data table in R?

LUIS not able to classify multiple person names in a query

I am having an issue where in LUIS is unable to identify multiple person names in an utterance when separated by "and or ," in a phrase.
For Eg:
When user types, "Schedule a meeting with Bob and Lisa", LUIS recognizes only Bob as builtin.personName where in Lisa is not recognized at all. Also separating names with comma didn't work either. If I change the order of names to Lisa and Bob, only Lisa gets listed and poor Bob gets ignored this time.
Also it failed to identify the name when typing, "Book meeting and Bob".
My another attempt was successful after changing the utterance to "Book meeting with Bob as well as Lisa". But that would not be general way of posting a query.
Phrase lists didn't help either, I have added below two samples in phrase list but the results were same as stated above.
"Schedule a meeting with {personName}, {personName}"
"can i have {personName} and {personName} for a quick meeting"
I don't see similar issue with emails separated by "and or comma".
Note:I also tried built in domain entity Entertainment.Person but got similar results.
Appreciate your help.
You need to make your app more intelligent by adding patterns to the app. I have tried to replicate your issue by creating my LUIS app, it successfully detects the entities properly. Refer the app stored as a gist here : https://gist.github.com/mandardhikari/f0edd9406aeeb6d7b9fd0f68371ff4eb

use case for LUIS (Microsoft Cognitive Service)

we want to use LUIS to get the entities and intent from a user question and identify the entities that belong to our domain, so what we're doing is training LUIS with a lot of entities that comes from our context domain. Is this a valid and "correct" use of LUIS?
Thanks
Yes you can the intents and entities fro the user question with LUIS. You have to provide training examples accordingly. There are many features in LUIS to label entities which follow a specific pattern using Patterns feature (pattern.any) and provide phrase lists for synonyms. You have to use them based on the scenario. Hope that helps!!
I'm creating a search engine to find in medical documents with a very specific terms. For this I'm training LUIS with this kind of words or tags as "entities".
Yes you are right. The medical term you are referring to are suppose to be entities.
But this approach implies a big bulk of terms in LUIS
If there is a difference only in the term i.e if your utterances are like
search for a
search for b
Then you can add a and b as a phrase list in LUIS, in this way you don't have to keep repeating the utterance for each term. You can check out how to add phrase list. If you look at the 3rd point there you can see that for the name City many city values are being entered. You can do the same with the medical terms you need to search.
In this way you can get the medical terms at your server side by inspecting the entity value.

Giving certain kinds of things to certain people (relation between people and kinds of things)

I would like for the player to be able to give certain kinds of thing to certain people, where the default is that people do not accept the items, but it should be possible to override this.
I'm trying to do this using a relation.
The block giving rule is not listed in the check giving it to rules.
Interest relates one person to various things. The verb to like means the interest relation.
Check giving (this is the polite refusal of unwanted objects rule):
unless the second noun likes the noun:
say "[The second noun] disdainfully refuses [the noun]." instead.
Then setting up the kind / instance of the relation, where Billy should accept food.
Food is a kind of thing. A baguette is food. A baguette is here.
Billy is a man. Billy is in Example Location. Billy likes food.
However taking the baguette and giving it to Billy results in:
Billy disdainfully refuses the baguette
However, if I say
Billy likes the baguette.
Then giving succeeds:
You give the baguette to Billy
How can I make Billy accept all food items?
I figured out how, not using a relation, but an either/or property.
A person can be interested-in-food.
With the giving-check:
Check giving (this is the polite refusal of unwanted objects rule):
Unless noun is food and the second noun is interested-in-food:
say "[The second noun] disdainfully refuses [the noun]." instead.
And giving setting property on the person:
Billy is interested-in-food.
The statement Billy likes food. creates a thing called 'food' that Billy likes. A way to make Billy like all food is using the word all, like the following:
All food is liked by Billy.
or
When play begins, now Billy likes all food.
These makes Billy like each food item individually.

How to include time into graph mapping (Neo4j)

I'm building a simple system for profiling people. I'm currently using neo4j to build simple relations between users. For example I have simple tuple
mike met sara
But how could I integrate time? For example
mike met sara 2 days ago OR mike will meet sara in 3 days
The main reason is because the relation can happen multiple times at different times. My goal is to be able to answer questions:
has mike met sara in last week?
are mike and sara dating (dating = they meet at least 5 times a week)?
what is the longest period mike and sara did not meet?
does mike have personal problems? (we can introduce mike met bill where sara & bill both have personality attribute "helping people". So we can presume if mike didn't met with sara or bill in last year but has X meeting in last week, something is wrong with him)
What is the best way to get these answers? Is Neo4j the right way to go?
I think what you want to model is events in time. Those events (e.g. Meeting) are nodes that are connected to the participants, places, additional information etc.
Then you can choose to link the events in a ordered list that represents their chronological order, i.e. a timeline.
For fast access of sub-parts of the timeline you could, create a time-tree (year->month->day[->hour]->event)
See this for a concrete example: http://docs.neo4j.org/chunked/milestone/cypher-cookbook-path-tree.html

Resources