Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PPP-libmodule-Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
PPP-libmodule-Python
Commits
bb09cb4c
Commit
bb09cb4c
authored
10 years ago
by
Valentin Lorentz
Browse files
Options
Downloads
Patches
Plain Diff
Fix union and intersection simplification.
parent
a9cb3960
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ppp_libmodule/simplification.py
+11
-9
11 additions, 9 deletions
ppp_libmodule/simplification.py
with
11 additions
and
9 deletions
ppp_libmodule/simplification.py
+
11
−
9
View file @
bb09cb4c
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment