Open daisylab opened 1 year ago
Oh, I figured it out why it does not work. ForAll
is changed to Forall
, the 'a' in the name is no longer capital.
In [1]: from lnn import ForAll
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from lnn import ForAll
ImportError: cannot import name 'ForAll' from 'lnn' (/home/sungjin/.virtualenvs/lnn/lib/python3.10/site-packages/lnn/__init__.py)
In [2]: from lnn import Forall
In [3]:
however, I got another error, that is,
from lnn import (Predicate, Variable,
Exists, Implies, Forall, Model, Fact, World)
model = Model()
# Variable
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)
print(model[query].true_groundings)
which is expected to emit the result:
{'c', 'k'}
but it just says:
(lnn) sungjin@daisylab:~/home/lnn-examples> python simple.py
set()
Hi, I'm currently studying the LNN, and trying to evaluate the example code.
However, I've got this error from the example code:
https://ibm.github.io/LNN/education/examples/reasoning.html#simple-geometry-reasoning-example
I know that LNN is a great tool which will leverage the next step of AI, and I glad to know about it. And I hope there will be a chance to the newcomers like me. Thank you.