Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import name 'ForAll' from 'lnn' #83

Open
daisylab opened this issue Mar 5, 2023 · 1 comment
Open

Cannot import name 'ForAll' from 'lnn' #83

daisylab opened this issue Mar 5, 2023 · 1 comment

Comments

@daisylab
Copy link

daisylab commented Mar 5, 2023

Hi, I'm currently studying the LNN, and trying to evaluate the example code.

However, I've got this error from the example code:

  1. example code:

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

  1. where I stuck:
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.11.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from lnn import (Predicate, Variable,
   ...:                  Exists, Implies, ForAll, Model, Fact, World)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from lnn import (Predicate, Variable,
      2                  Exists, Implies, ForAll, Model, Fact, World)

ImportError: cannot import name 'ForAll' from 'lnn' (/home/sungjin/.virtualenvs/lnn/lib/python3.10/site-packages/lnn/__init__.py)

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.

@daisylab
Copy link
Author

daisylab commented Mar 5, 2023

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant