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
6a136034
Commit
6a136034
authored
10 years ago
by
Valentin Lorentz
Browse files
Options
Downloads
Patches
Plain Diff
Implement union simplification.
parent
f60d407d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ppp_libmodule/simplification.py
+36
-0
36 additions, 0 deletions
ppp_libmodule/simplification.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
tests/test_simplification.py
+26
-0
26 additions, 0 deletions
tests/test_simplification.py
with
63 additions
and
1 deletion
ppp_libmodule/simplification.py
0 → 100644
+
36
−
0
View file @
6a136034
import
itertools
from
ppp_datamodel.nodes
import
Resource
from
ppp_datamodel.nodes.list_operators
import
*
__all__
=
[
'
simplify
'
]
def
simplify_union
(
tree
):
if
len
(
tree
.
list
)
==
0
:
return
List
([])
elif
len
(
tree
.
list
)
==
1
:
return
tree
.
list
[
0
]
list_
=
[
x
for
x
in
tree
.
list
if
x
]
lists
=
(
x
.
list
for
x
in
list_
if
isinstance
(
x
,
List
))
not_lists
=
[
x
for
x
in
list_
if
not
isinstance
(
x
,
List
)]
lists
=
list
(
set
(
itertools
.
chain
(
*
lists
)))
if
not_lists
:
all_
=
not_lists
all_
.
append
(
List
(
lists
))
return
Union
(
all_
)
else
:
return
List
(
lists
)
predicates
=
{
Union
:
simplify_union
}
def
predicate
(
tree
):
for
(
cls
,
f
)
in
predicates
.
items
():
if
isinstance
(
tree
,
cls
):
return
f
(
tree
)
return
tree
def
simplify
(
tree
):
return
tree
.
traverse
(
predicate
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
6a136034
...
...
@@ -24,7 +24,7 @@ setup(
'
Topic :: Software Development :: Libraries
'
,
],
install_requires
=
[
'
ppp_datamodel>=0.5.2,<0.6
'
,
'
ppp_datamodel>=0.5.2
2
,<0.6
'
,
],
packages
=
[
'
ppp_libmodule
'
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_simplification.py
0 → 100644
+
26
−
0
View file @
6a136034
import
unittest
from
ppp_datamodel.nodes
import
Triple
as
T
from
ppp_datamodel.nodes
import
Missing
as
M
from
ppp_datamodel.nodes
import
Resource
as
R
from
ppp_datamodel.nodes.list_operators
import
*
from
ppp_libmodule.simplification
import
simplify
class
SimplificationTestCase
(
unittest
.
TestCase
):
def
testUnionTrivial
(
self
):
self
.
assertEqual
(
simplify
(
Union
([])),
List
([]))
self
.
assertEqual
(
simplify
(
Union
([
List
([
R
(
'
a
'
)])])),
List
([
R
(
'
a
'
)]))
def
testUnionResourceLists
(
self
):
t
=
Union
([
List
([
R
(
'
a
'
),
R
(
'
b
'
)]),
List
([
R
(
'
c
'
)])])
t
=
simplify
(
t
)
self
.
assertIsInstance
(
t
,
List
)
self
.
assertEqual
(
set
(
t
.
list
),
{
R
(
'
a
'
),
R
(
'
b
'
),
R
(
'
c
'
)})
def
testUnionMixed
(
self
):
t
=
Union
([
List
([
R
(
'
a
'
),
R
(
'
b
'
)]),
T
(
M
(),
M
(),
M
())])
t
=
simplify
(
t
)
self
.
assertIsInstance
(
t
,
Union
)
self
.
assertEqual
(
t
.
list
[
0
],
T
(
M
(),
M
(),
M
()))
self
.
assertIsInstance
(
t
.
list
[
1
],
List
)
self
.
assertEqual
(
set
(
t
.
list
[
1
].
list
),
{
R
(
'
a
'
),
R
(
'
b
'
)})
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