Skip to content

Commit 4ee784c

Browse files
committed
review add_formal_parameter
1 parent c010953 commit 4ee784c

File tree

1 file changed

+38
-44
lines changed

1 file changed

+38
-44
lines changed

rocrate/rocrate.py

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# limitations under the License.
2121

2222
import errno
23-
from typing import Literal, Optional
2423
import uuid
2524
import zipfile
2625
import atexit
@@ -629,52 +628,47 @@ def add_action(self, instrument, identifier=None, object=None, result=None, prop
629628
self.root_dataset.append_to("mentions", action)
630629
return action
631630

632-
def add_formal_parameter(self,
633-
name: str,
634-
additionalType: Literal["Text", "Boolean", "Integer", "File", "Dataset"],
635-
identifier: Optional[str] = None,
636-
description: Optional[str] = None,
637-
valueRequired=False,
638-
defaultValue=None) -> ContextEntity:
639-
"""
640-
Create a FormalParameter to describe an input or output of a workflow.
641-
642-
A FormalParameter describes the data-type of an input or output, not its value.
643-
The value a parameter takes for a run of the workflow is documented by a separate Data entity,
644-
referring to the associated FormalParameter via the `exampleOfWork` attribute.
645-
646-
additionalType
647-
--------------
648-
The type of the parameter. It should be typically one of the following (although it is not enforced):
649-
- Text (for strings)
650-
- Boolean
651-
- Integer
652-
- File
653-
- Dataset (for directories)
654-
655-
656-
returns
657-
-------
658-
The created FormalParameter entity.
659-
It can be associated to a workflow e.g as an input using the syntax
660-
>>> workflow_entity.append_to("input", formal_parameter_entity)
661-
"""
662-
properties = {"@type": "FormalParameter",
663-
"additionalType": additionalType,
664-
"valueRequired": valueRequired,
665-
"conformsTo": {"@id": "https://bioschemas.org/profiles/FormalParameter/1.0-RELEASE"},
666-
"name": name
667-
}
631+
def add_formal_parameter(
632+
self,
633+
additionalType,
634+
identifier=None,
635+
name=None,
636+
description=None,
637+
valueRequired=False,
638+
defaultValue=None,
639+
properties=None
640+
):
641+
"""\
642+
Add a FormalParameter to describe an input or output of a workflow.
668643
669-
if description:
670-
properties["description"] = description
644+
A FormalParameter represents an input or output slot of a workflow, not
645+
the actual value taken by a parameter. For further information see
646+
https://w3id.org/ro/wfrun/workflow
671647
648+
Returns the created FormalParameter entity, which can be associated to
649+
a workflow (e.g. as an input) using the syntax:
650+
workflow_entity.append_to("input", formal_parameter_entity)
651+
"""
652+
if properties is None:
653+
properties = {}
654+
props = {
655+
"@type": "FormalParameter",
656+
"additionalType": additionalType,
657+
"valueRequired": valueRequired,
658+
"conformsTo": {
659+
"@id": "https://bioschemas.org/profiles/FormalParameter/1.0-RELEASE"
660+
}
661+
}
662+
if name:
663+
props["name"] = name
664+
if description:
665+
props["description"] = description
672666
if defaultValue:
673-
properties["defaultValue"] = defaultValue
674-
675-
return self.add(ContextEntity(self,
676-
identifier=identifier,
677-
properties=properties))
667+
props["defaultValue"] = defaultValue
668+
props.update(properties)
669+
return self.add(
670+
ContextEntity(self, identifier=identifier, properties=props)
671+
)
678672

679673
def add_jsonld(self, jsonld):
680674
"""Add a JSON-LD dictionary as a contextual entity to the RO-Crate.

0 commit comments

Comments
 (0)