Skip to content

Commit

Permalink
Merge pull request #93 from apdavison/issue92
Browse files Browse the repository at this point in the history
Partial fix for #92
  • Loading branch information
apdavison authored Sep 15, 2024
2 parents ed3c333 + 28da285 commit 4a28982
Show file tree
Hide file tree
Showing 175 changed files with 588 additions and 578 deletions.
48 changes: 29 additions & 19 deletions builder/update_openminds.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,31 +707,38 @@ def get_type(prop):
if linked:
linked_from = linked[self._schema_payload["_type"]]
for reverse_link_name in linked_from:
unique_forward_link_names = set(linked_from[reverse_link_name][0])
unique_forward_iris = set(linked_from[reverse_link_name][0])
types_str = [generate_class_name(iri) for iri in linked_from[reverse_link_name][2]]
if len(unique_forward_link_names) == 1:
(forward_link_name,) = unique_forward_link_names
(forward_link_name_plural,) = set(linked_from[reverse_link_name][1])
_forward_link_name_python = generate_python_name(forward_link_name_plural)
iri = f"^vocab:{forward_link_name}"
doc = f"reverse of '{forward_link_name}'" # use _plural?
if len(unique_forward_iris) == 1:
(forward_iri,) = unique_forward_iris
forward_link_names = set(linked_from[reverse_link_name][1])
if len(forward_link_names) == 1:
(forward_link_name,) = forward_link_names
else:
forward_link_name = sorted(forward_link_names)[0]
print(f"Multiple forward link names found: {forward_link_names}, using {forward_link_name}")
# if "FileRepository" in self._schema_payload["_type"]:
# breakpoint()
_forward_link_name_python = generate_python_name(forward_link_name)
iri = f"^vocab:{forward_iri}"
doc = f"reverse of '{_forward_link_name_python}'"
types_str = sorted(types_str)
if len(types_str) == 1:
types_str = f'"{types_str[0]}"'
else:
backwards_compatible = True
if backwards_compatible:
forward_link_name = sorted(set(linked_from[reverse_link_name][0]))
forward_link_name_plural = sorted(set(linked_from[reverse_link_name][1]))
forward_iri = sorted(set(linked_from[reverse_link_name][0]))
forward_link_name = sorted(set(linked_from[reverse_link_name][1]))
types_str = sorted(types_str)
else:
# this is a better solution, since we keep the match between types and names
# in the order of the lists, but is not backwards compatible
forward_link_name = linked_from[reverse_link_name][0]
forward_link_name_plural = linked_from[reverse_link_name][1]
_forward_link_name_python = [generate_python_name(name) for name in forward_link_name_plural]
iri = [f"^vocab:{name}" for name in forward_link_name]
doc = "reverse of " + ", ".join(name for name in forward_link_name) # use _plural?
forward_iri = linked_from[reverse_link_name][0]
forward_link_name = linked_from[reverse_link_name][1]
_forward_link_name_python = [generate_python_name(name) for name in forward_link_name]
iri = [f"^vocab:{part}" for part in forward_iri]
doc = "reverse of " + ", ".join(name for name in _forward_link_name_python)
reverse_name_python = generate_python_name(reverse_link_name)
if reverse_name_python in forward_property_names:
if reverse_name_python in conflict_resolution:
Expand Down Expand Up @@ -821,12 +828,15 @@ def get_edges(self):
reverse_link_name = prop["nameForReverseLink"]
if reverse_link_name is None:
reverse_link_name = reverse_name_map[prop["name"]]
allow_multiple = prop.get("type", "") == "array"
linked[lnk] = (
self._schema_payload["_type"],
prop["name"],
prop["namePlural"],
prop["name"], # property name
prop["namePlural"] if allow_multiple else prop["name"], # forward link name
reverse_link_name,
) # linked from (cls, prop name, prop name plural, reverse name)
# if self._schema_payload["_type"].endswith("File"):
# breakpoint()
return embedded, linked


