LNN icon indicating copy to clipboard operation
LNN copied to clipboard

Errors on educational example.

Open daisylab opened this issue 1 year ago • 4 comments

While trying to replicate the result from the educational examples, I've got this error.

  1. url:

https://ibm.github.io/LNN/education/examples/reasoning.html#simple-geometry-reasoning-example

  1. code:
from lnn import (Predicate, Variable,
                 Exists, Implies, Forall, Model, Fact, World)

model = Model()

# Variablle
x = Variable('x')

# Predicate declarations
square = Predicate('square')
rectangle = Predicate('rectangle')
foursides = Predicate('foursides')

# Axioms declarations
square_rect = Forall(x, Implies(square(x), rectangle(x)))
rect_foursides = Forall(x, Implies(rectangle(x), foursides(x)))

# Query
query = Exists(x, foursides(x))

# Add predicates and rules to the model
model.add_knowledge(square, rectangle, square_rect, rect_foursides, query)

# Add facts to the model
model.add_data({square: {'c': Fact.TRUE, 'k': Fact.TRUE}})

# Perform inference
steps, facts_inferred = model.infer()

# Inspect the query node
print(model['foursided_objects'].true_groundings)
  1. result:
Traceback (most recent call last):
  File "/home/sungjin/home/lnn-examples/simple.py", line 33, in <module>
    print(model['foursided_objects'].true_groundings)
  File "/home/sungjin/.virtualenvs/lnn/lib/python3.10/site-packages/lnn/model.py", line 133, in __getitem__
    if formula.formula_number is not None and formula.formula_number in self.nodes:
AttributeError: 'str' object has no attribute 'formula_number'
  1. how did I do to patch the error:
# Inspect the query node
# print(model['foursided_objects'].true_groundings)
print(model[query].true_groundings)

daisylab avatar Mar 03 '23 14:03 daisylab