I have a graph with the following structure:
- Some vertices represent real-world items and some type, i.e. there is a vertex for "city" and vertices for specific cities like "London" or "Seattle". Each vertex can have 'is-a' edge to its type vertex, i.e.
"London" -(is-a)-> "city"
,"USA" -(is-a)-> "country"
. - Vertices can be also linked by "in" relationship, i.e.
"London" -(in)-> "UK"
,"Seattle" -(in)->"Washington"
. - Some vertices may also have "in-country" relationship, i.e.
"Seattle"->(in-country)->"USA"
, but some may not. - It is possible to have multiple links (i.e. some city can be disputed between two countries and so have two "in-country" or "in" links) - in this case multiple countries should be returned.
The task is for each vertex to try and find the country in which it resides (of course, it's meaningless for generic vertices like "city" but in this case it should just produce null). So I tried to do something like this:
v.as('loopstep').ifThenElse{it.out('is-a').has('ID', 'country').hasNext()}{
it
}{
it.ifThenElse{it.out('in-country').hasNext()}{
it.out('in-country')
}{
it.out('in').loop('loopstep'){it.loops < 10 }
}
}
but that produces NPE on loop, e.g.:
java.lang.NullPointerException
at com.tinkerpop.pipes.branch.LoopPipe.getLoops(LoopPipe.java:75)
etc. It looks like the loop can not see the "loopstep" label. Am I doing it wrong? What would be the right way to write such traversal query?
ifThenElse
should start with anit
notif
. Some code that creats a graph according to your description would be nice. – Faberv
) a city? second, what is the point of the looping construct given your schema? all city vertices link to countries via one or more edges of label "in" or "in-country" - so where is the need to loop? maybe i'm misunderstanding something about your schema? – stephen mallette