use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class GraphBasedMatcher method match.
public Iterable<Edge> match(final Resource subject, final URI predicate, final Value object, final Resource context, final boolean includeInferred) {
// System.out.println("+ spoc: " + s + " " + p + " " + o + " " + c);
// System.out.println("+ \ts: " + subject + ", p: " + predicate + ", o: " + object + ", c: " + context);
final String contextStr = null == context ? GraphSail.NULL_CONTEXT_NATIVE : store.resourceToNative(context);
if (s && o) {
Vertex vs = store.getVertex(subject);
Vertex vo = store.getVertex(object);
if (null == vs || null == vo) {
return new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>());
} else {
// Right now, we arbitrarily choose the subject as the starting point.
return new FilteredIterator<Edge>(vs.getEdges(Direction.OUT), new FilteredIterator.Criterion<Edge>() {
public boolean fulfilledBy(final Edge edge) {
return store.matches(edge.getVertex(Direction.IN), object) && (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
}
});
}
} else if (s) {
Vertex vs = store.getVertex(subject);
return null == vs ? new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>()) : new FilteredIterator<Edge>(vs.getEdges(Direction.OUT), new FilteredIterator.Criterion<Edge>() {
public boolean fulfilledBy(final Edge edge) {
return (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
}
});
} else {
Vertex vo = store.getVertex(object);
return null == vo ? new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>()) : new FilteredIterator<Edge>(vo.getEdges(Direction.IN), new FilteredIterator.Criterion<Edge>() {
public boolean fulfilledBy(final Edge edge) {
return (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
}
});
}
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class PartitionEdgeIterable method iterator.
public Iterator<Edge> iterator() {
return new Iterator<Edge>() {
private Iterator<Edge> itty = iterable.iterator();
private PartitionEdge nextEdge;
public void remove() {
this.itty.remove();
}
public boolean hasNext() {
if (null != this.nextEdge) {
return true;
}
while (this.itty.hasNext()) {
final Edge edge = this.itty.next();
if (graph.isInPartition(edge)) {
nextEdge = new PartitionEdge(edge, graph);
return true;
}
}
return false;
}
public Edge next() {
if (null != this.nextEdge) {
final PartitionEdge temp = this.nextEdge;
this.nextEdge = null;
return temp;
} else {
while (this.itty.hasNext()) {
final Edge edge = this.itty.next();
if (graph.isInPartition(edge)) {
return new PartitionEdge(edge, graph);
}
}
throw new NoSuchElementException();
}
}
};
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class EventTransactionalGraphTest method testTransactionSeriesWithSuccess.
public void testTransactionSeriesWithSuccess() {
graph.addListener(graphChangedListener);
createEdge();
Edge e = createEdge();
e.setProperty("test", "it");
e.setProperty("test", "that");
Vertex v = createVertex();
v.setProperty("test", "it");
assertEquals(0, graphChangedListener.addEdgeEventRecorded());
assertEquals(0, graphChangedListener.addVertexEventRecorded());
assertEquals(0, graphChangedListener.edgePropertyChangedEventRecorded());
assertEquals(0, graphChangedListener.vertexPropertyChangedEventRecorded());
((EventTransactionalGraph) graph).commit();
assertEquals(2, graphChangedListener.addEdgeEventRecorded());
assertEquals(5, graphChangedListener.addVertexEventRecorded());
assertEquals(2, graphChangedListener.edgePropertyChangedEventRecorded());
assertEquals(1, graphChangedListener.vertexPropertyChangedEventRecorded());
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class EventTransactionalGraphTest method testTransactionSeriesOrder.
public void testTransactionSeriesOrder() {
graph.addListener(graphChangedListener);
graph.addListener(new ConsoleGraphChangedListener(graph));
Vertex v1 = graph.addVertex(10);
v1.setProperty("aaa", "bbb");
v1.setProperty("ccc", "ddd");
v1.removeProperty("aaa");
Vertex v2 = graph.addVertex(20);
Vertex v3 = graph.addVertex(30);
Edge e1 = graph.addEdge(100, v1, v2, "friend");
e1.setProperty("eee", "fff");
e1.setProperty("ggg", "hhh");
e1.setProperty("ggg", "hhhh");
e1.removeProperty("eee");
Edge e2 = graph.addEdge(101, v1, v2, "enemy");
graph.removeEdge(e2);
graph.removeVertex(v3);
assertEquals(0, graphChangedListener.getOrder().size());
((EventTransactionalGraph) graph).commit();
List<String> order = graphChangedListener.getOrder();
assertEquals("v-added-10", order.get(0));
assertEquals("v-property-changed-10-aaa:null->bbb", order.get(1));
assertEquals("v-property-changed-10-ccc:null->ddd", order.get(2));
assertEquals("v-property-removed-10-aaa:bbb", order.get(3));
assertEquals("v-added-20", order.get(4));
assertEquals("v-added-30", order.get(5));
assertEquals("e-added-100", order.get(6));
assertEquals("e-property-changed-100-eee:null->fff", order.get(7));
assertEquals("e-property-changed-100-ggg:null->hhh", order.get(8));
assertEquals("e-property-changed-100-ggg:hhh->hhhh", order.get(9));
assertEquals("e-property-removed-100-eee:fff", order.get(10));
assertEquals("e-added-101", order.get(11));
assertEquals("e-removed-101", order.get(12));
assertEquals("v-removed-30", order.get(13));
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class IdGraphTest method testDefaultIdFactory.
public void testDefaultIdFactory() throws Exception {
Graph graph = this.generateGraph();
Vertex v = graph.addVertex(null);
String id = (String) v.getId();
assertEquals(36, id.length());
assertEquals(5, id.split("-").length);
Vertex v2 = graph.addVertex(null);
Edge e = graph.addEdge(null, v, v2, "knows");
id = (String) e.getId();
assertEquals(36, id.length());
assertEquals(5, id.split("-").length);
graph.shutdown();
}
Aggregations