I have simplified a decision graph. It starts with begin vertex and ends with decision. My aim is to calculate the sum of a score (score associated with vertex) while traveling different paths (to reach decision vertex).
The input to Graph is JSON.
Edges between vertices contain variables and values which can be checked from the input JSON.
Example input JSON :{ "age":45,"income_source":"job" }
Output is the sum of the scores [10 + 15 + 22] = 47
In Neo4j a Cypher query allows you to pass JSON input as query parameters but I do not know how this can be done in Gremlin.
Graph link : https://gremlify.com/nwgxqs5h7zh/
g.addV('begin').as('beg').
addV('decision').property('score',0).property('decision_code',"minor").as('dec0').
addV('age').property('score',10).as('age10').
addV('age').property('score',20).as('age20').
addV('salary').property('score',15).as('sal15').
addV('salary').property('score',25).as('sal25').
addV('salary').property('score',18).as('sal18').
addV('salary').property('score',30).as('sal30').
addV('decision').property('score',22).property('decision_code',"decision_22").as('dec22').
addV('decision').property('score',45).property('decision_code',"decision_45").as('dec45').
addV('decision').property('score',18).property('decision_code',"decision_18").as('dec18').
addV('decision').property('score',30).property('decision_code',"decision_30").as('dec30').
addE('relation').property('var',"age").property('val',"").property('min',"10").property('max',"18").from('beg').to('dec0').
addE('relation').property('var',"age").property('val',"").property('min',"19").property('max',"48").from('beg').to('age10').
addE('relation').property('var',"age").property('val',"").property('min',"49").property('max',"80").from('beg').to('age20').
addE('relation').property('var',"income_source").property('val',"job").property('min',"-1").property('max',"-1").from('age10').to('sal15').
addE('relation').property('var',"income_source").property('val',"buisness").property('min',"-1").property('max',"-1").from('age10').to('sal25').
addE('relation').property('var',"income_source").property('val',"job").property('min',"-1").property('max',"-1").from('age20').to('sal18').
addE('relation').property('var',"income_source").property('val',"buisness").property('min',"-1").property('max',"-1").from('age20').to('sal30').
addE('relation').property('var',"").property('val',"").property('min',"-1").property('max',"-1").from('sal15').to('dec22').
addE('relation').property('var',"").property('val',"").property('min',"-1").property('max',"-1").from('sal25').to('dec45').
addE('relation').property('var',"").property('val',"").property('min',"-1").property('max',"-1").from('sal18').to('dec18').
addE('relation').property('var',"").property('val',"").property('min',"-1").property('max',"-1").from('sal30').to('dec30')
There is an issue with lt, gt, inside, between
predicate. It only accepts number not any thing which evaluates to number.
g.inject(['val1':10,'val2':15]).as('data').V().
where(select('data').select('val1').is(lt(select('data').values('val2'))))
Above query fails Cannot compare '10' (Integer) and '[SelectOneStep(last,data), PropertiesStep([val2],value)]'...
Due to this issue below query also fails.
g.withSack(0).inject(['age':45,'source':'job']).as('data').
V().hasLabel('begin').
repeat(outE().as('e').where(select('data').select(select('e').values('var')).is(eq(select('e').values('val')).or(inside(select('e').values('min'),select('e').values('max'))))).inV().sack(sum).by('score')).
until(hasLabel('decision')).project('final_score','path').by(sack()).by(path())
Please let me know if this problem can be modeled in different way to achieve same output score
Thank you for your time.