Expand All @@ -845,16 +855,16 @@ def main(openminds_root, ignore=[]):
for schema_file_path in schema_file_paths:
embedded_in, linked_from = FairgraphClassBuilder(schema_file_path, openminds_root, target_path).get_edges()
embedded.update(embedded_in)
for openminds_type, (link_type, property_name, property_name_plural, reverse_name) in linked_from.items():
for openminds_type, (link_type, property_name, forward_name, reverse_name) in linked_from.items():
if link_type not in embedded:
if isinstance(reverse_name, dict):
reverse_name = reverse_name[link_type]
if reverse_name in linked[openminds_type]:
linked[openminds_type][reverse_name][0].append(property_name)
linked[openminds_type][reverse_name][1].append(property_name_plural)
linked[openminds_type][reverse_name][1].append(forward_name)
linked[openminds_type][reverse_name][2].append(link_type)
else:
linked[openminds_type][reverse_name] = ([property_name], [property_name_plural], [link_type])
linked[openminds_type][reverse_name] = ([property_name], [forward_name], [link_type])
conflicts = set(linked).intersection(embedded)
if conflicts:
print(f"Found schema(s) that are both linked and embedded: {conflicts}")
Expand Down
8 changes: 4 additions & 4 deletions fairgraph/openminds/chemicals/chemical_mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class ChemicalMixture(KGObject):
"composes",
["openminds.ephys.Electrode", "openminds.ephys.ElectrodeArray", "openminds.ephys.Pipette"],
["^vocab:insulatorMaterial", "^vocab:material"],
reverse=["insulator_materials", "materials"],
reverse=["insulator_material", "material"],
multiple=True,
doc="reverse of insulatorMaterial, material",
doc="reverse of insulator_material, material",
),
Property(
"used_in",
Expand All @@ -75,9 +75,9 @@ class ChemicalMixture(KGObject):
"openminds.specimen_prep.TissueSampleSlicing",
],
["^vocab:cultureMedium", "^vocab:pipetteSolution", "^vocab:tissueBathSolution"],
reverse=["culture_media", "pipette_solutions", "tissue_bath_solutions"],
reverse=["culture_medium", "pipette_solution", "tissue_bath_solution"],
multiple=True,
doc="reverse of cultureMedium, pipetteSolution, tissueBathSolution",
doc="reverse of culture_medium, pipette_solution, tissue_bath_solution",
),
]
existence_query_properties = ("has_parts", "type")
Expand Down
8 changes: 4 additions & 4 deletions fairgraph/openminds/chemicals/chemical_substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ class ChemicalSubstance(KGObject):
"composes",
["openminds.ephys.Electrode", "openminds.ephys.ElectrodeArray", "openminds.ephys.Pipette"],
["^vocab:insulatorMaterial", "^vocab:material"],
reverse=["insulator_materials", "materials"],
reverse=["insulator_material", "material"],
multiple=True,
doc="reverse of insulatorMaterial, material",
doc="reverse of insulator_material, material",
),
Property(
"labels",
"openminds.ephys.PipetteUsage",
"^vocab:labelingCompound",
reverse="labeling_compounds",
reverse="labeling_compound",
multiple=True,
doc="reverse of 'labelingCompound'",
doc="reverse of 'labeling_compound'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/chemicals/product_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ class ProductSource(KGObject):
"is_source_of",
["openminds.chemicals.ChemicalMixture", "openminds.chemicals.ChemicalSubstance"],
"^vocab:productSource",
reverse="product_sources",
reverse="product_source",
multiple=True,
doc="reverse of 'productSource'",
doc="reverse of 'product_source'",
),
]
existence_query_properties = ("product_name", "provider")
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ class DataAnalysis(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/data_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ class DataCopy(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
2 changes: 1 addition & 1 deletion fairgraph/openminds/computation/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Environment(KGObject):
"openminds.computation.Visualization",
],
"^vocab:environment",
reverse="environments",
reverse="environment",
multiple=True,
doc="reverse of 'environment'",
),
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/generic_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ class GenericComputation(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/launch_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class LaunchConfiguration(KGObject):
"openminds.computation.Visualization",
],
"^vocab:launchConfiguration",
reverse="launch_configurations",
reverse="launch_configuration",
multiple=True,
doc="reverse of 'launchConfiguration'",
doc="reverse of 'launch_configuration'",
),
]
existence_query_properties = ("executable", "name")
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class LocalFile(KGObject):
"^vocab:output",
reverse="outputs",
multiple=True,
doc="reverse of 'output'",
doc="reverse of 'outputs'",
),
Property(
"is_used_to_group",
"openminds.core.FileBundle",
"^vocab:groupedBy",
reverse="grouped_by",
multiple=True,
doc="reverse of 'groupedBy'",
doc="reverse of 'grouped_by'",
),
]
existence_query_properties = ("name", "path")
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/model_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ class ModelValidation(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ class Optimization(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ class Simulation(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/software_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SoftwareAgent(KGObject):
"^vocab:performedBy",
reverse="performed_by",
multiple=True,
doc="reverse of 'performedBy'",
doc="reverse of 'performed_by'",
),
Property(
"started",
Expand All @@ -74,7 +74,7 @@ class SoftwareAgent(KGObject):
"^vocab:startedBy",
reverse="started_by",
multiple=True,
doc="reverse of 'startedBy'",
doc="reverse of 'started_by'",
),
]
existence_query_properties = ("name", "software")
Expand Down
2 changes: 1 addition & 1 deletion fairgraph/openminds/computation/validation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ValidationTest(KGObject):
"^vocab:hasPart",
reverse="has_parts",
multiple=True,
doc="reverse of 'hasPart'",
doc="reverse of 'has_parts'",
),
Property(
"learning_resources",
Expand Down
8 changes: 4 additions & 4 deletions fairgraph/openminds/computation/validation_test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,31 +304,31 @@ class ValidationTestVersion(KGObject):
"^vocab:input",
reverse="inputs",
multiple=True,
doc="reverse of 'input'",
doc="reverse of 'inputs'",
),
Property(
"is_old_version_of",
"openminds.computation.ValidationTestVersion",
"^vocab:isNewVersionOf",
reverse="is_new_version_of",
multiple=True,
doc="reverse of 'isNewVersionOf'",
doc="reverse of 'is_new_version_of'",
),
Property(
"is_part_of",
["openminds.core.Project", "openminds.core.ResearchProductGroup"],
"^vocab:hasPart",
reverse="has_parts",
multiple=True,
doc="reverse of 'hasPart'",
doc="reverse of 'has_parts'",
),
Property(
"is_version_of",
"openminds.computation.ValidationTest",
"^vocab:hasVersion",
reverse="has_versions",
multiple=True,
doc="reverse of 'hasVersion'",
doc="reverse of 'has_versions'",
),
Property(
"learning_resources",
Expand Down
4 changes: 2 additions & 2 deletions fairgraph/openminds/computation/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ class Visualization(KGObject):
"^vocab:wasInformedBy",
reverse="was_informed_by",
multiple=True,
doc="reverse of 'wasInformedBy'",
doc="reverse of 'was_informed_by'",
),
Property(
"is_part_of",
"openminds.computation.WorkflowExecution",
"^vocab:stage",
reverse="stages",
multiple=True,
doc="reverse of 'stage'",
doc="reverse of 'stages'",
),
]
existence_query_properties = ("lookup_label",)
Expand Down
2 changes: 1 addition & 1 deletion fairgraph/openminds/computation/workflow_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class WorkflowRecipe(KGObject):
"^vocab:hasPart",
reverse="has_parts",
multiple=True,
doc="reverse of 'hasPart'",
doc="reverse of 'has_parts'",
),
Property(
"learning_resources",
Expand Down
Loading

0 comments on commit 4a28982

Please sign in to comment.