Open laurendelong21 opened 1 year ago
Yes! Currently, this is the dumbest but most direct way
rel exists_path(true) = path(0, 4)
rel exists_path(false) = not path(0, 4)
I'm working on a patch in which the following syntax will be supported:
rel exists_path(b) = b := exists(path(0, 4))
Hope this answers your question!
I colud not find any example code making a query using "Scallopy" Python code. All query codes use Scallop syntax. For example given bellow scallopy code
ctx.add_relation("color",(int, str))
ctx.add_facts("color",[(0, "blue"), (1, "green"), (2, "blue")])
How do I query the context to get the "blue" ?
You will be able to query an output relation. For instance, what you can do is:
ctx.add_rule("color_of_obj_0(c) = color(0, c)") # adding a query
ctx.run(). # execute the query
result_facts = list(ctx.relation("color_of_obj_0")) # get the results stored inside of `color_of_obj_0` relation; will likely be [("blue",)]
result = result_facts[0][0] # "blue"
Thank you for the quick reply, and I'm sorry I did not clarify it. The query should find all the tuples having "blue". The expected result should be: [(0, "blue"), (2, "blue")]
In that case, you can write the following
ctx.add_rule("blue_objs(o, c) = color(o, c) and c == \"blue\"")
ctx.run()
result_facts = list(ctx.relation("blue_objs")) # [(0, "blue"), (2, "blue")]
Hello,
I was wondering if it's possible to make a query with a KB in scallopy in which you simply get a True/False or Yes/No answer. For example, within the tutorial, what if I want to check whether a path exists between two nodes without having to list out all of the paths?
Such as
path(0,4)
Thank you in advance.