Skip to content

Commit

Permalink
added option to not fix inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dyumanaditya committed Mar 9, 2023
1 parent b93a8ec commit 9473e7e
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 36 deletions.
2 changes: 0 additions & 2 deletions docs/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ edge_labels:

# Labels that apply to specific nodes. In this case nothing
node_specific_labels:
special_node_label: []

# Labels that apply to specific edges. In this case nothing
edge_specific_labels:
special_edge_label: []
```
Each node will receive a `popular` label, and each edge will get a `owns` and `friends` label. The bounds for each of these are set to `[0, 1]` initially.
Expand Down
4 changes: 2 additions & 2 deletions pyreason/examples/example_yamls/labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ edge_labels:

# Labels that apply to specific nodes
node_specific_labels:
special_node_label: []
- special_node_label: []
# special_node_label: [n2825]

# Labels that apply to specific edges
edge_specific_labels:
special_edge_label: []
- special_edge_label: []
# special_edge_label: [[n2625, n2825], [n2989, n2825]]
2 changes: 0 additions & 2 deletions pyreason/examples/hello-world/labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ edge_labels:

# Labels that apply to specific nodes. In this case nothing
node_specific_labels:
special_node_label: []

# Labels that apply to specific edges. In this case nothing
edge_specific_labels:
special_edge_label: []
36 changes: 33 additions & 3 deletions pyreason/pyreason.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self):
self.__atom_trace = False
self.__save_graph_attributes_to_trace = False
self.__canonical = False
self.__inconsistency_check = True

@property
def verbose(self) -> bool:
Expand Down Expand Up @@ -114,6 +115,14 @@ def canonical(self) -> bool:
:return: bool
"""
return self.__canonical

@property
def inconsistency_check(self) -> bool:
"""Returns whether to check for inconsistencies in the interpretation or not
:return: bool
"""
return self.__inconsistency_check

@verbose.setter
def verbose(self, value: bool) -> None:
Expand Down Expand Up @@ -238,6 +247,18 @@ def canonical(self, value: bool) -> None:
raise TypeError('value has to be a bool')
else:
self.__canonical = value

@inconsistency_check.setter
def inconsistency_check(self, value: bool) -> None:
"""Whether to check for inconsistencies in the interpretation or not
:param value: Whether to check for inconsistencies or not
:raises TypeError: If not bool raise error
"""
if not isinstance(value, bool):
raise TypeError('value has to be a bool')
else:
self.__inconsistency_check = value

# VARIABLES
__graph = None
Expand Down Expand Up @@ -377,13 +398,22 @@ def _reason(timesteps, convergence_threshold, convergence_bound_threshold):


# If graph attribute parsing, add results to existing specific labels and facts
__specific_node_labels.update(__specific_graph_node_labels)
__specific_edge_labels.update(__specific_graph_edge_labels)
for label_name, nodes in __specific_graph_node_labels.items():
if label_name in __specific_node_labels:
__specific_node_labels[label_name].extend(nodes)
else:
__specific_node_labels[label_name] = nodes

for label_name, edges in __specific_graph_edge_labels.items():
if label_name in __specific_edge_labels:
__specific_edge_labels[label_name].extend(edges)
else:
__specific_edge_labels[label_name] = edges
__node_facts.extend(__non_fluent_graph_facts_node)
__edge_facts.extend(__non_fluent_graph_facts_edge)

# Setup logical program
program = Program(__graph, timesteps, __node_facts, __edge_facts, __rules, __ipl, settings.reverse_digraph, settings.atom_trace, settings.save_graph_attributes_to_trace, settings.canonical)
program = Program(__graph, timesteps, __node_facts, __edge_facts, __rules, __ipl, settings.reverse_digraph, settings.atom_trace, settings.save_graph_attributes_to_trace, settings.canonical, settings.inconsistency_check)
program.available_labels_node = __node_labels
program.available_labels_edge = __edge_labels
program.specific_node_labels = __specific_node_labels
Expand Down
5 changes: 5 additions & 0 deletions pyreason/scripts/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def argparser():
parser.add_argument("--no-graph_attribute_parsing", dest='graph_attribute_parsing', action='store_false', help='Option to not make non fluent facts based on the attributes of the graph.')
parser.add_argument("--graph_attribute_parsing", dest='graph_attribute_parsing', action='store_true', help='Option to make non fluent facts based on the attributes of the graph. On by default')
parser.set_defaults(graph_attribute_parsing=True)
# Check for inconsistencies
parser.add_argument("--no-inconsistency_check", dest='inconsistency_check', action='store_false', help='Option to not check for any inconsistencies in the interpretation.')
parser.add_argument("--inconsistency_check", dest='inconsistency_check', action='store_true', help='Option to check for inconsistencies in the interpretation. On by default')
parser.set_defaults(inconsistency_check=True)

# Interpretation inconsistency check (not done)
parser.add_argument("--abort_on_inconsistency", dest='abort_on_inconsistency', action='store_true', help='Stop the program if there are inconsistencies, do not fix them automatically')
parser.set_defaults(abort_on_inconsistency=False)
Expand Down
13 changes: 12 additions & 1 deletion pyreason/scripts/diffuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def main(args):
if args.graph_attribute_parsing:
specific_node_labels.update(snl)
specific_edge_labels.update(sel)
for label_name, nodes in specific_node_labels.items():
if label_name in snl:
snl[label_name].extend(nodes)
else:
snl[label_name] = nodes

for label_name, edges in specific_edge_labels.items():
if label_name in sel:
sel[label_name].extend(edges)
else:
sel[label_name] = edges
else:
specific_node_labels = snl
specific_edge_labels = sel
Expand All @@ -60,7 +71,7 @@ def main(args):
ipl = yaml_parser.parse_ipl(args.ipl_yaml_path)

# Program comes here
program = Program(graph, tmax, facts_node, facts_edge, rules, ipl, args.reverse_digraph, args.atom_trace, args.save_graph_attributes_to_trace, args.canonical)
program = Program(graph, tmax, facts_node, facts_edge, rules, ipl, args.reverse_digraph, args.atom_trace, args.save_graph_attributes_to_trace, args.canonical, args.inconsistency_check)
program.available_labels_node = node_labels
program.available_labels_edge = edge_labels
program.specific_node_labels = specific_node_labels
Expand Down
Loading

0 comments on commit 9473e7e

Please sign in to comment.