diff --git a/pipeline/src/base.py b/pipeline/src/base.py index b81da10..1d2d35c 100644 --- a/pipeline/src/base.py +++ b/pipeline/src/base.py @@ -119,6 +119,8 @@ def from_jsonld(cls, data): data_copy = data.copy() context = data_copy.pop("@context", None) type_ = data_copy.pop("@type") + if isinstance(type_, list) and len(type_) == 1: + type_ = type_[0] if type_ and type_ != cls.type_: raise TypeError(f"Mismatched types. Data has '{type_}' but trying to create '{cls.type_}'") deserialized_data = {} diff --git a/pipeline/src/properties.py b/pipeline/src/properties.py index 6831853..d06e968 100644 --- a/pipeline/src/properties.py +++ b/pipeline/src/properties.py @@ -206,8 +206,12 @@ def deserialize_item(item): elif all(issubclass(t, Node) for t in self.types): # use data["@type"] to figure out class to use if "@type" in item: + if isinstance(item["@type"], list) and len(item["@type"]) == 1: + item_type = item["@type"][0] + else: + item_type = item["@type"] for cls in self.types: - if cls.type_ == item["@type"]: + if cls.type_ == item_type: if set(item.keys()) == link_keys: # if we only have @id and @type, it's a Link return Link(item["@id"], allowed_types=[cls]) @@ -215,8 +219,8 @@ def deserialize_item(item): # otherwise it's a Node return cls.from_jsonld(item) raise TypeError( - f"Mismatched types. Data has '{item['@type']}' " - f"but property only allows {[cls.type_ for cls in self.types]}" + f"Mismatched types. Data has '{item_type}' " + f"but property only allows one of {[cls.type_ for cls in self.types]}" ) else: return Link(item["@id"], allowed_types=self.types)