Path Traversals
Path traversals map traversal steps to a location to use in the event that a previous location must be revisited.
This path traversal starts at an ingredient, traverses to a recipe, and eventually finds a book that contains the recipe with the ingredients specified.
g.V().has('ingredient', 'name',within('beef','carrots')).in('includes').as('Recipe').
out().hasLabel('book').as('Book').
select('Book','Recipe').
by('name').by('name').path()
The output for this traversal lists each result:
==>[v[{~label=ingredient, member_id=2, community_id=1442590464}],
v[{~label=recipe, member_id=2, community_id=473764096}],
v[{~label=book, member_id=0, community_id=568859392}],
{Book=The Art of French Cooking, Vol. 1, Recipe=Beef Bourguignon}]
==>[v[{~label=ingredient, member_id=1, community_id=684566272}],
v[{~label=recipe, member_id=0, community_id=1462084224}],
v[{~label=book, member_id=1, community_id=1620680576}],
{Book=The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution, Recipe=Carrot Soup}]
Another path traversal creates a tree that emanates from a vertex label, in this case a book
.
g.V().hasLabel('book').in().tree().by('name').next()
The output for this traversal lists each result:
==>Simca's Cuisine: 100 Classic French Recipes for Every Occasion=
{Patricia Simon={}, Simone Beck={}}
==>The Art of French Cooking, Vol. 1=
{Simone Beck={}, Julia Child={}, Beef Bourguignon={}, Louisette Bertholie={}, Salade Nicoise={}}
==>The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution=
{Alice Waters={}, Kelsie Kerr={}, Roast Pork Loin={}, Carrot Soup={}, Fritz Streiff={}, Patricia Curtan={}}
==>The French Chef Cookbook=
{Julia Child={}}
Each book lists the authors and recipes that are included in the book.
Another tree traversal discovers all the vertices that are on outgoing tree branch from a recipe
.
g.V().hasLabel('recipe').out().tree().by('name').next()
The output for this traversal lists each result:
==>Roast Pork Loin=
{red wine={}, pork loin={}, chicken broth={}, The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution={}}
==>Spicy Meatloaf=
{bacon={}, celery={}, pork sausage={}, onion={}, ground beef={}, green bell pepper={}}
==>Beef Bourguignon=
{mashed garlic={}, butter={}, The Art of French Cooking, Vol. 1={}, onion={}, tomato paste={}, beef={}}
==>Carrot Soup=
{butter={}, onion={}, chicken broth={}, carrots={}, The Art of Simple Food: Notes, Lessons, and Recipes from a Delicious Revolution={}, thyme={}}
==>Rataouille=
{mashed garlic={}, yellow onion={}, olive oil={}, zucchini={}, eggplant={}}
==>Salade Nicoise=
{tuna={}, The Art of French Cooking, Vol. 1={}, hard-boiled egg={}, olive oil={}, tomato={}, green beans={}}
==>Wild Mushroom Stroganoff=
{mushrooms={}, yellow onion={}, egg noodles={}}
==>Oysters Rockefeller=
{oyster={}, chervil={}, parsley={}, celery={}, fennel={}, shallots={}, Pernod={}}
Each recipe lists the ingredients for the recipe and the books that include the recipe.