fairgraph 0.13.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fairgraph/__init__.py +61 -0
- fairgraph/base.py +104 -0
- fairgraph/caching.py +52 -0
- fairgraph/client.py +867 -0
- fairgraph/collection.py +104 -0
- fairgraph/embedded.py +122 -0
- fairgraph/errors.py +47 -0
- fairgraph/fields.py +11 -0
- fairgraph/kgobject.py +1087 -0
- fairgraph/kgproxy.py +178 -0
- fairgraph/kgquery.py +151 -0
- fairgraph/node.py +488 -0
- fairgraph/openminds/__init__.py +1 -0
- fairgraph/openminds/chemicals/__init__.py +40 -0
- fairgraph/openminds/chemicals/amount_of_chemical.py +23 -0
- fairgraph/openminds/chemicals/chemical_mixture.py +72 -0
- fairgraph/openminds/chemicals/chemical_substance.py +67 -0
- fairgraph/openminds/chemicals/product_source.py +57 -0
- fairgraph/openminds/computation/__init__.py +53 -0
- fairgraph/openminds/computation/data_analysis.py +104 -0
- fairgraph/openminds/computation/data_copy.py +104 -0
- fairgraph/openminds/computation/environment.py +66 -0
- fairgraph/openminds/computation/generic_computation.py +104 -0
- fairgraph/openminds/computation/hardware_system.py +53 -0
- fairgraph/openminds/computation/launch_configuration.py +68 -0
- fairgraph/openminds/computation/local_file.py +83 -0
- fairgraph/openminds/computation/model_validation.py +107 -0
- fairgraph/openminds/computation/optimization.py +104 -0
- fairgraph/openminds/computation/simulation.py +104 -0
- fairgraph/openminds/computation/software_agent.py +81 -0
- fairgraph/openminds/computation/validation_test.py +105 -0
- fairgraph/openminds/computation/validation_test_version.py +180 -0
- fairgraph/openminds/computation/visualization.py +104 -0
- fairgraph/openminds/computation/workflow_execution.py +44 -0
- fairgraph/openminds/computation/workflow_recipe.py +95 -0
- fairgraph/openminds/computation/workflow_recipe_version.py +185 -0
- fairgraph/openminds/controlled_terms/__init__.py +116 -0
- fairgraph/openminds/controlled_terms/action_status_type.py +97 -0
- fairgraph/openminds/controlled_terms/age_category.py +89 -0
- fairgraph/openminds/controlled_terms/analysis_technique.py +108 -0
- fairgraph/openminds/controlled_terms/anatomical_axes_orientation.py +89 -0
- fairgraph/openminds/controlled_terms/anatomical_identification_type.py +89 -0
- fairgraph/openminds/controlled_terms/anatomical_plane.py +89 -0
- fairgraph/openminds/controlled_terms/annotation_criteria_type.py +89 -0
- fairgraph/openminds/controlled_terms/annotation_type.py +89 -0
- fairgraph/openminds/controlled_terms/atlas_type.py +88 -0
- fairgraph/openminds/controlled_terms/auditory_stimulus_type.py +127 -0
- fairgraph/openminds/controlled_terms/biological_order.py +117 -0
- fairgraph/openminds/controlled_terms/biological_process.py +79 -0
- fairgraph/openminds/controlled_terms/biological_sex.py +132 -0
- fairgraph/openminds/controlled_terms/breeding_type.py +127 -0
- fairgraph/openminds/controlled_terms/cell_culture_type.py +117 -0
- fairgraph/openminds/controlled_terms/cell_type.py +151 -0
- fairgraph/openminds/controlled_terms/chemical_mixture_type.py +89 -0
- fairgraph/openminds/controlled_terms/colormap.py +79 -0
- fairgraph/openminds/controlled_terms/contribution_type.py +79 -0
- fairgraph/openminds/controlled_terms/cranial_window_construction_type.py +89 -0
- fairgraph/openminds/controlled_terms/cranial_window_reinforcement_type.py +89 -0
- fairgraph/openminds/controlled_terms/criteria_quality_type.py +89 -0
- fairgraph/openminds/controlled_terms/data_type.py +89 -0
- fairgraph/openminds/controlled_terms/device_type.py +94 -0
- fairgraph/openminds/controlled_terms/difference_measure.py +89 -0
- fairgraph/openminds/controlled_terms/disease.py +142 -0
- fairgraph/openminds/controlled_terms/disease_model.py +142 -0
- fairgraph/openminds/controlled_terms/educational_level.py +79 -0
- fairgraph/openminds/controlled_terms/electrical_stimulus_type.py +137 -0
- fairgraph/openminds/controlled_terms/ethics_assessment.py +79 -0
- fairgraph/openminds/controlled_terms/experimental_approach.py +79 -0
- fairgraph/openminds/controlled_terms/file_bundle_grouping.py +99 -0
- fairgraph/openminds/controlled_terms/file_repository_type.py +89 -0
- fairgraph/openminds/controlled_terms/file_usage_role.py +89 -0
- fairgraph/openminds/controlled_terms/genetic_strain_type.py +127 -0
- fairgraph/openminds/controlled_terms/gustatory_stimulus_type.py +127 -0
- fairgraph/openminds/controlled_terms/handedness.py +127 -0
- fairgraph/openminds/controlled_terms/language.py +88 -0
- fairgraph/openminds/controlled_terms/laterality.py +94 -0
- fairgraph/openminds/controlled_terms/learning_resource_type.py +88 -0
- fairgraph/openminds/controlled_terms/measured_quantity.py +89 -0
- fairgraph/openminds/controlled_terms/measured_signal_type.py +79 -0
- fairgraph/openminds/controlled_terms/meta_data_model_type.py +88 -0
- fairgraph/openminds/controlled_terms/model_abstraction_level.py +89 -0
- fairgraph/openminds/controlled_terms/model_scope.py +89 -0
- fairgraph/openminds/controlled_terms/molecular_entity.py +142 -0
- fairgraph/openminds/controlled_terms/mri_pulse_sequence.py +98 -0
- fairgraph/openminds/controlled_terms/mri_weighting.py +98 -0
- fairgraph/openminds/controlled_terms/olfactory_stimulus_type.py +127 -0
- fairgraph/openminds/controlled_terms/operating_device.py +79 -0
- fairgraph/openminds/controlled_terms/operating_system.py +88 -0
- fairgraph/openminds/controlled_terms/optical_stimulus_type.py +127 -0
- fairgraph/openminds/controlled_terms/organ.py +161 -0
- fairgraph/openminds/controlled_terms/organism_substance.py +151 -0
- fairgraph/openminds/controlled_terms/organism_system.py +117 -0
- fairgraph/openminds/controlled_terms/patch_clamp_variation.py +89 -0
- fairgraph/openminds/controlled_terms/preparation_type.py +98 -0
- fairgraph/openminds/controlled_terms/product_accessibility.py +79 -0
- fairgraph/openminds/controlled_terms/programming_language.py +88 -0
- fairgraph/openminds/controlled_terms/qualitative_overlap.py +79 -0
- fairgraph/openminds/controlled_terms/semantic_data_type.py +79 -0
- fairgraph/openminds/controlled_terms/service.py +89 -0
- fairgraph/openminds/controlled_terms/setup_type.py +89 -0
- fairgraph/openminds/controlled_terms/software_application_category.py +79 -0
- fairgraph/openminds/controlled_terms/software_feature.py +79 -0
- fairgraph/openminds/controlled_terms/species.py +143 -0
- fairgraph/openminds/controlled_terms/stimulation_approach.py +98 -0
- fairgraph/openminds/controlled_terms/stimulation_technique.py +98 -0
- fairgraph/openminds/controlled_terms/subcellular_entity.py +143 -0
- fairgraph/openminds/controlled_terms/subject_attribute.py +89 -0
- fairgraph/openminds/controlled_terms/tactile_stimulus_type.py +127 -0
- fairgraph/openminds/controlled_terms/technique.py +108 -0
- fairgraph/openminds/controlled_terms/term_suggestion.py +121 -0
- fairgraph/openminds/controlled_terms/terminology.py +89 -0
- fairgraph/openminds/controlled_terms/tissue_sample_attribute.py +89 -0
- fairgraph/openminds/controlled_terms/tissue_sample_type.py +127 -0
- fairgraph/openminds/controlled_terms/type_of_uncertainty.py +89 -0
- fairgraph/openminds/controlled_terms/uberon_parcellation.py +153 -0
- fairgraph/openminds/controlled_terms/unit_of_measurement.py +108 -0
- fairgraph/openminds/controlled_terms/visual_stimulus_type.py +127 -0
- fairgraph/openminds/controlledterms.py +6 -0
- fairgraph/openminds/core/__init__.py +107 -0
- fairgraph/openminds/core/actors/__init__.py +7 -0
- fairgraph/openminds/core/actors/account_information.py +44 -0
- fairgraph/openminds/core/actors/affiliation.py +30 -0
- fairgraph/openminds/core/actors/consortium.py +175 -0
- fairgraph/openminds/core/actors/contact_information.py +43 -0
- fairgraph/openminds/core/actors/contribution.py +23 -0
- fairgraph/openminds/core/actors/organization.py +199 -0
- fairgraph/openminds/core/actors/person.py +236 -0
- fairgraph/openminds/core/data/__init__.py +13 -0
- fairgraph/openminds/core/data/content_type.py +107 -0
- fairgraph/openminds/core/data/content_type_pattern.py +53 -0
- fairgraph/openminds/core/data/copyright.py +23 -0
- fairgraph/openminds/core/data/file.py +275 -0
- fairgraph/openminds/core/data/file_archive.py +71 -0
- fairgraph/openminds/core/data/file_bundle.py +150 -0
- fairgraph/openminds/core/data/file_path_pattern.py +23 -0
- fairgraph/openminds/core/data/file_repository.py +99 -0
- fairgraph/openminds/core/data/file_repository_structure.py +51 -0
- fairgraph/openminds/core/data/hash.py +23 -0
- fairgraph/openminds/core/data/license.py +77 -0
- fairgraph/openminds/core/data/measurement.py +45 -0
- fairgraph/openminds/core/data/service_link.py +49 -0
- fairgraph/openminds/core/digital_identifier/__init__.py +11 -0
- fairgraph/openminds/core/digital_identifier/doi.py +98 -0
- fairgraph/openminds/core/digital_identifier/gridid.py +41 -0
- fairgraph/openminds/core/digital_identifier/handle.py +52 -0
- fairgraph/openminds/core/digital_identifier/identifiers_dot_org_id.py +41 -0
- fairgraph/openminds/core/digital_identifier/isbn.py +88 -0
- fairgraph/openminds/core/digital_identifier/issn.py +63 -0
- fairgraph/openminds/core/digital_identifier/orcid.py +41 -0
- fairgraph/openminds/core/digital_identifier/rorid.py +41 -0
- fairgraph/openminds/core/digital_identifier/rrid.py +55 -0
- fairgraph/openminds/core/digital_identifier/stock_number.py +23 -0
- fairgraph/openminds/core/digital_identifier/swhid.py +48 -0
- fairgraph/openminds/core/miscellaneous/__init__.py +7 -0
- fairgraph/openminds/core/miscellaneous/comment.py +47 -0
- fairgraph/openminds/core/miscellaneous/funding.py +70 -0
- fairgraph/openminds/core/miscellaneous/quantitative_value.py +43 -0
- fairgraph/openminds/core/miscellaneous/quantitative_value_array.py +49 -0
- fairgraph/openminds/core/miscellaneous/quantitative_value_range.py +43 -0
- fairgraph/openminds/core/miscellaneous/research_product_group.py +26 -0
- fairgraph/openminds/core/miscellaneous/web_resource.py +104 -0
- fairgraph/openminds/core/products/__init__.py +12 -0
- fairgraph/openminds/core/products/dataset.py +95 -0
- fairgraph/openminds/core/products/dataset_version.py +240 -0
- fairgraph/openminds/core/products/meta_data_model.py +95 -0
- fairgraph/openminds/core/products/meta_data_model_version.py +168 -0
- fairgraph/openminds/core/products/model.py +103 -0
- fairgraph/openminds/core/products/model_version.py +235 -0
- fairgraph/openminds/core/products/project.py +56 -0
- fairgraph/openminds/core/products/setup.py +69 -0
- fairgraph/openminds/core/products/software.py +95 -0
- fairgraph/openminds/core/products/software_version.py +226 -0
- fairgraph/openminds/core/products/web_service.py +103 -0
- fairgraph/openminds/core/products/web_service_version.py +182 -0
- fairgraph/openminds/core/research/__init__.py +17 -0
- fairgraph/openminds/core/research/behavioral_protocol.py +69 -0
- fairgraph/openminds/core/research/configuration.py +67 -0
- fairgraph/openminds/core/research/custom_property_set.py +27 -0
- fairgraph/openminds/core/research/numerical_property.py +23 -0
- fairgraph/openminds/core/research/property_value_list.py +71 -0
- fairgraph/openminds/core/research/protocol.py +67 -0
- fairgraph/openminds/core/research/protocol_execution.py +76 -0
- fairgraph/openminds/core/research/strain.py +90 -0
- fairgraph/openminds/core/research/string_property.py +23 -0
- fairgraph/openminds/core/research/subject.py +79 -0
- fairgraph/openminds/core/research/subject_group.py +91 -0
- fairgraph/openminds/core/research/subject_group_state.py +113 -0
- fairgraph/openminds/core/research/subject_state.py +138 -0
- fairgraph/openminds/core/research/tissue_sample.py +87 -0
- fairgraph/openminds/core/research/tissue_sample_collection.py +99 -0
- fairgraph/openminds/core/research/tissue_sample_collection_state.py +109 -0
- fairgraph/openminds/core/research/tissue_sample_state.py +127 -0
- fairgraph/openminds/ephys/__init__.py +39 -0
- fairgraph/openminds/ephys/activity/__init__.py +3 -0
- fairgraph/openminds/ephys/activity/cell_patching.py +73 -0
- fairgraph/openminds/ephys/activity/electrode_placement.py +67 -0
- fairgraph/openminds/ephys/activity/recording_activity.py +67 -0
- fairgraph/openminds/ephys/device/__init__.py +6 -0
- fairgraph/openminds/ephys/device/electrode.py +81 -0
- fairgraph/openminds/ephys/device/electrode_array.py +85 -0
- fairgraph/openminds/ephys/device/electrode_array_usage.py +105 -0
- fairgraph/openminds/ephys/device/electrode_usage.py +101 -0
- fairgraph/openminds/ephys/device/pipette.py +81 -0
- fairgraph/openminds/ephys/device/pipette_usage.py +123 -0
- fairgraph/openminds/ephys/entity/__init__.py +2 -0
- fairgraph/openminds/ephys/entity/channel.py +23 -0
- fairgraph/openminds/ephys/entity/recording.py +63 -0
- fairgraph/openminds/publications/__init__.py +47 -0
- fairgraph/openminds/publications/book.py +106 -0
- fairgraph/openminds/publications/chapter.py +100 -0
- fairgraph/openminds/publications/learning_resource.py +90 -0
- fairgraph/openminds/publications/live_paper.py +95 -0
- fairgraph/openminds/publications/live_paper_resource_item.py +58 -0
- fairgraph/openminds/publications/live_paper_section.py +57 -0
- fairgraph/openminds/publications/live_paper_version.py +177 -0
- fairgraph/openminds/publications/periodical.py +53 -0
- fairgraph/openminds/publications/publication_issue.py +44 -0
- fairgraph/openminds/publications/publication_volume.py +44 -0
- fairgraph/openminds/publications/scholarly_article.py +146 -0
- fairgraph/openminds/sands/__init__.py +57 -0
- fairgraph/openminds/sands/atlas/__init__.py +9 -0
- fairgraph/openminds/sands/atlas/atlas_annotation.py +52 -0
- fairgraph/openminds/sands/atlas/brain_atlas.py +113 -0
- fairgraph/openminds/sands/atlas/brain_atlas_version.py +213 -0
- fairgraph/openminds/sands/atlas/common_coordinate_space.py +121 -0
- fairgraph/openminds/sands/atlas/common_coordinate_space_version.py +243 -0
- fairgraph/openminds/sands/atlas/parcellation_entity.py +133 -0
- fairgraph/openminds/sands/atlas/parcellation_entity_version.py +162 -0
- fairgraph/openminds/sands/atlas/parcellation_terminology.py +38 -0
- fairgraph/openminds/sands/atlas/parcellation_terminology_version.py +38 -0
- fairgraph/openminds/sands/mathematical_shapes/__init__.py +3 -0
- fairgraph/openminds/sands/mathematical_shapes/circle.py +23 -0
- fairgraph/openminds/sands/mathematical_shapes/ellipse.py +27 -0
- fairgraph/openminds/sands/mathematical_shapes/rectangle.py +23 -0
- fairgraph/openminds/sands/miscellaneous/__init__.py +6 -0
- fairgraph/openminds/sands/miscellaneous/anatomical_target_position.py +40 -0
- fairgraph/openminds/sands/miscellaneous/coordinate_point.py +23 -0
- fairgraph/openminds/sands/miscellaneous/qualitative_relation_assessment.py +34 -0
- fairgraph/openminds/sands/miscellaneous/quantitative_relation_assessment.py +38 -0
- fairgraph/openminds/sands/miscellaneous/single_color.py +24 -0
- fairgraph/openminds/sands/miscellaneous/viewer_specification.py +40 -0
- fairgraph/openminds/sands/non_atlas/__init__.py +3 -0
- fairgraph/openminds/sands/non_atlas/custom_anatomical_entity.py +110 -0
- fairgraph/openminds/sands/non_atlas/custom_annotation.py +54 -0
- fairgraph/openminds/sands/non_atlas/custom_coordinate_space.py +67 -0
- fairgraph/openminds/specimen_prep/__init__.py +38 -0
- fairgraph/openminds/specimen_prep/activity/__init__.py +3 -0
- fairgraph/openminds/specimen_prep/activity/cranial_window_preparation.py +69 -0
- fairgraph/openminds/specimen_prep/activity/tissue_culture_preparation.py +67 -0
- fairgraph/openminds/specimen_prep/activity/tissue_sample_slicing.py +69 -0
- fairgraph/openminds/specimen_prep/device/__init__.py +2 -0
- fairgraph/openminds/specimen_prep/device/slicing_device.py +73 -0
- fairgraph/openminds/specimen_prep/device/slicing_device_usage.py +117 -0
- fairgraph/openminds/specimenprep.py +4 -0
- fairgraph/openminds/stimulation/__init__.py +38 -0
- fairgraph/openminds/stimulation/activity/__init__.py +1 -0
- fairgraph/openminds/stimulation/activity/stimulation_activity.py +67 -0
- fairgraph/openminds/stimulation/stimulus/__init__.py +1 -0
- fairgraph/openminds/stimulation/stimulus/ephys_stimulus.py +63 -0
- fairgraph/queries.py +499 -0
- fairgraph/registry.py +123 -0
- fairgraph/utility.py +607 -0
- fairgraph-0.13.0.dist-info/METADATA +222 -0
- fairgraph-0.13.0.dist-info/RECORD +267 -0
- fairgraph-0.13.0.dist-info/WHEEL +5 -0
- fairgraph-0.13.0.dist-info/licenses/LICENSE.txt +177 -0
- fairgraph-0.13.0.dist-info/top_level.txt +1 -0
fairgraph/collection.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides the Collection class, an extension to the openMINDS Collection
|
|
3
|
+
that knows how to upload metadata to the KG.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# Copyright 2018-2024 CNRS
|
|
7
|
+
|
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
# you may not use this file except in compliance with the License.
|
|
10
|
+
# You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
# See the License for the specific language governing permissions and
|
|
18
|
+
# limitations under the License.
|
|
19
|
+
|
|
20
|
+
from importlib import import_module
|
|
21
|
+
import os
|
|
22
|
+
from time import sleep
|
|
23
|
+
from uuid import uuid4
|
|
24
|
+
from warnings import warn
|
|
25
|
+
|
|
26
|
+
from openminds import Collection as OMCollection
|
|
27
|
+
from .utility import ActivityLog
|
|
28
|
+
from .errors import AuthenticationError
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Collection(OMCollection):
|
|
32
|
+
"""
|
|
33
|
+
A collection of metadata nodes that can be saved to
|
|
34
|
+
and loaded from disk, and uploaded to the KG.
|
|
35
|
+
|
|
36
|
+
Args
|
|
37
|
+
----
|
|
38
|
+
|
|
39
|
+
*nodes (LinkedMetadata):
|
|
40
|
+
Nodes to store in the collection when creating it.
|
|
41
|
+
Child nodes that are referenced from the explicitly
|
|
42
|
+
listed nodes will also be added.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def load(self, *paths):
|
|
46
|
+
import_module("fairgraph.openminds")
|
|
47
|
+
super().load(*paths)
|
|
48
|
+
|
|
49
|
+
def upload(self, client, default_space=None, space_map=None, verbosity=0):
|
|
50
|
+
nodes_to_save = [
|
|
51
|
+
node
|
|
52
|
+
for node in self.sort_nodes_for_upload()
|
|
53
|
+
if not node.id.startswith("https://openminds.om-i.org/instances")
|
|
54
|
+
]
|
|
55
|
+
activity_log = ActivityLog()
|
|
56
|
+
|
|
57
|
+
if verbosity == 1:
|
|
58
|
+
try:
|
|
59
|
+
tqdm = import_module("tqdm")
|
|
60
|
+
except ImportError:
|
|
61
|
+
warn("Unable to show progress bar, please install tqdm")
|
|
62
|
+
else:
|
|
63
|
+
nodes_to_save = tqdm.tqdm(nodes_to_save)
|
|
64
|
+
|
|
65
|
+
if os.path.exists(".kg_upload_log.txt"):
|
|
66
|
+
with open(".kg_upload_log.txt") as fp:
|
|
67
|
+
skip = fp.read().strip().split("\n")
|
|
68
|
+
else:
|
|
69
|
+
skip = None
|
|
70
|
+
|
|
71
|
+
for i, node in enumerate(nodes_to_save):
|
|
72
|
+
if not (skip and node.id in skip):
|
|
73
|
+
if verbosity == 2:
|
|
74
|
+
print(f"[{100*i//len(nodes_to_save)}%] Saving {node.__class__.__name__} {node.id}")
|
|
75
|
+
if space_map:
|
|
76
|
+
target_space = space_map.get(node.__class__, default_space)
|
|
77
|
+
else:
|
|
78
|
+
target_space = default_space
|
|
79
|
+
original_node_id = node.id
|
|
80
|
+
try:
|
|
81
|
+
node.save(
|
|
82
|
+
client, space=target_space, recursive=False, ignore_duplicates=True, activity_log=activity_log
|
|
83
|
+
)
|
|
84
|
+
except AuthenticationError as err:
|
|
85
|
+
# client.refresh()
|
|
86
|
+
print(err)
|
|
87
|
+
break
|
|
88
|
+
except Exception as err:
|
|
89
|
+
if "500" in str(err):
|
|
90
|
+
sleep(5)
|
|
91
|
+
node.save(
|
|
92
|
+
client,
|
|
93
|
+
space=target_space,
|
|
94
|
+
recursive=False,
|
|
95
|
+
ignore_duplicates=True,
|
|
96
|
+
activity_log=activity_log,
|
|
97
|
+
)
|
|
98
|
+
else:
|
|
99
|
+
raise
|
|
100
|
+
else:
|
|
101
|
+
with open(".kg_upload_log.txt", "a") as fp:
|
|
102
|
+
fp.write(f"{original_node_id}\n")
|
|
103
|
+
|
|
104
|
+
return activity_log
|
fairgraph/embedded.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides the EmbeddedMetadata class, which is the base class
|
|
3
|
+
for representations of structured metadata that do not have their own identifier,
|
|
4
|
+
but are rather embedded within another metadata instance.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Copyright 2018-2024 CNRS
|
|
8
|
+
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
import logging
|
|
23
|
+
from typing import Optional, TYPE_CHECKING, Union
|
|
24
|
+
from warnings import warn
|
|
25
|
+
|
|
26
|
+
from .utility import as_list, ActivityLog
|
|
27
|
+
from .base import Resolvable, JSONdict
|
|
28
|
+
from .node import ContainsMetadata
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from .client import KGClient
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger("fairgraph")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class EmbeddedMetadata(ContainsMetadata, Resolvable):
|
|
38
|
+
"""
|
|
39
|
+
Base class for metadata structures that are embedded in Knowledge Graph objects.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
data (dict, optional): a JSON-LD document containing the KG representation of the metadata.
|
|
43
|
+
properties: the metadata properties (property names and values)
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, data: Optional[JSONdict] = None, **properties):
|
|
47
|
+
super().__init__(data=data, **properties)
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def space(self) -> Union[str, None]:
|
|
51
|
+
"""The KG space the metadata is stored in."""
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def default_space(self) -> Union[str, None]:
|
|
56
|
+
"""The KG space new metadata will be stored in if no space is specified."""
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
def __repr__(self):
|
|
60
|
+
template_parts = (
|
|
61
|
+
"{}={{self.{}!r}}".format(prop.name, prop.name)
|
|
62
|
+
for prop in self.properties
|
|
63
|
+
if getattr(self, prop.name, None) is not None
|
|
64
|
+
)
|
|
65
|
+
template = "{self.__class__.__name__}(" + ", ".join(template_parts) + ")"
|
|
66
|
+
return template.format(self=self)
|
|
67
|
+
|
|
68
|
+
def __eq__(self, other):
|
|
69
|
+
return isinstance(other, self.__class__) and self.to_jsonld(embed_linked_nodes=False) == other.to_jsonld(
|
|
70
|
+
embed_linked_nodes=False
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def from_jsonld(cls, data: JSONdict) -> Union[None, EmbeddedMetadata]:
|
|
75
|
+
"""Create an instance of the class from a JSON-LD document."""
|
|
76
|
+
if "@id" in data:
|
|
77
|
+
warn("Expected embedded metadata, but received @id")
|
|
78
|
+
return None
|
|
79
|
+
deserialized_data = cls._deserialize_data(data)
|
|
80
|
+
return cls(data=data, **deserialized_data)
|
|
81
|
+
|
|
82
|
+
def save(
|
|
83
|
+
self,
|
|
84
|
+
client: KGClient,
|
|
85
|
+
space: Optional[str] = None,
|
|
86
|
+
recursive: bool = True,
|
|
87
|
+
activity_log: Optional[ActivityLog] = None,
|
|
88
|
+
replace: bool = False,
|
|
89
|
+
ignore_duplicates: bool = False,
|
|
90
|
+
):
|
|
91
|
+
"""
|
|
92
|
+
Save to the KG any sub-components of the metadata object that are KGObjects.
|
|
93
|
+
"""
|
|
94
|
+
for prop in self.properties:
|
|
95
|
+
values = getattr(self, prop.name)
|
|
96
|
+
for value in as_list(values):
|
|
97
|
+
if isinstance(value, ContainsMetadata):
|
|
98
|
+
if value.space:
|
|
99
|
+
target_space = value.space
|
|
100
|
+
elif (
|
|
101
|
+
value.__class__.default_space == "controlled"
|
|
102
|
+
and value.exists(client, ignore_duplicates=ignore_duplicates)
|
|
103
|
+
and value.space == "controlled"
|
|
104
|
+
):
|
|
105
|
+
continue
|
|
106
|
+
elif space is None and self.space is not None:
|
|
107
|
+
target_space = self.space
|
|
108
|
+
else:
|
|
109
|
+
assert space is not None # for type checking
|
|
110
|
+
target_space = space
|
|
111
|
+
if target_space == "controlled":
|
|
112
|
+
if value.exists(client, ignore_duplicates=ignore_duplicates) and value.space == "controlled":
|
|
113
|
+
continue
|
|
114
|
+
else:
|
|
115
|
+
raise Exception("Cannot write to controlled space")
|
|
116
|
+
value.save(
|
|
117
|
+
client,
|
|
118
|
+
space=target_space,
|
|
119
|
+
recursive=recursive,
|
|
120
|
+
activity_log=activity_log,
|
|
121
|
+
ignore_duplicates=ignore_duplicates,
|
|
122
|
+
)
|
fairgraph/errors.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Definition of specific Exceptions.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Copyright 2018-2024 CNRS
|
|
6
|
+
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ResourceExistsError(Exception):
|
|
21
|
+
"""Raised when trying to create a resource that already exists in the Knowledge Graph"""
|
|
22
|
+
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AuthenticationError(Exception):
|
|
27
|
+
"""Raised when there is a problem with authentication"""
|
|
28
|
+
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AuthorizationError(Exception):
|
|
33
|
+
"""Raised when there is a problem with authorization"""
|
|
34
|
+
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ResolutionFailure(Exception):
|
|
39
|
+
"""Raised when unable to resolve a link in the Knowledge Graph"""
|
|
40
|
+
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class CannotBuildExistenceQuery(Exception):
|
|
45
|
+
"""Raised when it is not possible to build an existence query"""
|
|
46
|
+
|
|
47
|
+
pass
|
fairgraph/fields.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from warnings import warn
|
|
2
|
+
|
|
3
|
+
from .properties import Property as Field
|
|
4
|
+
|
|
5
|
+
warn(
|
|
6
|
+
"The 'Field' class has been renamed to 'Property' "
|
|
7
|
+
"for consistency with openMINDS. "
|
|
8
|
+
"Use of 'Field' will still work until the next release, "
|
|
9
|
+
"when this alias will be removed.",
|
|
10
|
+
DeprecationWarning,
|
|
11
|
+
)
|