Skip to content
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

New primitive SemanticFn: Filter #125

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

New primitive SemanticFn: Filter #125

wants to merge 8 commits into from

Conversation

ppasupat
Copy link
Collaborator

"Find all cities with more teachers than farmers"

This is a highly requested semantic function. One way to answer the question above in the original set of semantic function is

(mark x (and (type city) (: (and (!num_teachers (var x)) (> (!num_farmers (var x)))))))

where the special relation : returns an empty set when the argument is empty, and * otherwise. The relation : has not been implemented.

The proposed semantic function looks like this:

(filter (type city) (lambda x (and (!num_teachers (var x)) (> (!num_farmers (var x))))))

While it is equally long, I think it is a little clearer about what it does. (filter S F) is equivalent to {x in S : F(x) not empty}. Filter is also easier to execute than the generic mark since filter is similar to superlatives (i.e., try plugging each value in S into the function F and see what works).

Please refer to tables/grammars/combined.grammar of how it could be used in the grammar.

Copy link
Owner

@percyliang percyliang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me.

The only thing I'd perhaps think about a bit more is what formulas do we actually need in the long term. It's very easy to just start adding different types of formulas, but this could get out of control.

Actually, what do you think about making Filter be a different mode inside SuperlativeFormula? The type is the same. In the future, if we support map, then we could add it there too.

Do we need to add something to SparqlExecutor (at least to say that it's not supported)?

Adding a unittest would be nice, and something to the README.

import java.util.List;

/**
* (filter x y): Find the set of all elements in x that function y evaluates to a non-empty set.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give an example...in particular, so that people know the directionality of y (which should be consistent with SuperlativeFormula).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants