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

Issue #266: Caching typesystem.is_instance_of(..., TYPE_NAME_STRING_ARRAY) #267

Merged
merged 2 commits into from
Jan 23, 2023
Merged
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
10 changes: 9 additions & 1 deletion cassis/xmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def deserialize(self, source: Union[IO, str], typesystem: TypeSystem, lenient: b
if event == "end":
self._clear_elem(elem)

# See https://github.com/dkpro/dkpro-cassis/issues/266
# The checking for each feature if it is a StringArray is rather slow, hence, we cache the results
is_instance_of_string_array_map = {}

# Post-process feature values
for xmi_id, fs in feature_structures.items():
t = typesystem.get_type(fs.type.name)
Expand All @@ -217,7 +221,11 @@ def deserialize(self, source: Union[IO, str], typesystem: TypeSystem, lenient: b
fs[feature_name] = sofas[value]
continue

if typesystem.is_instance_of(fs.type.name, TYPE_NAME_STRING_ARRAY):
if fs.type.name not in is_instance_of_string_array_map:
is_instance_of_string_array_map[fs.type.name] = typesystem.is_instance_of(fs.type.name,
TYPE_NAME_STRING_ARRAY)

if is_instance_of_string_array_map[fs.type.name]:
# We already parsed string arrays to a Python list of string
# before, so we do not need to work more on this
continue
Expand Down