This file contains 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
/// IN TEST SUITE | |
public void testBasicWalk(Pipeline<Vertex,Vertex> pipeline) { | |
int counter = 0; | |
while(pipeline.hasNext()) { | |
Vertex v = pipeline.next(); | |
assertEquals(v.getProperty("type"), "person"); | |
} | |
assertEquals(counter, 5); | |
} |
This file contains 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 testIndicesPersist() { | |
if (graphTest.isPersistent) { | |
IndexableGraph graph = (IndexableGraph) this.graphTest.getGraphInstance(); | |
Vertex a = graph.addVertex(null); | |
Object aId = a.getId(); | |
Vertex b = graph.addVertex(null); | |
Edge e = graph.addEdge(null, a, b, "related"); | |
Object eId = e.getId(); | |
graph.createAutomaticIndex("TEST-AUTO-VERTEX", Vertex.class, null); |
This file contains 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
class ShareSavSchema { | |
public static Schema generateSchema() { | |
Schema schema = new Schema(); | |
def thing = schema.addClass("thing"); | |
def timeThing = schema.addClass("time thing"); | |
thing.canHaveProperty("_type", String.class); | |
timeThing.setSuperClass(thing); | |
timeThing.addCanHaveProperty("_startDate", Long.class) |
This file contains 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 Iterator<Long> evaluateQuery(final IndexableGraph g, final String userName, final String savName, Long startDate, Long endDate) { | |
if (endDate == -1l) { | |
endDate = Long.MAX_VALUE; | |
} | |
final Vertex root = g.idx(T.v)[[share_id: 2l]] >> 1; | |
final Vertex user = g.idx(T.v)[[user_name: userName]] >> 1; | |
return root.out('contains').loop(1) {it.loops < 3}.out('hasUser').retain([user]).back(2). | |
out('contains').loop(1) {it.loops < 5}.out('hasSav'). | |
out('hasProperty').filter {it.getProperty('_type') == 'sav_name'}.filter {it.getProperty('value') == savName}. | |
filter {it.getProperty('_startDate') >= startDate && it.getProperty('_endDate') <= endDate}.back(4).sav_id |
This file contains 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 void main(String[] args) { | |
//Graph graph = ShareSavParser.generateShareSavGraph(new Neo4jGraph("/tmp/hmp")); | |
Graph graph = ShareSavParser.generateShareSavGraph(new TransactionalTinkerGraph()); | |
println graph; | |
def itty = ShareSavTraversals.evaluateQuery(graph, "Marco Sena", "HOSPITAL NACIONAL", -1l, -1l); | |
while (itty.hasNext()) { | |
println(itty.next()); | |
} | |
graph.shutdown(); |
This file contains 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
Iterator<Vertex> itty = graph.getIndex(Index.VERTICES, Vertex.class).get("sav_id", 12345); | |
Vertex savNode; | |
if(itty.hasNext()) { | |
savNode = itty.next(); | |
} else { | |
savNode = graph.addVertex(new HashMap(..)) // the map has the MUST_HAVE requirements | |
} | |
// do something with savNode |
This file contains 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
package com.cisco.hmp.graph.sharesav | |
import com.tinkerpop.blueprints.pgm.IndexableGraph | |
import com.tinkerpop.blueprints.pgm.Vertex | |
import com.tinkerpop.gremlin.Gremlin | |
import com.tinkerpop.gremlin.GremlinTokens.T | |
/** | |
* @author Marko A. Rodriguez (http://markorodriguez.com) | |
*/ |
This file contains 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
Graph graph = ShareSavParser.generateShareSavGraph(new TransactionalTinkerGraph()); | |
def itty = ShareSavTraversals.evaluateQuery(graph, "Marco Sena", "HOSPITAL NACIONAL", 1222844400000l, 1223103600000l); | |
while (itty.hasNext()) { | |
println("here: " + itty.next()); | |
} | |
itty = ShareSavTraversals.evaluateQuery(graph, "Marco Sena", "HOSPITAL NACIONAL", -1l, -1l); | |
while (itty.hasNext()) { | |
println("here2: " + itty.next()); | |
} |
This file contains 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
package com.cisco.hmp.graph.sharesav; | |
import com.cisco.hmp.graph.BaseTest; | |
import com.cisco.hmp.graph.schema.graph.SchemaGraph; | |
import com.cisco.hmp.graph.schema.graph.util.TransactionalTinkerGraph; | |
import java.io.IOException; | |
import java.util.Iterator; | |
/** |
This file contains 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 Iterator<Long> evaluateQuery2(final Long shareId, int level, final Long startDate, final Long endDate) { | |
final Vertex root = g.idx(T.v)[[share_id: 2l]] >> 1; | |
int subLevel = Integer.MAX_VALUE; | |
final Vertex secondRoot = root.out('contains').loop(1) {def x = it.object.getProperty('share_id').equals(shareId); if (x) {subLevel = it.loops}; !x}.next(); | |
if (level == 0) { | |
return secondRoot.out('contains').loopEmit(1) {true} {true}. | |
filter {it.getProperty('_startDate') <= startDate && (it.getProperty('_endDate').equals(-1l) || it.getProperty('_endDate') >= endDate)}.share_id | |
} else { |
OlderNewer