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

Introduce a way to tag Rules, Predicates, Atoms and Terms #285

Open
jblaszczyk opened this issue Mar 26, 2021 · 2 comments
Open

Introduce a way to tag Rules, Predicates, Atoms and Terms #285

jblaszczyk opened this issue Mar 26, 2021 · 2 comments

Comments

@jblaszczyk
Copy link

Elements of core language often represent concepts from application domain or another languages, yet there's no easy way to map them back. For example, after translation from Argumentation Frameworks to Alpha I have to maintain clumsy mappings from Alpha's atoms back to domain objects. Synthetic predicates also need mapping especially for 1-to-many translations to recover meaning of answer set elements. Ideally, I would attach arbitrary object or hash map.

Note that this is not the same functionality as provided by ConstantTerm.getObject() which references representation e.g. a string from textual file after parsing. I need to resolve that string into some domain object and have the constant still refer both.

Rules, Predicates, Atoms and Terms could implement sth like:

interface Taggable {
  public void setTag(Object tag);
  public Object getTag();
}
@lorenzleutgeb
Copy link
Member

Thanks for filing this issue!

Could you please share more code, just so that I can understand the problem better? Ideally your "real" code base or, if that's not possible, an example.

I am asking for this, in order to understand why objects wrapped in ConstantTerms are not suitable. Not only strings but arbitrary domain objects can be wrapped.

Also note that #274 will likely improve Alpha's API.

@madmike200590
Copy link
Collaborator

@jblaszczyk from your description I'm assuming you were thinking of some "hibernate-esque" way of automatic mapping such as tagging classes with an annotation like @Entity and having the actual atom <-> object conversion done automagically using reflection or some such.
e.g.:

// Java
@Predicate(name="mapped_thing")
class MappedThing {
    @Argument(1)
    private String property1;
    @Argument(2)
    private String property2;
}

%% ASP
mapped_thing("prop1_value", "prop2_value").

I've thought about this a bit because I'd also like to get rid of those repetitive manual approaches, but I could see something as outlined above become complicated and intransparent pretty fast.

I introduced the interface AnswerSetToObjectMapper a while back as a first baby-step towards standardizing these kinds of mappings. Right now there are no generic implementations (and unfortunately nothing for the "Object -> Set of Facts" direction), but you might be able to do an implementation using for example Dozer that can handle simple objects relatively easily.

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

No branches or pull requests

3 participants