New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java: Parse Expressions and Operators returned from the polar core. #1011
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
I've ported over the relevant tests from the python module, I welcome suggestions for more testing though. |
Previous commits to add support for Operators mean that this is now supported in the java library. Fixes: #902
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! To my currently very tired eyes, this looks like a great start. I'm out tomorrow, but I'll make sure that this either (A) gets looked at more closely by someone else tomorrow or (B) is first thing on my plate Thursday morning.
@MFAshby added an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments/suggestions.
public Query query(Predicate query, Map<String, Object> bindings, boolean acceptExpression) | ||
throws Exceptions.OsoException { | ||
Host new_host = host.clone(); | ||
new_host.setAcceptExpression(acceptExpression); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we make setAcceptExpression
a method on the Query object that calls this? And then we don't need the multiple APIs for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately Query gets a result when it is constructed from the core, so this parameter needs to be set on Host before query construction.
This also (roughly) matches the API in other languages, but I agree it's not ideal.
|
||
Predicate rule = new Predicate("f", List.of(x)); | ||
List<HashMap<String, Object>> results = | ||
p.query(rule, Map.of("x", new TypeConstraint(x, "User")), true).results(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this working if ToPolar isn't implemented for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that it's not working, this might be the reason for 2 results instead of 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working now, I added the implementation to the PR. I noticed this test was different though as ported. The python test expects 1 result.
Are there any other tests you changed while porting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to my knowledge. I erroneously thought this should return 2 results for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I think it's just because the python test looks for two arguments in the And expression. I got a bit confused myself reading it.
I checked the other tests & they look good to me!
Predicate rule = new Predicate("f", List.of(x)); | ||
List<HashMap<String, Object>> results = | ||
p.query(rule, Map.of("x", new TypeConstraint(x, "User")), true).results(); | ||
assertEquals(2, results.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only have one result from the rule matching User
, not the rule matching Post
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dhatch ! I didn't know the motivation behind that argument, but it makes sense now.
|
||
Predicate rule = new Predicate("f", List.of(x)); | ||
List<HashMap<String, Object>> results = | ||
p.query(rule, Map.of("x", new TypeConstraint(x, "User")), true).results(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that it's not working, this might be the reason for 2 results instead of 1
The same test in Python is also returning two results, but I would expect it to return one. I'm going to do a little investigation on that. I'll update you tomorrow @MFAshby! |
And add isSubclass event.
@@ -191,6 +226,29 @@ public JSONObject toPolarTerm(Object value) throws Exceptions.OsoException { | |||
"Call", new JSONObject(Map.of("name", pred.name, "args", javaListToPolar(pred.args)))); | |||
} else if (value != null && value instanceof Variable) { | |||
jVal.put("Variable", value); | |||
} else if (value != null && value instanceof Expression) { | |||
Expression expression = (Expression) value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I completely missed transforming in this direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Does the changelog need updating here or in another PR? |
Remove test for throwing assertion when Expression is returned.
Ports tests for partial evaluation from the python code to java.
#1010
PR checklist:
-> I'm not sure of the format yet, so I haven't done this.