2017-05-23 208 views
2

我是Gremlin的新手,我正在使用Gremlin 3.0.2和Stardog 5.0。我編寫了這個查詢來找出schema.org本體中兩個實體之間的路徑。下面是輸出 -過濾gremlin結果

gremlin>`g.V().hasLabel('Canal').repeat(both().simplePath()).until(g.V().hasLabel('Continent')).path().limit(5)` 

==> [V [運河],V [RDF-模式#類]] ==> [V [運河],V [BodyOfWater],V [地貌],v [Continent]] ==> [v [Canal],v [BodyOfWater],v [rdf-schema#Class],v [Continent]] ==> [v [Canal],v [BodyOfWater] ,v [Pond],v [rdf-schema#Class],v [Continent]] ==> [v [Canal],v [BodyOfWater],v [OceanBodyOfWater],v [rdf-schema#Class] [Continent]]

我無法想出一種方法來消除所有具有「rdf-sche ma#Class「。請有人建議一個解決方案?我想使用Gremlin進行過濾。謝謝!

回答

1

這樣做的一種方法是將後過濾器應用於返回的路徑。因此,舉例來說,如果你有這樣的事情:

gremlin> graph = TinkerFactory.createModern() 
==>tinkergraph[vertices:6 edges:6] 
gremlin> g = graph.traversal() 
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] 
gremlin> g.V().outE('created').inV().path() 
==>[v[1],e[9][1-created->3],v[3]] 
==>[v[4],e[10][4-created->5],v[5]] 
==>[v[4],e[11][4-created->3],v[3]] 
==>[v[6],e[12][6-created->3],v[3]] 

,想要擺脫邊緣,你可以做這樣的事情:

gremlin> g.V().outE('created').inV().path(). 
......1> local(unfold().filter(__.not(hasLabel('created'))).fold()) 
==>[v[1],v[3]] 
==>[v[4],v[5]] 
==>[v[4],v[3]] 
==>[v[6],v[3]] 

,使新線基本上只是說,對於每個路徑項目,展開它,在標籤上爲那些沒有「創建」的過濾器做一些過濾,然後將路徑折回到列表中。