[Neo4j] Comparing properties among different nodes in Gremlin

2011-07-24 Thread Javier de la Rosa
Hi all,

I have the need to do something like this:

gremlin> g.v(0).out.inV{it.getProperty("J") ==
.getProperty("J") + 10}.out...

I mean, I need to compare the value of a node property with the value
in the last node property, and repeat the process on every node to
check growth rates. But I don't if this is possible without using
variables external to the query.

Thank you in advance.
Regards.


-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Peter Neubauer
Xavier,
why can't you use an external variable?

Cheers,

/peter neubauer

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org               - Your high performance graph database.
http://startupbootcamp.org/    - Öresund - Innovation happens HERE.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.



On Sun, Jul 24, 2011 at 11:49 PM, Javier de la Rosa  wrote:
> Hi all,
>
> I have the need to do something like this:
>
> gremlin> g.v(0).out.inV{it.getProperty("J") ==
> .getProperty("J") + 10}.out...
>
> I mean, I need to compare the value of a node property with the value
> in the last node property, and repeat the process on every node to
> check growth rates. But I don't if this is possible without using
> variables external to the query.
>
> Thank you in advance.
> Regards.
>
>
> --
> Javier de la Rosa
> http://versae.es
> ___
> 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] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Marko Rodriguez
Hi,

> I mean, I need to compare the value of a node property with the value
> in the last node property, and repeat the process on every node to
> check growth rates. But I don't if this is possible without using
> variables external to the query.


I don't know if this is your paricular solution, but I do this all the time:

g = Tinkegremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.v(1).sideEffect{x = it.name}.out.sideEffect{println x}
marko
==>v[2]
marko
==>v[3]
marko
==>v[4]
gremlin> 

In other words, I use a sideEffect to save something to 'x' and then later can 
access that x for something -- in this limp example, simply to 
System.out.println it.

Does that help you? Can you map that motif over to your problem?

Good luck,
Marko.

http://markorodriguez.com

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


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Javier de la Rosa
On Mon, Jul 25, 2011 at 09:50, Peter Neubauer
 wrote:
> why can't you use an external variable?

Because the query is auto-generated by a wrapper over another
language, so I'm trying to maintain the process as simple as possible.



-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Javier de la Rosa
On Mon, Jul 25, 2011 at 10:20, Marko Rodriguez  wrote:
> Does that help you? Can you map that motif over to your problem?

Thank you, I hope so. Maybe the best way is to get all the properties
map in each vertex in order to be able to operate with those values in
the next vertex. Is that possible?

My use case is a little particular. I'm writing a mini language to
support ITL [1], which can work over Kripke structures [2] stored in a
graph. So what I'm doing is a lexer and a grammar to translate ITL
into Gremlin queries.



[1] http://www.cse.dmu.ac.uk/STRL/ITL/
[2] http://en.wikipedia.org/wiki/Kripke_structure


-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Marko Rodriguez
Hi,

>> Does that help you? Can you map that motif over to your problem?
> 
> Thank you, I hope so. Maybe the best way is to get all the properties
> map in each vertex in order to be able to operate with those values in
> the next vertex. Is that possible?

In that case do:

gremlin> g.V.sideEffect{x = it.map()}.out.sideEffect{println x}   
[name:marko, age:29]
==>v[2]
[name:marko, age:29]
==>v[3]
[name:marko, age:29]
==>v[4]
[name:peter, age:35]
==>v[3]
[name:josh, age:32]
==>v[5]
[name:josh, age:32]
==>v[3]

In short, every vertex out of V is passed into sideEffect{}. The current 
vertex's properties are saved to x as a HashMap. Then the outgoing related 
vertices of that vertex are retrieved. There is a sideEffect again where you 
can access your map in x from previous.

Perhaps I'm misunderstanding your use case... Finally, you might want to 
consider "aggregate" as a way to get all before processing the next step. Check 
this:

gremlin> x = [] 
   
gremlin> g.V.aggregate(x).out.sideEffect{println x*.map()}
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[2]
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[3]
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[4]
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[3]
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[5]
[[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
[name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
==>v[3]

In this way, x has ALL the maps of all the vertices coming out of V. x is an 
ArrayList(). You can then do some sideEffect work on that aggregation 
later in the path expression... Does that help?

> My use case is a little particular. I'm writing a mini language to
> support ITL [1], which can work over Kripke structures [2] stored in a
> graph. So what I'm doing is a lexer and a grammar to translate ITL
> into Gremlin queries.

Ah. You might wish to translate it directly to Pipes perhaps? In one week 
(August 1st -- next round of TinkerPop releases), Pipes++ is coming out which 
will make it very easy for anyone to emulate Gremlin behavior in any language 
of their choosing.

http://groups.google.com/group/gremlin-users/browse_thread/thread/a1a7092762d22e37
Just a thought...

See ya,
Marko.

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


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Javier de la Rosa
Thank you, Marko.

Pipes++ looks interesting. I have to do more tests but I hope to find
a way to acomplish my goal.

On Mon, Jul 25, 2011 at 10:40, Marko Rodriguez  wrote:
> Hi,
>
>>> Does that help you? Can you map that motif over to your problem?
>>
>> Thank you, I hope so. Maybe the best way is to get all the properties
>> map in each vertex in order to be able to operate with those values in
>> the next vertex. Is that possible?
>
> In that case do:
>
>        gremlin> g.V.sideEffect{x = it.map()}.out.sideEffect{println x}
>        [name:marko, age:29]
>        ==>v[2]
>        [name:marko, age:29]
>        ==>v[3]
>        [name:marko, age:29]
>        ==>v[4]
>        [name:peter, age:35]
>        ==>v[3]
>        [name:josh, age:32]
>        ==>v[5]
>        [name:josh, age:32]
>        ==>v[3]
>
> In short, every vertex out of V is passed into sideEffect{}. The current 
> vertex's properties are saved to x as a HashMap. Then the outgoing related 
> vertices of that vertex are retrieved. There is a sideEffect again where you 
> can access your map in x from previous.
>
> Perhaps I'm misunderstanding your use case... Finally, you might want to 
> consider "aggregate" as a way to get all before processing the next step. 
> Check this:
>
>        gremlin> x = []
>        gremlin> g.V.aggregate(x).out.sideEffect{println x*.map()}
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[2]
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[3]
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[4]
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[3]
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[5]
>        [[name:lop, lang:java], [name:vadas, age:27], [name:marko, age:29], 
> [name:peter, age:35], [name:ripple, lang:java], [name:josh, age:32]]
>        ==>v[3]
>
> In this way, x has ALL the maps of all the vertices coming out of V. x is an 
> ArrayList(). You can then do some sideEffect work on that 
> aggregation later in the path expression... Does that help?
>
>> My use case is a little particular. I'm writing a mini language to
>> support ITL [1], which can work over Kripke structures [2] stored in a
>> graph. So what I'm doing is a lexer and a grammar to translate ITL
>> into Gremlin queries.
>
> Ah. You might wish to translate it directly to Pipes perhaps? In one week 
> (August 1st -- next round of TinkerPop releases), Pipes++ is coming out which 
> will make it very easy for anyone to emulate Gremlin behavior in any language 
> of their choosing.
>        
> http://groups.google.com/group/gremlin-users/browse_thread/thread/a1a7092762d22e37
> Just a thought...
>
> See ya,
> Marko.
>
> http://markorodriguez.com
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Marko Rodriguez
Hi,

> Pipes++ looks interesting. I have to do more tests but I hope to find
> a way to acomplish my goal.

I will give you any query you ask over the play dataset:
https://github.com/tinkerpop/gremlin/wiki/Defining-a-Property-Graph

Thus, if you say, "Marko, tell me how to get all X, where Y, and this, but then 
ensure that, etc. etc.," I will provide you the respective Gremlin expression. 
In this way, hopefully, you can then take that and map it to your particular 
problem domain.

Hope all goes well with your project,
Marko.

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


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-25 Thread Javier de la Rosa
On Mon, Jul 25, 2011 at 17:53, Marko Rodriguez  wrote:
> Thus, if you say, "Marko, tell me how to get all X, where Y, and this, but 
> then ensure that, etc. etc.," I will provide you the respective Gremlin 
> expression. In this way, hopefully, you can then take that and map it to your 
> particular problem domain.

Thank you again, Marko. Let's try with a query that I'm not able to
build in Gremlin. Looking at the property graph, I need the final
vertices of all the paths of length 3, with at least one property
"name" equals to "josh" in some vertex except the first one.

Regards.



-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-26 Thread Marko Rodriguez


Hey hey,

> Thank you again, Marko. Let's try with a query that I'm not able to
> build in Gremlin. Looking at the property graph, I need the final
> vertices of all the paths of length 3, with at least one property
> "name" equals to "josh" in some vertex except the first one.


Here is the concise pro-style, where 'both' traverses both incoming and 
outgoing adjacent vertices.

g.V.both.loop(1){it.loops < 4}[[name:'josh']]

Here is the less than pro-style (as('x') is a way to name a step so its more 
readable where to "loop back to"):

g.V.as('x').both.loop('x'){it.loops < 4}[[name:'josh']]

This will give you the actual paths with, of course, the last element in the 
path being the vertex with name 'josh' (v[4]).

g.V.both.loop(1){it.loops < 4}[[name:'josh']].paths

Finally, realize that you might incur "reverberation" in your paths. 

gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].paths
==>[v[3], v[1], v[3], v[4]] // reverb
==>[v[3], v[4], v[1], v[4]] // reverb
==>[v[3], v[4], v[5], v[4]] // reverb
==>[v[3], v[4], v[3], v[4]] // reverb
==>[v[3], v[6], v[3], v[4]] // reverb
==>[v[2], v[1], v[3], v[4]]
==>[v[1], v[2], v[1], v[4]] // reverb
==>[v[1], v[3], v[1], v[4]] // reverb
==>[v[1], v[4], v[1], v[4]] // reverb
==>[v[1], v[4], v[5], v[4]] // reverb
==>[v[1], v[4], v[3], v[4]] // reverb
==>[v[6], v[3], v[1], v[4]]
==>[v[5], v[4], v[1], v[4]] // reverb
==>[v[5], v[4], v[5], v[4]] // reverb
==>[v[5], v[4], v[3], v[4]] // reverb
==>[v[4], v[1], v[3], v[4]] // reverb
==>[v[4], v[3], v[1], v[4]] // reverb

As such you can use uniquePath to remove reverberant paths:

gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].uniquePath 
==>v[4]
==>v[4]
gremlin> g.V.both.loop(1){it.loops < 4}[[name:'josh']].uniquePath.paths
==>[v[2], v[1], v[3], v[4]]
==>[v[6], v[3], v[1], v[4]]

Hope that helps,
Marko.

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


Re: [Neo4j] Comparing properties among different nodes in Gremlin

2011-07-26 Thread Javier de la Rosa
Really thank you, Marko, you're being very helpful for me. but I think
that is not exactly what I looking for, or maybe I'm not understanding
your solution at all.

On Tue, Jul 26, 2011 at 12:07, Marko Rodriguez  wrote:
> This will give you the actual paths with, of course, the last element in the 
> path being the vertex with name 'josh' (v[4]).

I would like to get the actual paths with the property 'name'='josh'
in some of the vertices, not only in the last one.


Please, take a look on this graph [1], it's a tree. It represents
differents states with different values of the variables 'I' and 'J',
showed off in that order. The reference nodes is only taken into
account like a way to set the initial states. I have also two temporal
queries that would be translated into something like:
1. Get all the paths with states with I=3 from the second state up to
the end of the path, with J=4 exactly in the fourth state, and with al
least one state with I=1 anywhere the path. This should return v1, v2,
v3, v4
2. Get all the paths with states with I=3 from the second state up to
the end of the path, and not J=1 in the third state. This should
return nothing.


Just for your curiosity, I'm trying to find an algorithm to translate
the original ITL queries to Gremlin scripts. In ITL, the queries above
would be something like:
1. next(always(I=3)) and next(next(J=4)) and sometimes(I=1)
2. next(always(I=3)) and not(next(J=1))
The operators next, always and sometimes have the semantics expected:
in the next state XXX holds, always XXX holds, and sometimes XXX
holds. Besides we have the operator len(n) that check if the returned
path has exactly n states.

Thanks.
Regards!




[1] http://box.jisko.net/i/5cbd3d31.png

-- 
Javier de la Rosa
http://versae.es
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user