Skip to content

Commit

Permalink
Implement extra() origin() and rel() for accessing pipeline context i…
Browse files Browse the repository at this point in the history
…n action functions
  • Loading branch information
uogbuji committed Apr 19, 2019
1 parent b418706 commit 0480eb8
Showing 1 changed file with 53 additions and 15 deletions.
68 changes: 53 additions & 15 deletions tools/py/pipeline/core_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#FIXME: Use __all__


def link(origin=None, rel=None, value=None, attributes=None, source=None):
def link(origin=None, rel=None, target=None, value=None, attributes=None, source=None):
'''
Action function generator to create a link based on the context's current link, or on provided parameters
Expand All @@ -24,8 +24,10 @@ def link(origin=None, rel=None, value=None, attributes=None, source=None):
:param rel: IRI/string, or list of same; IDs for the created relationships.
If None, the action context provides the parameter.
:param value: IRI/string, or list of same; values/targets for the created relationships.
:param target: IRI/string, or list of same; values/targets for the created relationships.
If None, the action context provides the parameter.
:param value: Deprecated synonym for target
:param source: pattern action to be executed, generating contexts to determine the output statements. If given, overrides specific origin, rel or value params
Expand Down Expand Up @@ -64,37 +66,77 @@ def _link(ctx):
return _link


def links(origin, rel, target, attributes=None):
'''
'''
raise NotImplementedError('You can just use link() for this now.')


def var(name):
'''
Action function generator to retrieve a variable from context
'''
def _var(ctx):
return ctx.variables.get(name)
_name = name(ctx) if callable(name) else name
return ctx.variables.get(_name)
return _var


def extra(key, default=None):
'''
Action function generator to retrieve an extra value from context
'''
def _extra(ctx):
_key = key(ctx) if callable(key) else key
_default = default(ctx) if callable(default) else default
return ctx.extras.get(_key, _default)
return _extra


def attr(aid):
'''
Action function generator to retrieve an attribute from the current link
'''
def _attr(ctx):
return ctx.current_link[ATTRIBUTES].get(aid)
_aid = aid(ctx) if callable(aid) else aid
return ctx.current_link[ATTRIBUTES].get(_aid)
return _attr


def origin():
'''
Action function generator to return the origin of the context's current link
:return: origin of the context's current link
'''
def _origin(ctx):
'''
Versa action function Utility to return the origin of the context's current link
:param ctx: Versa context used in processing (e.g. includes the prototype link
:return: origin of the context's current link
'''
return ctx.current_link[ORIGIN]
return _origin


def rel():
'''
Action function generator to return the relationship of the context's current link
:return: origin of the context's current link
'''
def _rel(ctx):
'''
Versa action function Utility to return the relationship of the context's current link
:param ctx: Versa context used in processing (e.g. includes the prototype link
:return: relationship of the context's current link
'''
return ctx.current_link[RELATIONSHIP]
return _rel


def target():
'''
Action function generator to return the target of the context's current link
:return: target of the context's current link
'''
#Action function generator to multiplex a relationship at processing time
def _target(ctx):
'''
Versa action function Utility to return the target of the context's current link
Expand Down Expand Up @@ -374,10 +416,6 @@ def follow(self, rel):
return simple_lookup(self._input_model, self._origin, I(iri.absolutize(rel, self._base)))


def origin(ctx):
return resource(ctx.current_link[ORIGIN], ctx.input_model)


def run(pycmds):
def _run(ctx):
gdict = {
Expand Down

0 comments on commit 0480eb8

Please sign in to comment.