Extracting Superclassifiers

Hello!

Is there an elegant way of recursively extracting all superclassifiers of an element in the model? For example: Extract all animals, mammels, cats, dogs from the following example model:

abstract part def Animal;
abstract part def Mammal :> Animal;
abstract part def Bird :> Animal;
abstract part def Cat :> Mammel;
abstract part def Dog :> Mammel;

part def PersianCat :> Cat;
part def BritishShorthair :> Cat;
part def GermanShepherd :> Dog;
part def GoldenRetriever :> Dog;

My script currently only extracts the next associated element (PersianCat is Cat), but I would like to also get its superclassifiers (PersianCat is a Cat, and also a Mammel and Animal).

Thanks!

Tom

Hi,

We do not have such functionality in the API at the moment. This should work:

def all_supertypes_of(type: syside.Type) -> set[syside.Type]:
    queue = [type]
    visited = {type}

    while queue:
        next = queue.pop(0)
        if isinstance(next, syside.Feature):
            next = next.feature_target
        if next in visited:
            continue
        visited.add(next)
        queue.extend(next.heritage.elements)

    return visited