This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////// | |
///////// BLUEPRINTS //////////// | |
///////////////////////////////// | |
public interface Graph { | |
public <S, A extends Flow<A, S, Vertex>> A V(); | |
... | |
} | |
public interface Flow<A extends Flow, S, E> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void shouldFlow() { | |
Graph g = TinkerFactory.createClassic(); | |
g.V().has("name", "marko").has("age", 29).out("created", "knows").forEachRemaining(System.out::println); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <A extends Gremlin<?, Vertex>> A V() { | |
Gremlin gremlin = new DefaultGremlin<Object, Vertex>(); | |
gremlin.addStarts(new HolderIterator<>(this.vertices.values().iterator())); | |
return (A) gremlin; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Future<Graph> submit() { | |
try { | |
final FileSystem fs = FileSystem.get(this.hadoopConfiguration); | |
fs.delete(new Path("output"), true); | |
final FileSystem local = FileSystem.getLocal(this.hadoopConfiguration); | |
final Path vertexProgramPath = new Path("tmp/gremlin", UUID.randomUUID().toString()); | |
final ObjectOutputStream os = new ObjectOutputStream(fs.create(vertexProgramPath)); | |
os.writeObject(this.vertexProgram); | |
os.close(); | |
fs.deleteOnExit(vertexProgramPath); |