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

Added functionality for more than one parent in new_entity #295

Merged
Merged
Changes from 2 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
13 changes: 9 additions & 4 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import uuid
import tempfile
import types
from typing import Union, List
from collections import defaultdict

import rdflib
Expand Down Expand Up @@ -1210,10 +1211,12 @@ def get_wu_palmer_measure(self, cls1, cls2):
generations2 = self.number_of_generations(cls2, cca)
return 2 * ccadepth / (generations1 + generations2 + 2 * ccadepth)

def new_entity(self, name: str, parent: ThingClass) -> ThingClass:
def new_entity(
self, name: str, parent: Union[ThingClass, List[ThingClass]]
) -> ThingClass:
"""Create and return new entity

Makes a new entity in the ontology with given parent.
Makes a new entity in the ontology with given parent(s).
Return the new entity.

Throws exception if name consists of more than one word.
Expand All @@ -1223,6 +1226,8 @@ def new_entity(self, name: str, parent: ThingClass) -> ThingClass:
f"Error in label name definition {name}: "
"Label consists of more than one word."
)
with self:
entity = types.new_class(name, (parent,))
parent = parent if isinstance(parent, list) else [parent]
francescalb marked this conversation as resolved.
Show resolved Hide resolved
for thing in parent:
with self:
entity = types.new_class(name, (thing,))
francescalb marked this conversation as resolved.
Show resolved Hide resolved
return entity