GraphDB paths through a a specified node - path-finding

GraphDB 9.9 introduced a feature providing path searches with various configurations. Is there a way to filter obtained paths by a specific node which they need to traverse?
Using the recursive graph pattern instead of the wildcard pattern search does not help - the aim is not to repeatedly look for the specified node, only to pass through it once.

Currently this is not possible, but we do have it planned for a future release.

Related

gremlin shortestPath() with step

where is the document about gremlin with step?
https://tinkerpop.apache.org/docs/current/reference/#with-step
https://tinkerpop.apache.org/javadocs/current/full/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/ShortestPath.html
there is no example I can use.
I want to know all with-step option(like ShortestPath.edges-Direction.OUT) for shortestPath().
I found below
g.withComputer().V(xxx).shortestPath().with(ShortestPath.edges, Direction.OUT).with(ShortestPath.distance, 'cost').with(ShortestPath.target, hasId(bbb))
I want to know all option I can use
The with()-step is not really a "step". It is a step modulator. Its context is bound to the step that it is modifying and therefore you won't find "all the with() configurations" in one place. You can only find them in the documentation related to the steps that they modulate. Using shortestPath() as an example, note that if you look at the shortestPath() step documentation all of the options are present.
You may also need to consult the documentation of your graph provider as they may provide their own configuration keys for certain steps which can help optimize or otherwise modify traversal operations.

Gremlin.NET Query Compilation Error: Unable to find any method 'hasNext'

The line: g.V('1').out('knows').hasId('2').hasNext()
This exact line works in the Gremlin console.
I have not read in the documentation that hasNext does not exist in Gremlin.NET. Am I missing something, or is there simply another way to do this in Gremlin.NET?
This method is really missing in Gremlin.Net right now. While this is not explicitly stated in the documentation, the documentation does list all terminal steps implemented by Gremlin.Net:
ITraversal.Next()
ITraversal.NextTraverser()
ITraversal.ToList()
ITraversal.ToSet()
ITraversal.Iterate()
hasNext is also such a terminal step but as you can see it is missing in this list.
The only workaround I can think of for situations like this is to use the count step and then check in your application whether the returned count is greater than zero:
var count = g.V("1").Out("knows").HasId("2").Count().Next();
var exists = count > 0;
In some cases it could also make sense to limit the number of vertices going into the Count step as you aren't interested in the exact count but only want to know whether at least one vertex exists:
g.V("1").Out("knows").HasId("2").Limit<Vertex>(1).Count().Next();
This is also the proposed workaround in the ticket for this feature: TINKERPOP-1921.
It does not exist yet:
https://issues.apache.org/jira/browse/TINKERPOP-1921
The main reason is related to the fact that hasNext() is a Java Iterator semantic that was not applied to .NET. Gremlin Language Variants (GLVs) like .NET are given some latitude in terms of how they interpret the language so as to provide the most at-home feel for developers using it. In other words, if you are using the .NET GLV you shouldn't feel as though you are coding in Java, but should instead feel write at home with the standard .NET semantics.
That said, it could be argued, as it is in the issue I've referenced above, that something like hasNext() is a common form of Gremlin as a query language and should thus be available in all GLVs. So, we will consider those options as we come across them.
For .NET I guess you would try to check Current as discussed here.

Add or get vertex in Azure Cosmos DB Graph API

Using Gremlin, I can create a vertex in an Azure Cosmos DB graph by issuing
g.addV('the-label').property('id', 'the-id')
and subsequently find it using
g.V('the-label').has('id', 'the-id')
However, I haven't found a way to issue a query that will insert the node if it is missing, and just get the reference to it if it already exists. Is there a way?
My concrete use case is that I want to add an edge between two nodes, regardless of whether those nodes (or the edge, for that matter) exist already or not, in a single query. I tried this upsert approach, but apparently Cosmos DB does not support Groovy closures, so it won't work.
The "upsert pattern" is relatively well defined and accepted at this point. It is described here. If you want to extend that to also add an edge, that's possible too:
g.V().has('event','id','1').
fold().
coalesce(unfold(),
addV('event').property('id','1')).as('start').
coalesce(outE('link').has('id','3'),
coalesce(V().has('event','id','2'),
addV('event').property('id','2')).
addE('link').from('start').property('id','3'))
If that looks a bit complex you can definitely simplify with a Gremlin DSL (though I'm not sure that CosmosDB supports Gremlin bytecode at this point). Here's an example with even more complex upsert logic simplified by a DSL. It's discussed in this blog post in more detail.
Please look at this.
http://tinkerpop.apache.org/docs/current/reference/#coalesce-step
You can try
g.Inject(0).coalesce(__.V().has('id', 'the-id'), addV('the-label').property('id', 'the-id'))
btw, you won't able to find the vertex using g.V('the-label').has('id', 'the-id').
g.V() accepts vertex id as parameters and not vertex labels.

A* search in neo4j

I want to search for shortest path in the directed acyclic graph with neo4j. I have graph that looks similar to this:
I want to find path starting from Root down to Layer 3. At each layer I have different set of properties and I can calculate weight using this properties and user input. I need to find all shortest paths with minimal dynamic weight using A* or another search algorithm (it is possible to have several paths with equal weights). Is it possible with neo4j and cypher or gremlin?
I don't want to use embedded version because my project is written in python, so I can't use java library that as I know can do this.
As of now, Cypher does not allow you to pass in function e.g. your cost function. Adding this as feature must be decided very carefully as injecting runnable code by a query language has some security concerns.
That said what you can do now: create a unmanaged extension to the Neo4j server. Inside your unmanaged extension you make use of the the provided graph algorithms. Using JAX-RS parameter you provide data to identify the start and end node of your traversal and let graph algos do the dirty work.
You might want to take a look at https://github.com/sarmbruster/unmanaged-extension-archetype, this is a minimalistic sample project using gradle as a build system.
However, the sketched idea involved Java coding for the server side part. Client side you can use whatever stack you like.

TinkerPop Blueprints and Frames - How to treat data as collections

I found this question How to store and retrieve different types of Vertices with the Tinkerpop/Blueprints graph API?
But it's not a clear answer for me.
How do I query the 10 most recent articles vs the 10 most recently registered users for an api for instance? Put graphing aside for a moment as this stack must be able to handle both a collection/document paradigm as well as a graphing paradigm (relations between elements of these TYPES of collections). I've read everything including source and am getting closer but not quite there.
Closest document I've read is the multitenant article here: http://architects.dzone.com/articles/multitenant-graph-applications
But it focuses on using gremlin for graph segregation and querying which I'm hoping to avoid until I require analysis on the graphs.
I'm considering using cassandr/hadoop at this point with a reference to the graph id but I can see this biting me down the road.
Indexes in Tinkerpop/Blueprints only support simple lookups based on exact matches of property keys.
If you want to find the 10 most recent articles, or articles with the phrase 'Foo Bar', you may have to maintain an external index using Lucene or Elastic Search. These technologies use inverted indexes which support term/phrase lookups, range queries, and wildcard searches, etc. You can store the vertex.getId() as the field in the indexed document to link back to the vertex in the graph database.
I have implemented something like this for my application which uses a Blueprints database (Bitsy) and a fancy index (Lucene). I have documented the high-level design to (a) keep the fancy index up-to-date using batch updates every few seconds and (b) ensure transactional consistency across the graph database and the fancy index. Hope this helps.
Answering my own question to this - The answer is indices.
https://github.com/tinkerpop/blueprints/wiki/Graph-Indices

Resources