I would like to display all connected record ids grouped on the edge-classes they are connected with.
V1
^
|
edgeClass1
|
V2 <--edgeClass1-- V0 --edgeClass2--> V3
/ \
edgeClass3 edgeClass4
\ /
v v
V4
From this I would like to be able to target V0 and get the whole V0 record as well as all connected vertices grouped by their edge classes as follows:
{
rid: <V0rid>
someV0Property: someV0Value,
edgeClass1: [<V1rid>, <V2rid>],
edgeClass2: [<V3rid>],
edgeClass3: [<V4rid>],
edgeClass4: [<V4rid>]
}
The available edgeClasses are not known in advance, so I can't target them explicitly.
Is this possible?
Related
I have a couple of vertices (with property value) connected with edges in OrientDB such as:
X[value=0] ------------->Y[value=0]
^ \
/ v
A[value=1] -> B[value=1] -> C[value=1] -> D[value=1] -> E[value=1]
I now want to have the following traverse condition:
continue following vertices with value=1
if you find 2 paths, only follow path along value=0
The query on the vertices above should therefore return:
A,B,X,Y,D,E (C ignored and not visited)
How is that realizable in orientdb?
Using networkx 2.0 I try to dynamically add an additional edge attribute by looping through all the edges. The graph is a MultiDiGraph.
According to the tutorial it seems to be possible to add edge attributes the way I do in the code below:
g = nx.read_gpickle("../pickles/" + gname)
yearmonth = gname[:7]
g.name = yearmonth # works
for source, target in g.edges():
g[source][target]['yearmonth'] = yearmonth
This code throws the following error:
TypeError: 'AtlasView' object does not support item assignment
What am I doing wrong?
That should happen if your graph is a nx.MultiGraph. From which case you need an extra index going from 0 to n where n is the number of edges between the two nodes.
Try:
for source, target in g.edges():
g[source][target][0]['yearmonth'] = yearmonth
The tutorial example is intended for a nx.Graph.
Very basic question,
I just upgraded my Titan from 0.54 to Titan 1.0 Hadoop 1 / TP3 version 3.01.
I encounter a problem with deleting values of
Property key: Cardinality.LIST/SET
Maybe it is due to upgrade process or just my TP3 misunderstanding.
// ----- CODE ------:
tg = TitanFactory.open(c);
TitanManagement mg = tg.openManagement();
//create KEY (Cardinality.LIST) and commit changes
tm.makePropertyKey("myList").dataType(String.class).cardinality( Cardinality.LIST).make();
mg.commit();
//add vertex with multi properties
Vertex v = tg.addVertex();
v.property("myList", "role1");
v.property("myList", "role2");
v.property("myList", "role3");
v.property("myList", "role4");
v.property("myList", "role4");
Now, I want to delete all the values "role1,role2...."
// iterate over all values and try to remove the values
List<String> values = IteratorUtils.toList(v.values("myList"));
for (String val : values) {
v.property("myList", val).remove();
}
tg.tx().commit();
//---------------- THE EXPECTED RESULT ----------:
Empty vertex properties
But unfortunately the result isn't empty:
System.out.println("Values After Delete" + IteratorUtils.toList(v.values("myList")));
//------------------- OUTPUT --------------:
After a delete, values are still apparent!
15:19:59,780 INFO ThriftKeyspaceImpl:745 - Detected partitioner org.apache.cassandra.dht.Murmur3Partitioner for keyspace titan
15:19:59,784 INFO Values After Delete [role1, role2, role3, role4, role4]
Any ideas?
You're not executing graph traversals with the higher level Gremlin API, but you're currently mutating the graph with the lower level graph API. Doing for loops in Gremlin is often an antipattern.
According to the TinkerPop 3.0.1 Drop Step documentation, you should be able to do the following from the Gremlin console:
v = g.addV().next()
g.V(v).property("myList", "role1")
g.V(v).property("myList", "role2")
// ...
g.V(v).properties('myList').drop()
property(key, value) will set the value of the property on the vertex (javadoc). What you should do is get the VertexProperties (javadoc).
for (VertexProperty vp : v.properties("name")) {
vp.remove();
}
#jbmusso offered a solid solution using the GraphTraversal instead.
I'm trying to get multiple values by running an OrientDb command from Java. Specifically I am trying to get a list of Vertices that are linked to a vertex and the #rid of the Edges.
E.g If vertex V1 is linked to vertex V2 by edge E1, my query for V1 should return #rid of E1 and V2.
I can do that in Orient Studio by running the query:
select #rid, expand(in) from ExampleEdge where out = '#14:33'
How can I code the above query in Java? All the examples are showing only single value results like:
Iterable<Vertex> vertexes = graph.command(new OCommandSQL("select expand(in()) from node where #rid = '#14:33'")).execute();
I have this simple structure:
to get the RIDS, you can use this code:
String yourRid = "#12:0";
Iterable<Vertex> targets = g.command(new OSQLSynchQuery<Vertex>("select from ?")).execute(yourRid);
for (Vertex target : targets) {
Iterable<Edge> r = target.getEdges(Direction.IN, "exampleEdge");
List<Edge> results = new ArrayList<Edge>();
CollectionUtils.addAll(results, r.iterator());
System.out.println("Starting Vertex: "+yourRid);
System.out.println();
for (Edge result:results){
System.out.println("Edge "+result.getId()+" connected with Vertex "+result.getVertex(Direction.OUT).getId());
}
}
Output:
Starting Vertex: #12:0
Edge #13:3 connected with Vertex #12:1
Edge #13:4 connected with Vertex #12:2
Edge #13:5 connected with Vertex #12:3
I am in a situation where I need to get two different types of vertices using a single query. For example, assume that the graph has the following structure :
Node("User")--Edge("is_member")-->Node("Membership")--Edge("is_member")-->Node("Group")
Assume that the nodes have the following properties:
Membership
status
date
Group
name
date
type
Now, I need to get all the Membership nodes that a user is_member of, along with the corresponding Group's name. How do I write a Gremlin query for this?
I am using the Bulbs framework. How do I store the result in a python object?
The following query gives you for user u1 a map with key = Membership-Nodes and value = list of group names of the key membership node:
m=[:];u1.out('is_member').groupBy(m){it}{it.out('is_member').name}
Output is:
gremlin> m
==>v[m1]=[group1]
==>v[m2]=[group2, group3]
Here the used sample graph:
g = new TinkerGraph()
u1 = g.addVertex('u1')
u2 = g.addVertex('u2')
m1 = g.addVertex('m1')
m2 = g.addVertex('m2')
g1 = g.addVertex('g1')
g2 = g.addVertex('g2')
g3 = g.addVertex('g3')
g.addEdge(u1, m1, 'is_member')
g.addEdge(u1, m2, 'is_member')
g.addEdge(u2, m2, 'is_member')
g.addEdge(m1, g1, 'is_member')
g.addEdge(m2, g2, 'is_member')
g.addEdge(m2, g3, 'is_member')
g1.name = 'group1'
g2.name = 'group2'
g3.name = 'group3'
See also: How do I write a sub-query?
(tested with gremlin2)