Skip to content
Snippets Groups Projects
Commit bb09cb4c authored by Valentin Lorentz's avatar Valentin Lorentz
Browse files

Fix union and intersection simplification.

parent a9cb3960
No related branches found
No related tags found
No related merge requests found
......@@ -27,12 +27,12 @@ def simplify_union(tree):
lists = list(set(itertools.chain(*lists)))
non_lists = list(non_lists)
if non_lists: # If there are non-lists (eg. triples)
if lists:
all_ = non_lists
all_.append(List(lists))
return Union(all_)
else: # If there are only lists
return List(lists)
else:
return List(non_lists)
def simplify_intersection(tree):
# Trivial cases
......@@ -41,18 +41,20 @@ def simplify_intersection(tree):
elif len(tree.list) == 1:
return tree.list[0]
(lists, non_lists) = partition(lambda x:isinstance(x, List), tree.list)
(a, b) = partition(lambda x:isinstance(x, (List, Resource)), tree.list)
(lists, non_lists) = partition(lambda x:isinstance(x, (List, Resource)),
tree.list)
# Make intersection of lists
lists = list(map(set, map(operator.attrgetter('list'), lists))) or [set()]
lists = [set(x.list) if isinstance(x, List) else {x} for x in lists] or [set()]
lists = list(lists[0].intersection(*lists[1:]))
non_lists = list(non_lists)
if non_lists: # If there are non-lists (eg. triples)
if lists:
all_ = non_lists
all_.append(List(lists))
all_.append(simplify_list(List(lists)))
return Intersection(all_)
else: # If there are only lists
return List(lists)
else:
return List(non_lists)
def simplify_list(tree):
if len(tree.list) == 1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment