Skip to content

Commit

Permalink
Allow input and output of nested entities (CMEM-4492) (#4)
Browse files Browse the repository at this point in the history
* Allow input and output of nested entities.

* Add is_uri property to EntityPath

* change log

* fix safety issue

---------

Co-authored-by: Sebastian Tramp <[email protected]>
  • Loading branch information
robertisele and seebi authored Nov 24, 2023
1 parent 1ebe669 commit eafe271
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 257 deletions.
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

0 comments on commit eafe271

Please sign in to comment.