Skip to content

Documentation error: model.add_data() example uses .name and raises TypeError #115

@tronmon

Description

@tronmon

In the Python API documentation under "Tables of Data", the example for model.add_data() uses:

Smokes.name: {
Cancer.name: {

However, running this code raises:

TypeError: formula expected of type Formula, received str

It appears that .name returns a string, while model.add_data() expects a Formula object as the dictionary key.

Replacing:

Smokes.name
Cancer.name

Code Snippet:

from lnn import Fact

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

with:

Smokes
Cancer

Code Snippet:
from lnn import Fact

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 : {
'Anna': Fact.TRUE,
'Edward': Fact.TRUE,
'Frank': Fact.TRUE,
'Gary': Fact.TRUE},
Cancer : {
'Anna': Fact.TRUE,
'Edward': Fact.TRUE}
})
model.print()

resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions