title: Reflect on Gremlin traversal type (Edge, Vertex, Property) in CHOOSE step, possible?
body: <p>I am extending <strong>sparql-to-gremlin</strong> code to support fully and partially unbound predicate queries that can be used by automated processes to explore the graph structure. The idea being that you could just connect to some graph DB and ask a fully unbound query with some limit and get vertex properties, edge types, edge properties, etc. That can then be explored more.</p>
  
  <p>I can now solve a fully unbound query and can solve one that has the subject bound to a vertex. Now I am trying to put it together into a multi-literal query and finding that the Gremlin MATCH Step would need to reflect on the type of Traversal before it can decide which steps would actually apply. For example if, the Traversal results in a Vertex, asking for out/in edges and properties makes sense; if it’s an Edge though, asking for out/in edges does not make sense and actually results in errors about unexpected type being thrown.</p>
  
  <p>Thus the question, is it possible to write a kind of “switch” statement that would reflect on the type and then only ask for things that makes sense in that context?</p>
  
  <p>Here’s one type of SPARQL query that I am trying to support (based on the Graph of the Gods described here <a href="https://old-docs.janusgraph.org/0.1.0/getting-started.html" rel="nofollow noreferrer">https://old-docs.janusgraph.org/0.1.0/getting-started.html</a>):</p>
  
  <p><a href="https://i.stack.imgur.com/iL0sb.png" rel="nofollow noreferrer">https://old-docs.janusgraph.org/0.1.0/images/graph-of-the-gods-2.png</a></p>
  
  <pre><code>SELECT ?BATTLE ?PRED ?VALUE
  WHERE {
      vid:6 ep:battled ?BATTLE .
      ?BATTLE ?PRED ?VALUE .
  }
  </code></pre>
  
  <p>Here we are starting from a vertex with id 6, grabbing the outgoing edge reference with “battled” label, then grabbing all possible properties of the edge along with their values.</p>
  
  <p>Here vertex with id 6 is Hercules, which has 3 outgoing edges with label “battled” going to vertex with id 9 (Nemean), 10 (Hydra) and 11 (Cerberus). I would want to the have ?PRED be bound to v:id (edge id), v:label (edge label), v:time (edge time property value), v:place (edge place property value), eps:battled (an extension to sparql-to-gremlin relating edge to an IN vertex).</p>