1

I have a scenario here where (unable to attach image) a vertex label as 'url' is attached to various other labels . Realtime English Verbs are made as edge names and are provided during retrieval.

URL -> has -> otherentities

URL -> verb1 -> states
URL -> verb2 -> states  etc..

Likewise for other labels
URL -> verb1 -> pages
URL -> verb2 -> pages etc..

URL -> verb1 -> lines
URL -> verb2 -> lines etc..

URL -> verb1 -> schedule
URL -> verb2 -> schedule etc..

URL -> verb1 -> section
URL -> verb2 -> section etc..

URL -> verb1 -> box
URL -> verb2 -> box etc..

URL -> verb1 -> input_method
URL -> verb2 -> input_method etc..

As the starting point I have labels and value properties of name of some of the vertices ie states, schedule,section,box,lines,pages and verbs(this is compolsary as input).

Now the values of the above labels are provided seperated by & in each cell of the CSV and I am parsing the CSV in java and checking labels and the names of each and forming dynamic gremlin query.

So the problem statement here is we want to get all URLS : Where all the verbs are present in edge labels(and condition) along with , vertices where all input_method name-value vertices are present ( with and condition ) And rest of the name-value vertices (other labels) present with or condition(one label multiple name-values) .

I have segregated and made three queries to solve the problem where I am getting the startvertex first ( starting with any vertex ) and getting all urls.

Like:
For otherentities-
g.V().hasLabel('" + startLabel + "').inE('has').has('forward','" + startLabel+ "').outV().hasLabel('url') 
For rest all labels:
g.V().hasLabel('" + startLabel + "').inE('" + verb + "').has('forward','" + startLabel+ "').outV().hasLabel('url')

Then I am looping each url and forming queries depending on label like:
g.V().hasLabel('url').has('id','fbd385c2-232f-4cdf-842d-ccea20941d4d').as('a').where(and(outE('generate').has('forward','states').where(or(inV().hasLabel('states').has('name', 'Massachusetts'))))).select('a')

And for input_method and other entities forming another sort of queries and querying separately .

So is there a method where I can combine all 4 queries into single query and fire to get my answer to avoid latency. Please help.

Varun Tahin
  • 299
  • 1
  • 2
  • 15
  • 1
    When asking questions about Gremlin it's much easier for those trying to supply an answer if you include some Gremlin to create some sample data (especially for more complex questions). Please consider replacing your pseudo-graph code for actual Gremlin as was done here: https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Sep 19 '18 at 10:52
  • Thanks . Will try to do so . Right now have solved the problem . For other's reference wrote this query: g.V().hasLabel('schedule').has('name',within('2')).as('a').inE().outV().hasLabel('url').and(outE('needed').has('forward','schedule').inV().hasLabel('schedule').has('name', within('2')),outE('input').has('forward','schedule').inV().hasLabel('schedule').has('name',within('2'))) – Varun Tahin Sep 19 '18 at 11:31

0 Answers0