Re: [Neo4j] Gremlin Query - Help

2011-12-05 Thread Romiko Derbynew
Marko,

I am thinking of using this statement.
g.V.ifThenElse{it.out('hasCentre').filter{it == aCentre}.hasNext()}{}{println 
"${it} has center unknown"}

to get nodes that DO NOT have a relationship, is this the best way to do it? I 
guess so, if this is the case, I am now adding support to the .NET graph client 
to support ifThenElse expressions. I am wondering though, as I am designing the 
interface for it, can and ifThenElse have nested ifThenElse expressions as 
well? I guess "it" and _() can be used within them?

Cheers

-Original Message-
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On 
Behalf Of Marko Rodriguez
Sent: Saturday, 3 December 2011 4:10 AM
To: Neo4j user discussions
Subject: Re: [Neo4j] Gremlin Query - Help

Hi,

> Scenario 1:
> I would like to get all Nodes that do not have a relationship to another 
> node. What is the best way to do this Gremlin?
> 
> Root => NodeA => NodeB
> Root => NodeC
> 
> Output should be NodeC

I don't understand the problem.

> Scenario 2:
> Root = > User -> Centre
> 
> I would like to get all centres for userA, and then get all users who 
> are also linked to the same centres of the userA

userA.out('hasCentre').in('hasCentre').except([userA])

> Scenario 3:
> User => Centre
> I would like to get all users that do not have a link to a Centre, and if 
> this is the case, do a projection that returns a fake centre with property 
> "Unknown"

g.V.ifThenElse{it.out('hasCentre').filter{it == 
aCentre}.hasNext()}{}{println "${it} has center unknown"}

If you have an index of your Users, then its more efficient to hit that index, 
then iterate through all vertices (g.V). E.g.

g.idx(T.v)[[type:'User']].ifThenElse

> Scenario 4:
> 
> REFERRAL => PERSON
> 
> I would like to combine a query that gets all Referrals that are 
> linked to a person and project a table result (contains referrals and 
> person property values (this is easy to do) However, I then want to do a 
> SPLIT query, that gets referrals without the persons, and then MERGE both 
> back into the table projection? So table projecton might look like this.
> I guess this is done with .table().it{}cap, but what I am not sure, is 
> how to do a split and merge in parallel and then get that merge projected 
> into the same table.


I don't quite understand your problem, but here is an example of splitting and 
merging.

g.v(1).out('knows').copySplit(_().out('knows').name, 
_().out('created').name).fairMerge

This will get all the people that v[1] knows and then generate two parallel 
pipeline. Each friend of v[1] is copied to each of the 2 parallel pipelines. 
One pipeline will get their friend's names and one will get their created 
project's names. It will then merge those two parallel pipelines into a single 
stream. You can do either fairMerge or exhaustMerge depending on the merging 
algorithm you want. fairMerge is more memory efficient. I need to write more 
about split/merge in the Gremlin documentation.

https://github.com/tinkerpop/gremlin/wiki/Split-Merge-Pattern <-- will 
work on it :)

HTH,
Marko.

http://markorodriguez.com

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Gremlin Query - Help

2011-12-02 Thread Romiko Derbynew
Marko,

Thank you very much, I really appreciate it, I will start going through your 
response here. I have also added the copy/split aggregate functionality into 
our Gremlin Client. I was not aware of the if then else as well, will extend 
our client to support this.


Apologise, will explain Scenario One.
I have a User Node that has a relationship LINKED_TO_CENTRE

I would like to get a query that can give me all Users that do not have a 
relationship  LINKED_TO_CENTRE. I was thinking of the Except/Retain pattern for 
this, e.g. get all users as aggregate A then get all users linked  as aggregate 
b  - then use except/retain or something along these lines.

On Another note, is there a way to get unique()._() to preserve all previous 
pipes and placeholders, the reason is I want to use unique() before doing a 
table projection. And unique breaks closures? ( I have a separate post on this 
in the mail list)

Marko, if you interested here is how the .NET code looks like that I am 
currently trying to write to generate a report. Its not yet finished as I need 
to take into consideration your feedback, but I am sure I will get their 
eventually. 
//ToDo Chained 'As' statements are reversed, bug in gremlin plugin with 
chained as - https://github.com/neo4j/community/issues/114
var resultSet = graphClient
.RootNode
.Out(Hosts.TypeKey, a => a.Key == 
userIdentifier.AgencyKey)
.In(UserBelongsTo.TypeKey, u => u.Username == 
userIdentifier.Username)
.Out(UserLinkedToCentre.TypeKey)
.As("Centre")
.In(UserLinkedToCentre.TypeKey)
//.GremlinDistinct() - breaks pipes for table output
.As("UserGivenName")
.As("UserFamilyName")
.In(CreatedBy.TypeKey, r => r.Completed == false)
.As("ReferralId")
.Out(ReferralHasWhoSection.TypeKey)
.As("ReferralDate")
.Out(HasParticipant.TypeKey)
.As("ParticipantName")
.In(HasParticipant.TypeKey)
.In(ReferralHasWhoSection.TypeKey)
//.GremlinDistinct() - breaks pipes for table output
.Table(
centre => centre.Name,
user => user.FamilyName,
user => user.GivenName,
referral => referral.UniqueId,
referral2 => referral2.DateInitiatedUtc,
participant => participant.Name
);

Thank You
Much appreciated


