AI-Planning / pddl

Unquestionable PDDL 3.1 parser
https://ai-planning.github.io/pddl/
MIT License
85 stars 27 forks source link

Parse single file with domain + problem #108

Closed ssardina closed 8 months ago

ssardina commented 8 months ago

Is your feature request related to a problem? Please describe.

We can now parse domain files, and problem files. But what if a file contain boths?

Describe the solution you'd like

At minimum a DomProb object that can capture files with domain + problem specs

Describe alternatives you've considered

I thought having this grammar that builds on top of domain + problem would work:

image

but it doesn't, and all the other symbols from domain say get the name domain__X, so I had to add one by one:

%import domain.X -> X

and also for problem, but then they start clashing as some terms are duplicated in both!

My whole implementation take can be seen in this branch (in a fork of pddl):

https://github.com/ssardina-research/pddl/tree/domprob

I mirrored how domain and problems were done to keep the same style. Then I did:

$ python -m pddl domprob  tests/fixtures/pddl_files/blocksworld_fond/domain_problem.pddl 

raceback (most recent call last):
  File "/home/ssardina/.local/lib/python3.10/site-packages/lark/visitors.py", line 124, in _call_userfunc
    return f(children)
  File "/home/ssardina/git/planning/parsers/pddl.git/pddl/parser/domain.py", line 349, in atomic_formula_skeleton
    variables = self._formula_skeleton(args)
  File "/home/ssardina/git/planning/parsers/pddl.git/pddl/parser/domain.py", line 343, in _formula_skeleton
    variables = [Variable(var_name, tags) for var_name, tags in variable_data]
TypeError: 'Tree' object is not iterable

So, the question is we could combine the existing grammar for domain with the existing grammar from problem to get a structure object/class DomProb that has both?

I know this is probably more about Lark than pddl, but I couldn't find ANY example of Lark that combines two grammar "in sequence". Do you know how? Thanks for any tips, I feel this should be easy/trivial and I am not getting how Lark works well. :-)

ssardina commented 8 months ago

OK I found out finally how to make this happen in a "clean" manner. Basically we need to merge the transformers for domain and problem, and Lark provides the merging mechanism. Also the lalr grammar won´t work, it will give error if only a problem is given; I think it's because the 1 lookahead is not enough to know which rule to use. So I used earley:

image

This domprob branch in the fork has the full solution. @marcofavorito , do you think it is worth allowing pddl to read files that can contain any combination of domain problem (domain alone, problem alone, domain and problem) and return a tuple [Domain, Problem] (with None when it corresponds).