Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow input and output of nested entities (CMEM-4492) #4

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/)

## [Unreleased]

### Added

- capabilities for hierarchical entities as input and output of workflow tasks


## [4.3.0] 2023-10-20

### Added
Expand Down
21 changes: 17 additions & 4 deletions cmem_plugin_base/dataintegration/entity.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
"""Instance of any given concept."""
from typing import Sequence, Iterator
from typing import Sequence, Iterator, Optional


class EntityPath:
"""A path in a schema.

:param path: The path string using the Silk path language.
:param is_uri: If true, values for this path must only contain URIs that point to
a sub entity.
"""

def __init__(self, path: str) -> None:
def __init__(self, path: str, is_uri: bool = False) -> None:
self.path = path
self.is_uri = is_uri


class EntitySchema:
"""An entity schema.

:param type_uri: The entity type
:param paths: Ordered list of paths
:param sub_path: Path starting from the root for enumerating the entities.
"""

def __init__(self, type_uri: str, paths: Sequence[EntityPath]) -> None:
def __init__(self,
type_uri: str,
paths: Sequence[EntityPath],
sub_path: EntityPath = EntityPath("")) -> None:
self.type_uri = type_uri
self.paths = paths
self.sub_path = sub_path


class Entity:
Expand All @@ -45,8 +53,13 @@ class Entities:
:param entities: An iterable collection of entities. May be very large, so it
should be iterated over and not loaded into memory at once.
:param schema: All entities conform to this entity schema.
:param sub_entities Additional entity collections.
"""

def __init__(self, entities: Iterator[Entity], schema: EntitySchema) -> None:
def __init__(self,
entities: Iterator[Entity],
schema: EntitySchema,
sub_entities: Optional[Sequence['Entities']] = None) -> None:
self.entities = entities
self.schema = schema
self.sub_entities = sub_entities
Loading