Skip to content

Commit 9e3aeb4

Browse files
authored
Change the type_ attribute to be a string (as in openMINDS Python), rather than a single-element list containing that string (as in the KG). (#89)
1 parent f2c5a00 commit 9e3aeb4

File tree

227 files changed

+254
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+254
-247
lines changed

builder/fairgraph_module_template.py.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class {{ class_name }}({{ base_class }}):
1717
{%- if default_space %}
1818
default_space = "{{ default_space }}"
1919
{%- endif %}
20-
type_ = ["{{ openminds_type }}"]
20+
type_ = "{{ openminds_type }}"
2121
context = {
2222
"schema": "http://schema.org/",
2323
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/base.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ContainsMetadata(Resolvable, metaclass=Registry): # KGObject and Embedded
7777
properties: List[Property]
7878
reverse_properties: List[Property]
7979
context: Dict[str, str]
80-
type_: List[str]
80+
type_: str
8181
scope: Optional[str]
8282
space: Union[str, None]
8383
default_space: Union[str, None]
@@ -166,7 +166,7 @@ def to_jsonld(
166166
167167
"""
168168
if self.properties:
169-
data: JSONdict = {"@type": self.type_}
169+
data: JSONdict = {"@type": [self.type_]}
170170
if hasattr(self, "id") and self.id:
171171
data["@id"] = self.id
172172
for prop in self.__class__.all_properties:
@@ -339,9 +339,16 @@ def _deserialize_data(cls, data: JSONdict, client: KGClient, include_id: bool =
339339
elif key[0] != "@":
340340
normalised_key = expand_uri(key, cls.context)
341341
D[normalised_key] = value
342-
for otype in expand_uri(as_list(cls.type_), cls.context):
343-
if otype not in D["@type"]:
344-
raise TypeError("type mismatch {} - {}".format(otype, D["@type"]))
342+
if cls.type_ not in D["@type"]:
343+
raise TypeError("type mismatch {} - {}".format(cls.type_, D["@type"]))
344+
345+
def _get_type_from_data(data_item):
346+
type_ = data_item.get("@type", None)
347+
if type_:
348+
return type_[0]
349+
else:
350+
return None
351+
345352
deserialized_data = {}
346353
for prop in cls.all_properties:
347354
expanded_path = expand_uri(prop.path, cls.context)
@@ -352,7 +359,7 @@ def _deserialize_data(cls, data: JSONdict, client: KGClient, include_id: bool =
352359
try:
353360
data_item = [
354361
part for part in as_list(data_item)
355-
if part.get("@type", None) in [t.type_ for t in prop.types]
362+
if _get_type_from_data(part) in [t.type_ for t in prop.types]
356363
]
357364
except AttributeError:
358365
# problem when a forward and reverse path both given the same expanded path

fairgraph/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def configure_space(self, space_name: Optional[str] = None, types: Optional[List
576576
if result: # error
577577
raise Exception(f"Unable to configure KG space for space '{space_name}': {result}")
578578
for cls in types:
579-
result = self._kg_admin_client.assign_type_to_space(space=space_name, target_type=cls.type_[0])
579+
result = self._kg_admin_client.assign_type_to_space(space=space_name, target_type=cls.type_)
580580
if result: # error
581581
raise Exception(f"Unable to assign {cls.__name__} to space {space_name}: {result}")
582582
return space_name

fairgraph/kgobject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def from_id(
229229
if follow_links is not None:
230230
raise NotImplementedError
231231
data = client.instance_from_full_uri(uri, use_cache=use_cache, scope=scope)
232-
cls_from_data = lookup_type(data["@type"])
232+
cls_from_data = lookup_type(data["@type"][0])
233233
return cls_from_data.from_kg_instance(data, client, scope=scope)
234234

235235
@classmethod
@@ -760,7 +760,7 @@ def show(self, max_width: Optional[int] = None, include_empty_properties=False):
760760
data = [
761761
("id", str(self.id)),
762762
("space", str(self.space)),
763-
("type", self.type_[0]),
763+
("type", self.type_),
764764
]
765765
for prop in self.__class__.all_properties:
766766
value = getattr(self, prop.name, None)
@@ -813,7 +813,7 @@ def generate_query(
813813
normalized_filters = None
814814
# first pass, we build the basic structure
815815
query = Query(
816-
node_type=cls.type_[0],
816+
node_type=cls.type_,
817817
label=label,
818818
space=real_space,
819819
properties=cls.generate_query_properties(follow_links),

fairgraph/openminds/chemicals/amount_of_chemical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AmountOfChemical(EmbeddedMetadata):
1313
Structured information about the amount of a given chemical that was used.
1414
"""
1515

16-
type_ = ["https://openminds.ebrains.eu/chemicals/AmountOfChemical"]
16+
type_ = "https://openminds.ebrains.eu/chemicals/AmountOfChemical"
1717
context = {
1818
"schema": "http://schema.org/",
1919
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/openminds/chemicals/chemical_mixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ChemicalMixture(KGObject):
1414
"""
1515

1616
default_space = "in-depth"
17-
type_ = ["https://openminds.ebrains.eu/chemicals/ChemicalMixture"]
17+
type_ = "https://openminds.ebrains.eu/chemicals/ChemicalMixture"
1818
context = {
1919
"schema": "http://schema.org/",
2020
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/openminds/chemicals/chemical_substance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ChemicalSubstance(KGObject):
1414
"""
1515

1616
default_space = "in-depth"
17-
type_ = ["https://openminds.ebrains.eu/chemicals/ChemicalSubstance"]
17+
type_ = "https://openminds.ebrains.eu/chemicals/ChemicalSubstance"
1818
context = {
1919
"schema": "http://schema.org/",
2020
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/openminds/chemicals/product_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ProductSource(KGObject):
1414
"""
1515

1616
default_space = "in-depth"
17-
type_ = ["https://openminds.ebrains.eu/chemicals/ProductSource"]
17+
type_ = "https://openminds.ebrains.eu/chemicals/ProductSource"
1818
context = {
1919
"schema": "http://schema.org/",
2020
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/openminds/computation/data_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DataAnalysis(KGObject):
1717
"""
1818

1919
default_space = "computation"
20-
type_ = ["https://openminds.ebrains.eu/computation/DataAnalysis"]
20+
type_ = "https://openminds.ebrains.eu/computation/DataAnalysis"
2121
context = {
2222
"schema": "http://schema.org/",
2323
"kg": "https://kg.ebrains.eu/api/instances/",

fairgraph/openminds/computation/data_copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DataCopy(KGObject):
1717
"""
1818

1919
default_space = "computation"
20-
type_ = ["https://openminds.ebrains.eu/computation/DataCopy"]
20+
type_ = "https://openminds.ebrains.eu/computation/DataCopy"
2121
context = {
2222
"schema": "http://schema.org/",
2323
"kg": "https://kg.ebrains.eu/api/instances/",

0 commit comments

Comments
 (0)