Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Minor changes #634

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def consistent_det(A, E):
# ______________________________________________________________________________


class FOIL_container(FolKB):
class FOILKB(FolKB):
"""Holds the kb and other necessary elements required by FOIL"""

def __init__(self, clauses=[]):
Expand Down
4 changes: 2 additions & 2 deletions logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def prop_symbols(x):
elif is_prop_symbol(x.op):
return {x}
else:
return {symbol for arg in x.args for symbol in prop_symbols(arg)}
return set().union(*map(prop_symbols, x.args))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I prefer the comprehension to the set union with the map pointer, since it is much easier to understand (at least for me).

If both are correct, I would change it to the comprehension (which is simpler and stylistically closer to the way we do things in the repository).

That is unless the union is much, much faster or is the most popular way to deal with the problem.

Copy link
Contributor Author

@Chipe1 Chipe1 Aug 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map method is efficient but I dont think we need to worry about speed as we are using only small expressions. Since it is not directly mentioned in any pseudocode, people could think of it as a simple blackbox function and not really care to look into it. Finally, it's upto @norvig
Maybe we can use both. One in each of the functions :D



def constant_symbols(x):
Expand All @@ -232,7 +232,7 @@ def constant_symbols(x):
elif is_prop_symbol(x.op) and not x.args:
return {x}
else:
return {symbol for arg in x.args for symbol in constant_symbols(arg)}
return set().union(*map(constant_symbols, x.args))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as my above review.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think the comprehension is easier to understand, let's stick with that.



def predicate_symbols(x):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def r_example(Alt, Bar, Fri, Hun, Pat, Price, Rain, Res, Type, Est, GOAL):
vv v
C F
"""
test_network = FOIL_container([expr("Conn(A, B)"),
test_network = FOILKB([expr("Conn(A, B)"),
expr("Conn(A ,D)"),
expr("Conn(B, C)"),
expr("Conn(D, C)"),
Expand All @@ -257,7 +257,7 @@ def r_example(Alt, Bar, Fri, Hun, Pat, Price, Rain, Res, Type, Est, GOAL):
expr("Conn(H, G)"),
expr("Conn(H, I)")])

small_family = FOIL_container([expr("Mother(Anne, Peter)"),
small_family = FOILKB([expr("Mother(Anne, Peter)"),
expr("Mother(Anne, Zara)"),
expr("Mother(Sarah, Beatrice)"),
expr("Mother(Sarah, Eugenie)"),
Expand Down