Skip to content

Commit

Permalink
Switch to representing propositional constant as Constant.
Browse files Browse the repository at this point in the history
Make the fact format more consistent by representing propositional
constants and constant terms using the same Predicate, same as how
function terms and function atoms use the same Predicate.
  • Loading branch information
namcsi committed Jun 16, 2023
1 parent e1d63e2 commit 9cdad3b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/renopro/asp/tests/reify/prop_fact.lp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

program("base",constant_tuple(0),statement_tuple(1)).
statement_tuple(1,0,rule(2)).
rule(2,literal(3),literal_tuple(6)).
rule(2,literal(3),literal_tuple(5)).
% facts representing head literal a.
literal(3,"pos",function(4)).
function(4,a,term_tuple(5)).
literal(3,"pos",constant(4)).
constant(4,a).
18 changes: 9 additions & 9 deletions src/renopro/asp/tests/reify/prop_normal_rule.lp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

program("base",constant_tuple(0),statement_tuple(1)).
statement_tuple(1,0,rule(2)).
rule(2,literal(3),literal_tuple(6)).
rule(2,literal(3),literal_tuple(5)).
% facts representing head literal a.
literal(3,"pos",function(4)).
function(4,a,term_tuple(5)).
literal(3,"pos",constant(4)).
constant(4,a).
% facts representing body literal b.
literal_tuple(6,0,literal(7)).
literal(7,"pos",function(8)).
function(8,b,term_tuple(9)).
literal_tuple(5,0,literal(6)).
literal(6,"pos",constant(7)).
constant(7,b).
% facts representing body literal not c.
literal_tuple(6,1,literal(10)).
literal(10,"not",function(11)).
function(11,c,term_tuple(12)).
literal_tuple(5,1,literal(8)).
literal(8,"not",constant(9)).
constant(9,c).
5 changes: 4 additions & 1 deletion src/renopro/clorm_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class Binary_Operation(Predicate):

Term.fields.append(Binary_Operation1.Field)

# an atom may be a predicate (Function) or propositional constant (Constant)
Atom = combine_fields([Function1.Field, Constant1.Field], name="Atom")


class Sign(str, enum.Enum):
DoubleNegation = "not not"
Expand All @@ -189,7 +192,7 @@ class Literal(Predicate):
sig = define_enum_field(parent_field=StringField,
enum_class=Sign,
name="SignField")
atom = Function1.Field
atom = Atom


Literal1 = make_id_predicate(Literal)
Expand Down
16 changes: 16 additions & 0 deletions src/renopro/reify.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ def _reify_symbolic_atom(self, node):

@_reify_ast.register(ASTType.Function)
def _reify_function(self, node):
"""Reify an ast node with node.ast_type of ASTType.Function.
Note that clingo's ast also represents propositional constants
as nodes with node.type of ASTType.Function and an empty
node.arguments list; thus some additional care must be taken
to create the correct clorm predicate.
"""
if len(node.arguments) == 0:
constant1 = preds.Constant1()
constant = preds.Constant(
id=constant1.id,
name=node.name
)
self._reified.add(constant)
return constant1
function1 = preds.Function1()
function = preds.Function(
id=function1.id,
Expand Down

0 comments on commit 9cdad3b

Please sign in to comment.