Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Marko A. Rodriguez okram

🏠
Working from home
View GitHub Profile
View gist:8711493
@Test
public void testUnion() {
Graph g = TinkerFactory.createClassic();
Gremlin.of(g).v(1).union(
Gremlin.of().out("knows"),
Gremlin.of().out("created").in("created")
).value("name").forEach(System.out::println);
}
View gist:8739037
public static TinkerGraph createModern() {
final TinkerGraph g = TinkerGraph.open();
final Vertex marko = g.addVertex(Element.ID, 1, Element.LABEL, "person", "name", "marko", "locations", AnnotatedList.make());
final Vertex stephen = g.addVertex(Element.ID, 7, Element.LABEL, "person", "name", "stephen", "locations", AnnotatedList.make());
final Vertex matthias = g.addVertex(Element.ID, 8, Element.LABEL, "person", "name", "matthias", "locations", AnnotatedList.make());
final Vertex daniel = g.addVertex(Element.ID, 9, Element.LABEL, "person", "name", "daniel", "locations", AnnotatedList.make());
final Vertex gremlin = g.addVertex(Element.ID, 10, Element.LABEL, "software", "name", "gremlin");
final Vertex blueprints = g.addVertex(Element.ID, 11, Element.LABEL, "software", "name", "blueprints");
View gist:8829550
@Test
public void shouldFlow() {
Graph g = TinkerFactory.createClassic();
g.V().has("name", "marko").has("age", 29).out("created", "knows").forEachRemaining(System.out::println);
}
View gist:8830081
public <A extends Gremlin<?, Vertex>> A V() {
Gremlin gremlin = new DefaultGremlin<Object, Vertex>();
gremlin.addStarts(new HolderIterator<>(this.vertices.values().iterator()));
return (A) gremlin;
}
View gist:8828362
//////////////////////////////////
///////// BLUEPRINTS ////////////
/////////////////////////////////
public interface Graph {
public <S, A extends Flow<A, S, Vertex>> A V();
...
}
public interface Flow<A extends Flow, S, E> {
View gist:9104098
public void testStuff() throws Exception {
Graph g = TinkerFactory.createClassic();
g.V().out().value("name").forEach(System.out::println);
System.out.println("----------");
g.V().out().value("name").submit(g.compute()).forEachRemaining(System.out::println);
}
///////////
lop
View gist:9105890
g.V().pageRank().forEachRemaining(System.out::println);
[v[1], 0.15000000000000002]
[v[2], 0.19250000000000003]
[v[3], 0.4018125]
[v[4], 0.19250000000000003]
[v[5], 0.23181250000000003]
[v[6], 0.15000000000000002]
View gist:9125599
public void testOLAPWriteBack() throws Exception {
Graph g = TinkerFactory.createClassic();
g.V().pageRank().sideEffect(p -> p.get().getValue0().setProperty("pageRank", p.get().getValue1())).forEachRemaining(System.out::println);
System.out.println("---------------");
g.V().value("pageRank").forEachRemaining(System.out::println);
System.out.println("---------------");
g.V().pageRank().sideEffect(p -> p.get().getValue0().setProperty("pageRank", p.get().getValue1())).submit(g.compute()).forEachRemaining(System.out::println);
}
View gist:9237525
private SliceRange getSliceRange(final VertexQueryFilter inputFilter, final int limit) {
final SliceQuery slice = TitanInputFormat.inputSlice(inputFilter, this.graph);
final SliceRange sliceRange = new SliceRange();
sliceRange.setStart(slice.getSliceStart().asByteBuffer());
sliceRange.setFinish(slice.getSliceEnd().asByteBuffer());
sliceRange.setCount(Math.min(limit, slice.getLimit()));
return sliceRange;
}
View gist:9237551
public class VertexQueryFilter extends DefaultVertexQuery {
public static final String FAUNUS_GRAPH_INPUT_VERTEX_QUERY_FILTER = "faunus.graph.input.vertex-query-filter";
private static final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
private static final String V = "v";
private static final DummyVertex DUMMY_VERTEX = new DummyVertex();
private boolean doesFilter = false;