Skip to content

Commit

Permalink
Merge pull request #311 from dkpro/feature/310-Add-short_name-propert…
Browse files Browse the repository at this point in the history
…y-to-type

#310 - Add short_name property to type
  • Loading branch information
reckart authored May 4, 2024
2 parents 22232b6 + f4f56ec commit 1fa0932
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cassis/typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ def descendants(self) -> Iterator["Type"]:
for child in self._children.values():
yield from child.descendants

@property
def short_name(self) -> str:
"""The short name of the type (i.e. the part after the last dot)."""
return self.name.split(".")[-1]

def subsumes(self, other_type: "Type") -> bool:
"""Determines if the type `other_type` is a child of `self`.
Expand Down Expand Up @@ -838,10 +843,10 @@ def __init__(self, add_document_annotation_type: bool = True):
if add_document_annotation_type:
self._add_document_annotation_type()

def __iter__(self):
def __iter__(self) -> Iterator[Type]:
return self.get_types()

def contains_type(self, typename: str):
def contains_type(self, typename: str) -> bool:
"""Checks whether this type system contains a type with name `typename`.
Args:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ def test_is_array():
assert cas.typesystem.is_array(type.name) == type.name.endswith("Array")


def test_type_name():
cas = Cas()

Annotation = cas.typesystem.get_type(TYPE_NAME_ANNOTATION)
assert Annotation.name == TYPE_NAME_ANNOTATION
assert Annotation.short_name == "Annotation"


def test_get_types():
cas = Cas()

Expand Down

0 comments on commit 1fa0932

Please sign in to comment.