Created
August 20, 2014 09:15
-
-
Save fancyerii/2cf070972886836eaae0 to your computer and use it in GitHub Desktop.
create graph and query with gremlin
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) { | |
TitanGraph g=TitanFactory.open("/Users/lili/soft/titan-server-0.4.4/conf/titan-hbase-es.properties"); | |
{ | |
Vertex mike=g.addVertex(null); | |
mike.setProperty("name", "Mike"); | |
mike.setProperty("l_name", "mike"); | |
mike.setProperty("v_type", 0); | |
Vertex automobile=g.addVertex(null); | |
automobile.setProperty("name", "Avalon"); | |
automobile.setProperty("l_name", "avalon"); | |
automobile.setProperty("v_type", 0); | |
Vertex buy=g.addVertex(null); | |
buy.setProperty("v_type", 0); | |
Vertex word_buy=g.addVertex(null); | |
word_buy.setProperty("name", "buy"); | |
word_buy.setProperty("l_name", "buy"); | |
buy.addEdge("meaning_to_word", word_buy); | |
Vertex word_purchase=g.addVertex(null); | |
word_purchase.setProperty("name", "purchase"); | |
word_purchase.setProperty("l_name", "purchase"); | |
buy.addEdge("meaning_to_word", word_purchase); | |
TitanEdge e=(TitanEdge) mike.addEdge("predicate", automobile); | |
e.setProperty("toMeaning", buy); | |
g.commit(); | |
//query mike purchase what? | |
Pipe pipe = Gremlin.compile("_().outE('predicate').as('x').outE('toMeaning').inV.out.has('l_name','purchase').back('x').out.name"); | |
pipe.setStarts(g.query().has("l_name","mike").vertices().iterator()); | |
for(Object name : pipe) { | |
System.out.println((String) name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment