Closed ejgroene closed 5 months ago
I just noticed that I simplified the use case in the attachment too much so it doesn't show the problem anymore. I prepare a new one.
The different ways to achieve what you want.
Thank you!
I tried all the options for preserving atoms/symbols, but it did not make any difference. I also found that for conditional literals, the grounder passes a rule with a head for which no symbol exists. Some sort of anonymous rule that I now duly use for substitution, and that seems to make the problem go away.
Regarding the SymbolicAtoms, I see that I don't have to maintain the symbols myself, so that comes in handy. Is that actually being the point of SymbolicAtoms? Just to have symbols bound to atom numbers? Or is there more to it?
Erik
The symbol table is something stored by the system and the API provides access to it. You can inspect what information the system has about an atom. For example, whether an atom is a fact or external or its numeric id.
Note that conditional literals are not the only place where the system introduces program atoms that are not associated with symbols. Aggregates, minimize directives, and also show statements can lead to unnamed program atoms.
Thank you Roland, this really helped me. This particular problem is gone now.
L.S.
I want to translate the ground form of ASP to boolean logic for an PLC system.
For that, I need to lookup the symbols associated with facts using the atoms (numbers) passed to
rule()
.However, the Python API does not give me those:
The
Observer
added to theControl
in Python gets called withoutput_atom(symbol, atom)
, but for facts theatom
is always zero.The
rule(choice, head, body)
method gets called and the head contains an atom (number) that refers to a symbol. However, this symbol is unknown to the Python application because of 1.No other methods are called on the Observer (as I made sure by a catchall deliberatly raising an exception).
Neither the Control nor the default Backend seem to have Symbols for facts.
My current solution is to trace the atoms of the facts by having two separate lists for them (complete code attached as .txt):
In
rule()
I add the symbols:In
output_atom()
I add the atoms:And then I make the symbol table complete by zipping the symbols and the atoms:
This works well, up till now, also with externals, which seem to influence the numbering in such a way that a simple counter to track the atoms does not work anymore.
Why is the API not giving the atoms used for facts? Is the approach above solid or can it break at any time? Is there a better way to get the atoms for facts?
Thank you in advance! Erik