-Original Message-
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On 
Behalf Of Marko Rodriguez
Sent: Saturday, 3 December 2011 4:10 AM
To: Neo4j user discussions
Subject: Re: [Neo4j] Gremlin Query - Help

Hi,

> Scenario 1:
> I would like to get all Nodes that do not have a relationship to another 
> node. What is the best way to do this Gremlin?
> 
> Root => NodeA => NodeB
> Root => NodeC
> 
> Output should be NodeC

I don't understand the problem.

> Scenario 2:
> Root = > User -> Centre
> 
> I would like to get all centres for userA, and then get all users who 
> are also linked to the same centres of the userA

userA.out('hasCentre').in('hasCentre').except([userA])

> Scenario 3:
> User => Centre
> I would like to get all users that do not have a link to a Centre, and if 
> this is the case, do a projection that returns a fake centre with property 
> "Unknown"

g.V.ifThenElse{it.out('hasCentre').filter{it == 
aCentre}.hasNext()}{}{println "${it} has center unknown"}

If you have an index of your Users, then its more efficient to hit that index, 
then iterate through all vertices (g.V). E.g.

g.idx(T.v)[[type:'User']].ifThenElse

> Scenario 4:
> 
> REFERRAL => PERSON
> 
> I would like to combine a query that gets all Referrals that are 
> linked to a person and project a table result (contains referrals and 
> person property values (this is easy to do) However, I then want to do a 
> SPLIT query, that gets referrals without the persons, and then MERGE both 
> back into the table projection? So table projecton might look like this.
> I guess this is done with .table().it{}cap, but what I am not sure, is 
> how to do a split and merge in parallel and then get that merge projected 
> into the same table.


I don't quite understand your problem, but here is an example of splitting and 
merging.

g.v(1).out('knows').copySplit(_().out('knows').name, 
_().out('created').name).fairMerge

This will get all the people that v[1] knows and then generate two parallel 
p

Re: [Neo4j] Gremlin Query - Help

2011-12-02 Thread Marko Rodriguez
Hi,

> Scenario 1:
> I would like to get all Nodes that do not have a relationship to another 
> node. What is the best way to do this Gremlin?
> 
> Root => NodeA => NodeB
> Root => NodeC
> 
> Output should be NodeC

I don't understand the problem.

> Scenario 2:
> Root = > User -> Centre
> 
> I would like to get all centres for userA, and then get all users who are 
> also linked to the same centres of the userA

userA.out('hasCentre').in('hasCentre').except([userA])

> Scenario 3:
> User => Centre
> I would like to get all users that do not have a link to a Centre, and if 
> this is the case, do a projection that returns a fake centre with property 
> "Unknown"

g.V.ifThenElse{it.out('hasCentre').filter{it == 
aCentre}.hasNext()}{}{println "${it} has center unknown"}

If you have an index of your Users, then its more efficient to hit that index, 
then iterate through all vertices (g.V). E.g.

g.idx(T.v)[[type:'User']].ifThenElse

> Scenario 4:
> 
> REFERRAL => PERSON
> 
> I would like to combine a query that gets all
> Referrals that are linked to a person and project a table result (contains 
> referrals and person property values (this is easy to do)
> However, I then want to do a SPLIT query, that gets referrals without the 
> persons, and then MERGE both back into the table projection? So table 
> projecton might look like this.
> I guess this is done with .table().it{}cap, but what I am not sure, is 
> how to do a split and merge in parallel and then get that merge projected 
> into the same table.


I don't quite understand your problem, but here is an example of splitting and 
merging.

g.v(1).out('knows').copySplit(_().out('knows').name, 
_().out('created').name).fairMerge

This will get all the people that v[1] knows and then generate two parallel 
pipeline. Each friend of v[1] is copied to each of the 2 parallel pipelines. 
One pipeline will get their friend's names and one will get their created 
project's names. It will then merge those two parallel pipelines into a single 
stream. You can do either fairMerge or exhaustMerge depending on the merging 
algorithm you want. fairMerge is more memory efficient. I need to write more 
about split/merge in the Gremlin documentation.

https://github.com/tinkerpop/gremlin/wiki/Split-Merge-Pattern <-- will 
work on it :)

HTH,
Marko.

http://markorodriguez.com

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Gremlin Query - Help

2011-11-30 Thread Romiko Derbynew
Hi,


Scenario 1:
I would like to get all Nodes that do not have a relationship to another node. 
What is the best way to do this Gremlin?

Root => NodeA => NodeB
Root => NodeC

Output should be NodeC

Scenario 2:
Root = > User -> Centre

I would like to get all centres for userA, and then get all users who are also 
linked to the same centres of the userA


Scenario 3:
User => Centre
I would like to get all users that do not have a link to a Centre, and if this 
is the case, do a projection that returns a fake centre with property "Unknown"

Scenario 4:

REFERRAL => PERSON

I would like to combine a query that gets all
Referrals that are linked to a person and project a table result (contains 
referrals and person property values (this is easy to do)
However, I then want to do a SPLIT query, that gets referrals without the 
persons, and then MERGE both back into the table projection? So table projecton 
might look like this.
I guess this is done with .table().it{}cap, but what I am not sure, is how 
to do a split and merge in parallel and then get that merge projected into the 
same table.

ReferralId, Name
1, Bob
2, Jill
3, null
4, null

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user