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

Error running Smoking Example #60

Open
buddha314 opened this issue Nov 4, 2022 · 1 comment
Open

Error running Smoking Example #60

buddha314 opened this issue Nov 4, 2022 · 1 comment

Comments

@buddha314
Copy link

From the Usage page I have abstracted the following code

from lnn import Predicates
from lnn import Variables
from lnn import Implies, Equivalent
from lnn import World
from lnn import Fact

Smokes, Cancer = Predicates('Smokes', 'Cancer')
Friends = Predicates('Friends', arity=2)

x, y = Variables('x', 'y')

Smoking_causes_Cancer = Implies(Smokes(x), Cancer(x))
Smokers_befriend_Smokers = Implies(Friends(x, y), Equivalent(Smokes(x), Smokes(y)))

formulae = [
    Smoking_causes_Cancer,
    Smokers_befriend_Smokers
]
model.add_knowledge(*formulae, world=World.AXIOM)

# add data to the model
model.add_data({
    Friends: {
        ('Anna', 'Bob'): Fact.TRUE,
        ('Bob', 'Anna'): Fact.TRUE,
        ('Anna', 'Edward'): Fact.TRUE,
        ('Edward', 'Anna'): Fact.TRUE,
        ('Anna', 'Frank'): Fact.TRUE,
        ('Frank', 'Anna'): Fact.TRUE,
        ('Bob', 'Chris'): Fact.TRUE},
    Smokes.name: {
        'Anna': Fact.TRUE,
        'Edward': Fact.TRUE,
        'Frank': Fact.TRUE,
        'Gary': Fact.TRUE},
    Cancer.name: {
        'Anna': Fact.TRUE,
        'Edward': Fact.TRUE}
    })
model.print()

I added a comma in the formulae. When I run this, I get

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [17], line 27
     23 model.add_knowledge(*formulae, world=World.AXIOM)
     26 # add data to the model
---> 27 model.add_data({
     28     Friends: {
     29         ('Anna', 'Bob'): Fact.TRUE,
     30         ('Bob', 'Anna'): Fact.TRUE,
     31         ('Anna', 'Edward'): Fact.TRUE,
     32         ('Edward', 'Anna'): Fact.TRUE,
     33         ('Anna', 'Frank'): Fact.TRUE,
     34         ('Frank', 'Anna'): Fact.TRUE,
     35         ('Bob', 'Chris'): Fact.TRUE},
     36     Smokes.name: {
     37         'Anna': Fact.TRUE,
     38         'Edward': Fact.TRUE,
     39         'Frank': Fact.TRUE,
     40         'Gary': Fact.TRUE},
     41     Cancer.name: {
     42         'Anna': Fact.TRUE,
     43         'Edward': Fact.TRUE}
     44     })
     45 model.print()

File ~/src/pas-notebooks/env/lib64/python3.9/site-packages/lnn/model.py:346, in Model.add_data(self, data)
    344 for formula, fact in data.items():
    345     if not isinstance(formula, Formula):
--> 346         raise TypeError(
    347             "formula expected of type Formula, received "
    348             f"{formula.__class__.__name__}"
    349         )
    350     _exceptions.AssertFormulaInModel(self, formula)
    351     if formula.propositional:

TypeError: formula expected of type Formula, received str
@buddha314
Copy link
Author

I would like to note that the construction syntax seems pretty different than the Jupyter notebooks in the Examples folder.

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