Merge branch 'FT_random' of git_opytex:/lafrite/Mapytex into FT_random

This commit is contained in:
Bertrand Benjamin 2019-05-16 19:42:52 +02:00
commit 91efea28cd
3 changed files with 31 additions and 6 deletions

View File

@ -97,7 +97,7 @@ class Expression(object):
:example: :example:
>>> Expression.random("{a}/{a*k}") # doctest: +SKIP >>> Expression.random("{a}/{a*k}") # doctest: +SKIP
<Exp: -3 / -15> <Exp: -3 / -15>
>>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest +SKIP >>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest: +SKIP
<Exp: 18 / 108 - 3 * 9> <Exp: 18 / 108 - 3 * 9>
""" """

View File

@ -7,7 +7,7 @@
# Distributed under terms of the MIT license. # Distributed under terms of the MIT license.
""" """
Tools to extract random nodes, random variables, generate random values and Tools to extract random leafs, random variables, generate random values and
fill new trees fill new trees
Flow Flow
@ -15,9 +15,9 @@ Flow
Tree with RdLeaf Tree with RdLeaf
| |
| Extract nodes | Extract rdLeaf
| |
List of nodes to generate List of leafs to generate
| |
| extract_rv | extract_rv
| |
@ -27,9 +27,9 @@ List random variables to generate
| |
Dictionnary of generated random variables Dictionnary of generated random variables
| |
| Compute nodes | Compute leafs
| |
Dictionnary of computed nodes Dictionnary of computed leafs
| |
| Replace | Replace
| |

View File

@ -836,6 +836,31 @@ def rdstr2(sink):
return pipeline return pipeline
def rdstr2(sink):
""" Return a pipeline which parse random expression and with sink as endpoint
:example:
>>> rdstr2list = rdstr2(list_sink)
>>> rdstr2list("{a}+{a*b}-2")
[<RdLeaf a>, '+', <RdLeaf a*b>, '+', <MOnumber - 2>]
"""
lfop = lookfor(is_operator)
operator_corout = partial(concurent_broadcast, lookfors=[lfop])
def pipeline(expression):
str2_corout = look_for_rdleaf(
lookforNumbers(operator_corout(missing_times(moify_cor(pparser(sink)))))
)
for i in expression.replace(" ", ""):
str2_corout.send(i)
a = str2_corout.throw(STOOOP)
return a
return pipeline
str2nestedlist = str2(list_sink) str2nestedlist = str2(list_sink)