dsp-tools 0.9.13__py3-none-any.whl → 18.3.0.post13__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.
- dsp_tools/__init__.py +5 -0
- dsp_tools/cli/args.py +47 -0
- dsp_tools/cli/call_action.py +85 -0
- dsp_tools/cli/call_action_files_only.py +101 -0
- dsp_tools/cli/call_action_with_network.py +207 -0
- dsp_tools/cli/create_parsers.py +479 -0
- dsp_tools/cli/entry_point.py +322 -0
- dsp_tools/cli/utils.py +87 -0
- dsp_tools/clients/CLAUDE.md +420 -0
- dsp_tools/clients/authentication_client.py +14 -0
- dsp_tools/clients/authentication_client_live.py +66 -0
- dsp_tools/clients/connection.py +35 -0
- dsp_tools/clients/connection_live.py +233 -0
- dsp_tools/clients/fuseki_metrics.py +60 -0
- dsp_tools/clients/group_user_clients.py +35 -0
- dsp_tools/clients/group_user_clients_live.py +181 -0
- dsp_tools/clients/legal_info_client.py +23 -0
- dsp_tools/clients/legal_info_client_live.py +132 -0
- dsp_tools/clients/list_client.py +49 -0
- dsp_tools/clients/list_client_live.py +166 -0
- dsp_tools/clients/metadata_client.py +24 -0
- dsp_tools/clients/metadata_client_live.py +47 -0
- dsp_tools/clients/ontology_clients.py +49 -0
- dsp_tools/clients/ontology_create_client_live.py +166 -0
- dsp_tools/clients/ontology_get_client_live.py +80 -0
- dsp_tools/clients/permissions_client.py +68 -0
- dsp_tools/clients/project_client.py +16 -0
- dsp_tools/clients/project_client_live.py +66 -0
- dsp_tools/commands/create/communicate_problems.py +24 -0
- dsp_tools/commands/create/create.py +134 -0
- dsp_tools/commands/create/create_on_server/cardinalities.py +111 -0
- dsp_tools/commands/create/create_on_server/classes.py +99 -0
- dsp_tools/commands/create/create_on_server/complete_ontologies.py +116 -0
- dsp_tools/commands/create/create_on_server/default_permissions.py +134 -0
- dsp_tools/commands/create/create_on_server/group_users.py +165 -0
- dsp_tools/commands/create/create_on_server/lists.py +163 -0
- dsp_tools/commands/create/create_on_server/mappers.py +12 -0
- dsp_tools/commands/create/create_on_server/onto_utils.py +74 -0
- dsp_tools/commands/create/create_on_server/ontology.py +52 -0
- dsp_tools/commands/create/create_on_server/project.py +68 -0
- dsp_tools/commands/create/create_on_server/properties.py +119 -0
- dsp_tools/commands/create/exceptions.py +29 -0
- dsp_tools/commands/create/lists_only.py +66 -0
- dsp_tools/commands/create/models/create_problems.py +87 -0
- dsp_tools/commands/create/models/parsed_ontology.py +88 -0
- dsp_tools/commands/create/models/parsed_project.py +81 -0
- dsp_tools/commands/create/models/rdf_ontology.py +12 -0
- dsp_tools/commands/create/models/server_project_info.py +100 -0
- dsp_tools/commands/create/parsing/parse_lists.py +45 -0
- dsp_tools/commands/create/parsing/parse_ontology.py +243 -0
- dsp_tools/commands/create/parsing/parse_project.py +149 -0
- dsp_tools/commands/create/parsing/parsing_utils.py +40 -0
- dsp_tools/commands/create/project_validate.py +595 -0
- dsp_tools/commands/create/serialisation/ontology.py +119 -0
- dsp_tools/commands/create/serialisation/project.py +44 -0
- dsp_tools/commands/excel2json/CLAUDE.md +101 -0
- dsp_tools/commands/excel2json/json_header.py +321 -0
- dsp_tools/commands/excel2json/lists/__init__.py +0 -0
- dsp_tools/commands/excel2json/lists/compliance_checks.py +292 -0
- dsp_tools/commands/excel2json/lists/make_lists.py +247 -0
- dsp_tools/commands/excel2json/lists/models/__init__.py +0 -0
- dsp_tools/commands/excel2json/lists/models/deserialise.py +30 -0
- dsp_tools/commands/excel2json/lists/models/input_error.py +216 -0
- dsp_tools/commands/excel2json/lists/models/serialise.py +57 -0
- dsp_tools/commands/excel2json/lists/utils.py +81 -0
- dsp_tools/commands/excel2json/models/__init__.py +0 -0
- dsp_tools/commands/excel2json/models/input_error.py +416 -0
- dsp_tools/commands/excel2json/models/json_header.py +175 -0
- dsp_tools/commands/excel2json/models/list_node_name.py +16 -0
- dsp_tools/commands/excel2json/models/ontology.py +76 -0
- dsp_tools/commands/excel2json/old_lists.py +328 -0
- dsp_tools/commands/excel2json/project.py +280 -0
- dsp_tools/commands/excel2json/properties.py +370 -0
- dsp_tools/commands/excel2json/resources.py +336 -0
- dsp_tools/commands/excel2json/utils.py +352 -0
- dsp_tools/commands/excel2xml/__init__.py +7 -0
- dsp_tools/commands/excel2xml/excel2xml_cli.py +523 -0
- dsp_tools/commands/excel2xml/excel2xml_lib.py +1953 -0
- dsp_tools/commands/excel2xml/propertyelement.py +47 -0
- dsp_tools/commands/get/__init__.py +0 -0
- dsp_tools/commands/get/get.py +166 -0
- dsp_tools/commands/get/get_permissions.py +257 -0
- dsp_tools/commands/get/get_permissions_legacy.py +89 -0
- dsp_tools/commands/get/legacy_models/__init__.py +0 -0
- dsp_tools/commands/get/legacy_models/context.py +318 -0
- dsp_tools/commands/get/legacy_models/group.py +241 -0
- dsp_tools/commands/get/legacy_models/helpers.py +47 -0
- dsp_tools/commands/get/legacy_models/listnode.py +390 -0
- dsp_tools/commands/get/legacy_models/model.py +12 -0
- dsp_tools/commands/get/legacy_models/ontology.py +324 -0
- dsp_tools/commands/get/legacy_models/project.py +366 -0
- dsp_tools/commands/get/legacy_models/propertyclass.py +417 -0
- dsp_tools/commands/get/legacy_models/resourceclass.py +676 -0
- dsp_tools/commands/get/legacy_models/user.py +438 -0
- dsp_tools/commands/get/models/__init__.py +0 -0
- dsp_tools/commands/get/models/permissions_models.py +10 -0
- dsp_tools/commands/id2iri.py +258 -0
- dsp_tools/commands/ingest_xmlupload/__init__.py +0 -0
- dsp_tools/commands/ingest_xmlupload/bulk_ingest_client.py +178 -0
- dsp_tools/commands/ingest_xmlupload/create_resources/__init__.py +0 -0
- dsp_tools/commands/ingest_xmlupload/create_resources/apply_ingest_id.py +69 -0
- dsp_tools/commands/ingest_xmlupload/create_resources/upload_xml.py +166 -0
- dsp_tools/commands/ingest_xmlupload/create_resources/user_information.py +121 -0
- dsp_tools/commands/ingest_xmlupload/ingest_files/__init__.py +0 -0
- dsp_tools/commands/ingest_xmlupload/ingest_files/ingest_files.py +64 -0
- dsp_tools/commands/ingest_xmlupload/upload_files/__init__.py +0 -0
- dsp_tools/commands/ingest_xmlupload/upload_files/filechecker.py +20 -0
- dsp_tools/commands/ingest_xmlupload/upload_files/input_error.py +57 -0
- dsp_tools/commands/ingest_xmlupload/upload_files/upload_failures.py +66 -0
- dsp_tools/commands/ingest_xmlupload/upload_files/upload_files.py +67 -0
- dsp_tools/commands/resume_xmlupload/__init__.py +0 -0
- dsp_tools/commands/resume_xmlupload/resume_xmlupload.py +96 -0
- dsp_tools/commands/start_stack.py +428 -0
- dsp_tools/commands/update_legal/CLAUDE.md +344 -0
- dsp_tools/commands/update_legal/__init__.py +0 -0
- dsp_tools/commands/update_legal/core.py +182 -0
- dsp_tools/commands/update_legal/csv_operations.py +135 -0
- dsp_tools/commands/update_legal/models.py +87 -0
- dsp_tools/commands/update_legal/xml_operations.py +247 -0
- dsp_tools/commands/validate_data/CLAUDE.md +159 -0
- dsp_tools/commands/validate_data/__init__.py +0 -0
- dsp_tools/commands/validate_data/constants.py +59 -0
- dsp_tools/commands/validate_data/mappers.py +143 -0
- dsp_tools/commands/validate_data/models/__init__.py +0 -0
- dsp_tools/commands/validate_data/models/api_responses.py +45 -0
- dsp_tools/commands/validate_data/models/input_problems.py +119 -0
- dsp_tools/commands/validate_data/models/rdf_like_data.py +117 -0
- dsp_tools/commands/validate_data/models/validation.py +106 -0
- dsp_tools/commands/validate_data/prepare_data/__init__.py +0 -0
- dsp_tools/commands/validate_data/prepare_data/get_rdf_like_data.py +296 -0
- dsp_tools/commands/validate_data/prepare_data/make_data_graph.py +91 -0
- dsp_tools/commands/validate_data/prepare_data/prepare_data.py +184 -0
- dsp_tools/commands/validate_data/process_validation_report/__init__.py +0 -0
- dsp_tools/commands/validate_data/process_validation_report/get_user_validation_message.py +358 -0
- dsp_tools/commands/validate_data/process_validation_report/query_validation_result.py +507 -0
- dsp_tools/commands/validate_data/process_validation_report/reformat_validation_results.py +150 -0
- dsp_tools/commands/validate_data/shacl_cli_validator.py +70 -0
- dsp_tools/commands/validate_data/sparql/__init__.py +0 -0
- dsp_tools/commands/validate_data/sparql/cardinality_shacl.py +209 -0
- dsp_tools/commands/validate_data/sparql/construct_shacl.py +92 -0
- dsp_tools/commands/validate_data/sparql/legal_info_shacl.py +36 -0
- dsp_tools/commands/validate_data/sparql/value_shacl.py +357 -0
- dsp_tools/commands/validate_data/utils.py +59 -0
- dsp_tools/commands/validate_data/validate_data.py +283 -0
- dsp_tools/commands/validate_data/validation/__init__.py +0 -0
- dsp_tools/commands/validate_data/validation/check_duplicate_files.py +55 -0
- dsp_tools/commands/validate_data/validation/check_for_unknown_classes.py +67 -0
- dsp_tools/commands/validate_data/validation/get_validation_report.py +94 -0
- dsp_tools/commands/validate_data/validation/validate_ontology.py +107 -0
- dsp_tools/commands/xmlupload/CLAUDE.md +292 -0
- dsp_tools/commands/xmlupload/__init__.py +0 -0
- dsp_tools/commands/xmlupload/iri_resolver.py +21 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/__init__.py +0 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/constants.py +63 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/jsonld_utils.py +44 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/make_file_value.py +77 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/make_resource_and_values.py +114 -0
- dsp_tools/commands/xmlupload/make_rdf_graph/make_values.py +262 -0
- dsp_tools/commands/xmlupload/models/__init__.py +0 -0
- dsp_tools/commands/xmlupload/models/bitstream_info.py +18 -0
- dsp_tools/commands/xmlupload/models/formatted_text_value.py +10 -0
- dsp_tools/commands/xmlupload/models/ingest.py +143 -0
- dsp_tools/commands/xmlupload/models/input_problems.py +58 -0
- dsp_tools/commands/xmlupload/models/lookup_models.py +21 -0
- dsp_tools/commands/xmlupload/models/permission.py +45 -0
- dsp_tools/commands/xmlupload/models/permissions_parsed.py +93 -0
- dsp_tools/commands/xmlupload/models/processed/__init__.py +0 -0
- dsp_tools/commands/xmlupload/models/processed/file_values.py +29 -0
- dsp_tools/commands/xmlupload/models/processed/res.py +27 -0
- dsp_tools/commands/xmlupload/models/processed/values.py +101 -0
- dsp_tools/commands/xmlupload/models/rdf_models.py +26 -0
- dsp_tools/commands/xmlupload/models/upload_clients.py +14 -0
- dsp_tools/commands/xmlupload/models/upload_state.py +20 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/__init__.py +0 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/ark2iri.py +55 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/get_processed_resources.py +252 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/iiif_uri_validator.py +50 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/list_client.py +120 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/prepare_xml_input.py +67 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/read_validate_xml_file.py +58 -0
- dsp_tools/commands/xmlupload/prepare_xml_input/transform_input_values.py +118 -0
- dsp_tools/commands/xmlupload/resource_create_client.py +25 -0
- dsp_tools/commands/xmlupload/richtext_id2iri.py +37 -0
- dsp_tools/commands/xmlupload/stash/__init__.py +0 -0
- dsp_tools/commands/xmlupload/stash/analyse_circular_reference_graph.py +236 -0
- dsp_tools/commands/xmlupload/stash/create_info_for_graph.py +53 -0
- dsp_tools/commands/xmlupload/stash/graph_models.py +87 -0
- dsp_tools/commands/xmlupload/stash/stash_circular_references.py +68 -0
- dsp_tools/commands/xmlupload/stash/stash_models.py +109 -0
- dsp_tools/commands/xmlupload/stash/upload_stashed_resptr_props.py +106 -0
- dsp_tools/commands/xmlupload/stash/upload_stashed_xml_texts.py +196 -0
- dsp_tools/commands/xmlupload/upload_config.py +76 -0
- dsp_tools/commands/xmlupload/write_diagnostic_info.py +27 -0
- dsp_tools/commands/xmlupload/xmlupload.py +516 -0
- dsp_tools/config/__init__.py +0 -0
- dsp_tools/config/logger_config.py +69 -0
- dsp_tools/config/warnings_config.py +32 -0
- dsp_tools/error/__init__.py +0 -0
- dsp_tools/error/custom_warnings.py +39 -0
- dsp_tools/error/exceptions.py +204 -0
- dsp_tools/error/problems.py +10 -0
- dsp_tools/error/xmllib_errors.py +20 -0
- dsp_tools/error/xmllib_warnings.py +54 -0
- dsp_tools/error/xmllib_warnings_util.py +159 -0
- dsp_tools/error/xsd_validation_error_msg.py +19 -0
- dsp_tools/legacy_models/__init__.py +0 -0
- dsp_tools/legacy_models/datetimestamp.py +81 -0
- dsp_tools/legacy_models/langstring.py +253 -0
- dsp_tools/legacy_models/projectContext.py +49 -0
- dsp_tools/py.typed +0 -0
- dsp_tools/resources/schema/data.xsd +648 -0
- dsp_tools/resources/schema/lists-only.json +72 -0
- dsp_tools/resources/schema/project.json +1258 -0
- dsp_tools/resources/schema/properties-only.json +874 -0
- dsp_tools/resources/schema/resources-only.json +140 -0
- dsp_tools/resources/start-stack/docker-compose.override-host.j2 +11 -0
- dsp_tools/resources/start-stack/docker-compose.override.yml +11 -0
- dsp_tools/resources/start-stack/docker-compose.yml +88 -0
- dsp_tools/resources/start-stack/dsp-app-config.json +45 -0
- dsp_tools/resources/start-stack/dsp-app-config.override-host.j2 +26 -0
- dsp_tools/resources/validate_data/api-shapes-resource-cardinalities.ttl +191 -0
- dsp_tools/resources/validate_data/api-shapes.ttl +804 -0
- dsp_tools/resources/validate_data/shacl-cli-image.yml +4 -0
- dsp_tools/resources/validate_data/validate-ontology.ttl +99 -0
- dsp_tools/utils/__init__.py +0 -0
- dsp_tools/utils/ansi_colors.py +32 -0
- dsp_tools/utils/data_formats/__init__.py +0 -0
- dsp_tools/utils/data_formats/date_util.py +166 -0
- dsp_tools/utils/data_formats/iri_util.py +30 -0
- dsp_tools/utils/data_formats/shared.py +81 -0
- dsp_tools/utils/data_formats/uri_util.py +76 -0
- dsp_tools/utils/fuseki_bloating.py +63 -0
- dsp_tools/utils/json_parsing.py +22 -0
- dsp_tools/utils/rdf_constants.py +42 -0
- dsp_tools/utils/rdflib_utils.py +10 -0
- dsp_tools/utils/replace_id_with_iri.py +66 -0
- dsp_tools/utils/request_utils.py +238 -0
- dsp_tools/utils/xml_parsing/__init__.py +0 -0
- dsp_tools/utils/xml_parsing/get_lookups.py +32 -0
- dsp_tools/utils/xml_parsing/get_parsed_resources.py +325 -0
- dsp_tools/utils/xml_parsing/models/__init__.py +0 -0
- dsp_tools/utils/xml_parsing/models/parsed_resource.py +76 -0
- dsp_tools/utils/xml_parsing/parse_clean_validate_xml.py +137 -0
- dsp_tools/xmllib/CLAUDE.md +302 -0
- dsp_tools/xmllib/__init__.py +49 -0
- dsp_tools/xmllib/general_functions.py +877 -0
- dsp_tools/xmllib/internal/__init__.py +0 -0
- dsp_tools/xmllib/internal/checkers.py +162 -0
- dsp_tools/xmllib/internal/circumvent_circular_imports.py +36 -0
- dsp_tools/xmllib/internal/constants.py +46 -0
- dsp_tools/xmllib/internal/input_converters.py +155 -0
- dsp_tools/xmllib/internal/serialise_file_value.py +57 -0
- dsp_tools/xmllib/internal/serialise_resource.py +177 -0
- dsp_tools/xmllib/internal/serialise_values.py +152 -0
- dsp_tools/xmllib/internal/type_aliases.py +11 -0
- dsp_tools/xmllib/models/__init__.py +0 -0
- dsp_tools/xmllib/models/config_options.py +28 -0
- dsp_tools/xmllib/models/date_formats.py +48 -0
- dsp_tools/xmllib/models/dsp_base_resources.py +1542 -0
- dsp_tools/xmllib/models/internal/__init__.py +0 -0
- dsp_tools/xmllib/models/internal/file_values.py +172 -0
- dsp_tools/xmllib/models/internal/geometry.py +162 -0
- dsp_tools/xmllib/models/internal/migration_metadata.py +55 -0
- dsp_tools/xmllib/models/internal/serialise_permissions.py +66 -0
- dsp_tools/xmllib/models/internal/values.py +342 -0
- dsp_tools/xmllib/models/licenses/__init__.py +0 -0
- dsp_tools/xmllib/models/licenses/other.py +59 -0
- dsp_tools/xmllib/models/licenses/recommended.py +107 -0
- dsp_tools/xmllib/models/permissions.py +41 -0
- dsp_tools/xmllib/models/res.py +1782 -0
- dsp_tools/xmllib/models/root.py +348 -0
- dsp_tools/xmllib/value_checkers.py +434 -0
- dsp_tools/xmllib/value_converters.py +777 -0
- dsp_tools-18.3.0.post13.dist-info/METADATA +90 -0
- dsp_tools-18.3.0.post13.dist-info/RECORD +286 -0
- dsp_tools-18.3.0.post13.dist-info/WHEEL +4 -0
- dsp_tools-18.3.0.post13.dist-info/entry_points.txt +3 -0
- dsp_tools-0.9.13.dist-info/LICENSE +0 -674
- dsp_tools-0.9.13.dist-info/METADATA +0 -144
- dsp_tools-0.9.13.dist-info/RECORD +0 -71
- dsp_tools-0.9.13.dist-info/WHEEL +0 -5
- dsp_tools-0.9.13.dist-info/entry_points.txt +0 -3
- dsp_tools-0.9.13.dist-info/top_level.txt +0 -1
- dsplib/models/connection.py +0 -272
- dsplib/models/group.py +0 -296
- dsplib/models/helpers.py +0 -505
- dsplib/models/langstring.py +0 -277
- dsplib/models/listnode.py +0 -578
- dsplib/models/model.py +0 -20
- dsplib/models/ontology.py +0 -448
- dsplib/models/permission.py +0 -112
- dsplib/models/project.py +0 -547
- dsplib/models/propertyclass.py +0 -505
- dsplib/models/resource.py +0 -366
- dsplib/models/resourceclass.py +0 -810
- dsplib/models/sipi.py +0 -30
- dsplib/models/user.py +0 -731
- dsplib/models/value.py +0 -1000
- dsplib/utils/knora-data-schema.xsd +0 -454
- dsplib/utils/knora-schema-lists.json +0 -83
- dsplib/utils/knora-schema.json +0 -434
- dsplib/utils/onto_commons.py +0 -24
- dsplib/utils/onto_create_lists.py +0 -73
- dsplib/utils/onto_create_ontology.py +0 -442
- dsplib/utils/onto_get.py +0 -58
- dsplib/utils/onto_validate.py +0 -33
- dsplib/utils/xml_upload.py +0 -539
- dsplib/widgets/doublepassword.py +0 -80
- knora/MLS-import-libraries.py +0 -84
- knora/dsp_tools.py +0 -96
- knora/dsplib/models/connection.py +0 -272
- knora/dsplib/models/group.py +0 -296
- knora/dsplib/models/helpers.py +0 -506
- knora/dsplib/models/langstring.py +0 -277
- knora/dsplib/models/listnode.py +0 -578
- knora/dsplib/models/model.py +0 -20
- knora/dsplib/models/ontology.py +0 -448
- knora/dsplib/models/permission.py +0 -112
- knora/dsplib/models/project.py +0 -583
- knora/dsplib/models/propertyclass.py +0 -505
- knora/dsplib/models/resource.py +0 -416
- knora/dsplib/models/resourceclass.py +0 -811
- knora/dsplib/models/sipi.py +0 -35
- knora/dsplib/models/user.py +0 -731
- knora/dsplib/models/value.py +0 -1000
- knora/dsplib/utils/knora-data-schema.xsd +0 -464
- knora/dsplib/utils/knora-schema-lists.json +0 -83
- knora/dsplib/utils/knora-schema.json +0 -444
- knora/dsplib/utils/onto_commons.py +0 -24
- knora/dsplib/utils/onto_create_lists.py +0 -73
- knora/dsplib/utils/onto_create_ontology.py +0 -451
- knora/dsplib/utils/onto_get.py +0 -58
- knora/dsplib/utils/onto_validate.py +0 -33
- knora/dsplib/utils/xml_upload.py +0 -540
- knora/dsplib/widgets/doublepassword.py +0 -80
- knora/knora.py +0 -2108
- knora/test.py +0 -99
- knora/testit.py +0 -76
- knora/xml2knora.py +0 -633
- {dsplib → dsp_tools/cli}/__init__.py +0 -0
- {dsplib/models → dsp_tools/clients}/__init__.py +0 -0
- {dsplib/utils → dsp_tools/commands}/__init__.py +0 -0
- {dsplib/widgets → dsp_tools/commands/create}/__init__.py +0 -0
- {knora → dsp_tools/commands/create/create_on_server}/__init__.py +0 -0
- {knora/dsplib → dsp_tools/commands/create/models}/__init__.py +0 -0
- {knora/dsplib/models → dsp_tools/commands/create/parsing}/__init__.py +0 -0
- {knora/dsplib/utils → dsp_tools/commands/create/serialisation}/__init__.py +0 -0
- {knora/dsplib/widgets → dsp_tools/commands/excel2json}/__init__.py +0 -0
dsplib/models/ontology.py
DELETED
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import copy
|
|
3
|
-
from pystrict import strict
|
|
4
|
-
from typing import List, Set, Dict, Tuple, Optional, Any, Union
|
|
5
|
-
from urllib.parse import quote_plus
|
|
6
|
-
|
|
7
|
-
from .connection import Connection
|
|
8
|
-
from .helpers import Actions, BaseError, Context, LastModificationDate, OntoInfo
|
|
9
|
-
from .model import Model
|
|
10
|
-
from .project import Project
|
|
11
|
-
from .propertyclass import PropertyClass
|
|
12
|
-
from .resourceclass import ResourceClass
|
|
13
|
-
|
|
14
|
-
class SetEncoder(json.JSONEncoder):
|
|
15
|
-
def default(self, obj):
|
|
16
|
-
if isinstance(obj, set):
|
|
17
|
-
return list(obj)
|
|
18
|
-
elif isinstance(obj, Context):
|
|
19
|
-
return obj.toJsonObj()
|
|
20
|
-
elif isinstance(obj, OntoInfo):
|
|
21
|
-
return {"iri": obj.iri, "hashtag": obj.hashtag}
|
|
22
|
-
return json.JSONEncoder.default(self, obj)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"""
|
|
26
|
-
This model implements the handling of ontologies. It is to note that ResourceClasses, PropertyClasses
|
|
27
|
-
as well as the assignment of PropertyCLasses to the ResourceClasses (with a given cardinality)
|
|
28
|
-
is handeld in "cooperation" with the propertyclass.py (PropertyClass) and resourceclass.py (ResourceClass
|
|
29
|
-
and HasProperty) modules.
|
|
30
|
-
|
|
31
|
-
_Note_: All modifications to an ontology
|
|
32
|
-
|
|
33
|
-
CREATE:
|
|
34
|
-
* Instantiate a new object of the Ontology class with all required parameters
|
|
35
|
-
* Call the ``create``-method on the instance to create the ontology withing the backend
|
|
36
|
-
|
|
37
|
-
READ:
|
|
38
|
-
* Instantiate a new object with ``id``(IRI of ontology) given
|
|
39
|
-
* Call the ``read``-method on the instance. Reading the ontology also reads all
|
|
40
|
-
associated PropertyClasses and ResourceClasses as well as the assignments.
|
|
41
|
-
* Access the information that has been provided to the instance
|
|
42
|
-
|
|
43
|
-
UPDATE:
|
|
44
|
-
* You need an instance of an existing Ontology by reading an instance
|
|
45
|
-
* Change the attributes by assigning the new values
|
|
46
|
-
* Call the ``update```method on the instance
|
|
47
|
-
|
|
48
|
-
DELETE
|
|
49
|
-
* Instantiate a new objects with ``id``(IRI of group) given, or use any instance that has the id set,
|
|
50
|
-
that is, that You've read before
|
|
51
|
-
* Call the ``delete``-method on the instance
|
|
52
|
-
|
|
53
|
-
"""
|
|
54
|
-
@strict
|
|
55
|
-
class Ontology(Model):
|
|
56
|
-
_id: str
|
|
57
|
-
_project: str
|
|
58
|
-
_name: str
|
|
59
|
-
_label: str
|
|
60
|
-
_comment: str
|
|
61
|
-
_lastModificationDate: LastModificationDate
|
|
62
|
-
_resource_classes: List[ResourceClass]
|
|
63
|
-
_property_classes: List[PropertyClass]
|
|
64
|
-
_context: Context
|
|
65
|
-
_skiplist: List[str]
|
|
66
|
-
|
|
67
|
-
def __init__(self,
|
|
68
|
-
con: Connection,
|
|
69
|
-
id: Optional[str] = None,
|
|
70
|
-
project: Optional[Union[str, Project]] = None,
|
|
71
|
-
name: Optional[str] = None,
|
|
72
|
-
label: Optional[str] = None,
|
|
73
|
-
comment: Optional[str] = None,
|
|
74
|
-
lastModificationDate: Optional[Union[str, LastModificationDate]] = None,
|
|
75
|
-
resource_classes: List[ResourceClass] = [],
|
|
76
|
-
property_classes: List[PropertyClass] = [],
|
|
77
|
-
context: Context = None):
|
|
78
|
-
super().__init__(con)
|
|
79
|
-
self._id = id
|
|
80
|
-
if isinstance(project, Project):
|
|
81
|
-
self._project = project.id
|
|
82
|
-
else:
|
|
83
|
-
self._project = project
|
|
84
|
-
self._name = name
|
|
85
|
-
self._label = label
|
|
86
|
-
self._comment = comment
|
|
87
|
-
if lastModificationDate is None:
|
|
88
|
-
self._lastModificationDate = None
|
|
89
|
-
elif isinstance(lastModificationDate, LastModificationDate):
|
|
90
|
-
self._lastModificationDate = lastModificationDate
|
|
91
|
-
else:
|
|
92
|
-
self._lastModificationDate = LastModificationDate(lastModificationDate)
|
|
93
|
-
self._resource_classes = resource_classes
|
|
94
|
-
self._property_classes = property_classes
|
|
95
|
-
self._context = context if context is not None else Context()
|
|
96
|
-
self._skiplist = []
|
|
97
|
-
|
|
98
|
-
@property
|
|
99
|
-
def id(self) -> str:
|
|
100
|
-
return self._id
|
|
101
|
-
|
|
102
|
-
@id.setter
|
|
103
|
-
def id(self, value: str):
|
|
104
|
-
raise BaseError('Ontology id cannot be modified!')
|
|
105
|
-
|
|
106
|
-
@property
|
|
107
|
-
def project(self) -> str:
|
|
108
|
-
return self._project
|
|
109
|
-
|
|
110
|
-
@project.setter
|
|
111
|
-
def project(self, value: str):
|
|
112
|
-
raise BaseError("An ontology's project cannot be modified!")
|
|
113
|
-
|
|
114
|
-
@property
|
|
115
|
-
def name(self) -> str:
|
|
116
|
-
return self._name
|
|
117
|
-
|
|
118
|
-
@name.setter
|
|
119
|
-
def name(self, value: str):
|
|
120
|
-
raise BaseError("An ontology's name cannot be modified!")
|
|
121
|
-
|
|
122
|
-
@property
|
|
123
|
-
def label(self):
|
|
124
|
-
return self._label
|
|
125
|
-
|
|
126
|
-
@label.setter
|
|
127
|
-
def label(self, value: str):
|
|
128
|
-
self._label = str(value)
|
|
129
|
-
self._changed.add('label')
|
|
130
|
-
|
|
131
|
-
@property
|
|
132
|
-
def comment(self):
|
|
133
|
-
return self._comment
|
|
134
|
-
|
|
135
|
-
@comment.setter
|
|
136
|
-
def comment(self, value: str):
|
|
137
|
-
self._comment = str(value)
|
|
138
|
-
self._changed.add('comment')
|
|
139
|
-
|
|
140
|
-
@property
|
|
141
|
-
def lastModificationDate(self) -> LastModificationDate:
|
|
142
|
-
return self._lastModificationDate
|
|
143
|
-
|
|
144
|
-
@lastModificationDate.setter
|
|
145
|
-
def lastModificationDate(self, value: Union[str, LastModificationDate]):
|
|
146
|
-
self._lastModificationDate = LastModificationDate(value)
|
|
147
|
-
|
|
148
|
-
@property
|
|
149
|
-
def resource_classes(self) -> List[ResourceClass]:
|
|
150
|
-
return self._resource_classes
|
|
151
|
-
|
|
152
|
-
@resource_classes.setter
|
|
153
|
-
def resource_classes(self, value: List[ResourceClass]) -> None:
|
|
154
|
-
self._resource_classes = value
|
|
155
|
-
|
|
156
|
-
def addResourceClass(self, resourceclass: ResourceClass, create: bool = False) -> Tuple[int, ResourceClass]:
|
|
157
|
-
if create:
|
|
158
|
-
print('Calling resourceclass.create in Ontology.addResourceClass')
|
|
159
|
-
lmd, resourceclass = resourceclass.create(self._lastModificationDate)
|
|
160
|
-
self._lastModificationDate = lmd
|
|
161
|
-
self._resource_classes.append(resourceclass)
|
|
162
|
-
index = len(self._resource_classes) - 1
|
|
163
|
-
return index, resourceclass
|
|
164
|
-
|
|
165
|
-
def updateResourceClass(self, index: int, resourceclass: ResourceClass) -> ResourceClass:
|
|
166
|
-
lmd, resourceclass = resourceclass.update(self._lastModificationDate)
|
|
167
|
-
self._lastModificationDate = lmd
|
|
168
|
-
self._resource_classes[index] = resourceclass
|
|
169
|
-
return resourceclass
|
|
170
|
-
|
|
171
|
-
def removeResourceClass(self, index: int, erase: bool = False) -> None:
|
|
172
|
-
if erase:
|
|
173
|
-
lmd = self._resource_classes[index].delete(self._lastModificationDate)
|
|
174
|
-
self._lastModificationDate = lmd
|
|
175
|
-
del self._resource_classes[index]
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
@property
|
|
179
|
-
def property_classes(self) -> List[PropertyClass]:
|
|
180
|
-
return self._property_classes
|
|
181
|
-
|
|
182
|
-
@property_classes.setter
|
|
183
|
-
def property_classes(self, value: List[PropertyClass]):
|
|
184
|
-
self._property_classes = value
|
|
185
|
-
|
|
186
|
-
def addPropertyClass(self, propclass: PropertyClass, create: bool = False) -> Tuple[int, ResourceClass]:
|
|
187
|
-
if create:
|
|
188
|
-
lmd, resourceclass = propclass.create(self._lastModificationDate)
|
|
189
|
-
self._lastModificationDate = lmd
|
|
190
|
-
self._property_classes.append(resourceclass)
|
|
191
|
-
index = len(self._property_classes) - 1
|
|
192
|
-
return index, propclass
|
|
193
|
-
|
|
194
|
-
def updatePropertyClass(self, index: int, propclass: PropertyClass) -> PropertyClass:
|
|
195
|
-
lmd, propclass = propclass.update(self._lastModificationDate)
|
|
196
|
-
self._lastModificationDate = lmd
|
|
197
|
-
self._property_classes[index] = propclass
|
|
198
|
-
return propclass
|
|
199
|
-
|
|
200
|
-
def removePropertyClass(self, index: int, erase: bool = False) -> None:
|
|
201
|
-
if erase:
|
|
202
|
-
lmd = self._property_classes[index].delete(self._lastModificationDate)
|
|
203
|
-
self._lastModificationDate = lmd
|
|
204
|
-
del self._property_classes[index]
|
|
205
|
-
|
|
206
|
-
@property
|
|
207
|
-
def context(self):
|
|
208
|
-
return self._context
|
|
209
|
-
|
|
210
|
-
@context.setter
|
|
211
|
-
def context(self, value: Context):
|
|
212
|
-
raise BaseError('"Context" cannot be set!')
|
|
213
|
-
|
|
214
|
-
@classmethod
|
|
215
|
-
def fromJsonObj(cls, con: Connection, json_obj: Any) -> 'Ontology':
|
|
216
|
-
#
|
|
217
|
-
# First let's get the ID (IRI) of the ontology
|
|
218
|
-
#
|
|
219
|
-
id = json_obj.get('@id')
|
|
220
|
-
if id is None:
|
|
221
|
-
raise BaseError('Ontology id is missing')
|
|
222
|
-
|
|
223
|
-
#
|
|
224
|
-
# evaluate the JSON-LD context to get the proper prefixes
|
|
225
|
-
#
|
|
226
|
-
context = Context(json_obj.get('@context'))
|
|
227
|
-
onto_name = id.split('/')[-2]
|
|
228
|
-
context.add_context(onto_name, id + '#')
|
|
229
|
-
rdf = context.prefix_from_iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
|
230
|
-
rdfs = context.prefix_from_iri("http://www.w3.org/2000/01/rdf-schema#")
|
|
231
|
-
owl = context.prefix_from_iri("http://www.w3.org/2002/07/owl#")
|
|
232
|
-
xsd = context.prefix_from_iri("http://www.w3.org/2001/XMLSchema#")
|
|
233
|
-
knora_api = context.prefix_from_iri("http://api.knora.org/ontology/knora-api/v2#")
|
|
234
|
-
salsah_gui = context.prefix_from_iri("http://api.knora.org/ontology/salsah-gui/v2#")
|
|
235
|
-
this_onto = context.prefix_from_iri(id + "#")
|
|
236
|
-
|
|
237
|
-
label = json_obj.get(rdfs + ':label')
|
|
238
|
-
if label is None:
|
|
239
|
-
raise BaseError('Ontology label is missing')
|
|
240
|
-
comment = json_obj.get(rdfs + ':comment')
|
|
241
|
-
if json_obj.get(knora_api + ':attachedToProject') is None:
|
|
242
|
-
raise BaseError('Ontology not attached to a project')
|
|
243
|
-
if json_obj[knora_api + ':attachedToProject'].get('@id') is None:
|
|
244
|
-
raise BaseError('Ontology not attached to a project')
|
|
245
|
-
project = json_obj[knora_api + ':attachedToProject']['@id']
|
|
246
|
-
tmp = json_obj.get(knora_api + ':lastModificationDate')
|
|
247
|
-
if tmp is not None:
|
|
248
|
-
last_modification_date = LastModificationDate(json_obj.get(knora_api + ':lastModificationDate'))
|
|
249
|
-
else:
|
|
250
|
-
last_modification_date = None
|
|
251
|
-
resource_classes = None
|
|
252
|
-
property_classes = None
|
|
253
|
-
if json_obj.get('@graph') is not None:
|
|
254
|
-
resclasses_obj = list(filter(lambda a: a.get(knora_api + ':isResourceClass') is not None, json_obj.get('@graph')))
|
|
255
|
-
resource_classes = list(map(lambda a: ResourceClass.fromJsonObj(con=con,
|
|
256
|
-
context=context,
|
|
257
|
-
json_obj=a), resclasses_obj))
|
|
258
|
-
standoffclasses_obj = list(filter(lambda a: a.get(knora_api + ':isStandoffClass') is not None, json_obj.get('@graph')))
|
|
259
|
-
# ToDo: parse standoff classes
|
|
260
|
-
|
|
261
|
-
properties_obj = list(filter(lambda a: a.get(knora_api + ':isResourceProperty') is not None, json_obj.get('@graph')))
|
|
262
|
-
property_classes = list(map(lambda a: PropertyClass.fromJsonObj(con=con,
|
|
263
|
-
context=context,
|
|
264
|
-
json_obj=a), properties_obj))
|
|
265
|
-
return cls(con=con,
|
|
266
|
-
id=id,
|
|
267
|
-
label=label,
|
|
268
|
-
project=project,
|
|
269
|
-
name=this_onto, # TODO: corresponds the prefix always to the ontology name?
|
|
270
|
-
comment=comment,
|
|
271
|
-
lastModificationDate=last_modification_date,
|
|
272
|
-
resource_classes=resource_classes,
|
|
273
|
-
property_classes=property_classes,
|
|
274
|
-
context=context)
|
|
275
|
-
|
|
276
|
-
@classmethod
|
|
277
|
-
def __oneOntologiesFromJsonObj(cls, con: Connection, json_obj: Any, context: Context) -> 'Ontology':
|
|
278
|
-
rdf = context.prefix_from_iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
|
279
|
-
rdfs = context.prefix_from_iri("http://www.w3.org/2000/01/rdf-schema#")
|
|
280
|
-
owl = context.prefix_from_iri("http://www.w3.org/2002/07/owl#")
|
|
281
|
-
xsd = context.prefix_from_iri("http://www.w3.org/2001/XMLSchema#")
|
|
282
|
-
knora_api = context.prefix_from_iri("http://api.knora.org/ontology/knora-api/v2#")
|
|
283
|
-
salsah_gui = context.prefix_from_iri("http://api.knora.org/ontology/salsah-gui/v2#")
|
|
284
|
-
if json_obj.get('@type') != owl + ':Ontology':
|
|
285
|
-
return None
|
|
286
|
-
id = json_obj.get('@id')
|
|
287
|
-
if id is None:
|
|
288
|
-
raise BaseError('Ontology id is missing')
|
|
289
|
-
if json_obj.get(knora_api + ':attachedToProject') is None:
|
|
290
|
-
raise BaseError('Ontology not attached to a project (1)')
|
|
291
|
-
if json_obj[knora_api + ':attachedToProject'].get('@id') is None:
|
|
292
|
-
raise BaseError('Ontology not attached to a project (2)')
|
|
293
|
-
project = json_obj[knora_api + ':attachedToProject']['@id']
|
|
294
|
-
tmp = json_obj.get(knora_api + ':lastModificationDate')
|
|
295
|
-
if tmp is not None:
|
|
296
|
-
last_modification_date = LastModificationDate(json_obj.get(knora_api + ':lastModificationDate'))
|
|
297
|
-
else:
|
|
298
|
-
last_modification_date = None
|
|
299
|
-
label = json_obj.get(rdfs + ':label')
|
|
300
|
-
if label is None:
|
|
301
|
-
raise BaseError('Ontology label is missing')
|
|
302
|
-
comment = json_obj.get(rdfs + ':comment')
|
|
303
|
-
this_onto = id.split('/')[-2]
|
|
304
|
-
context2 = copy.deepcopy(context)
|
|
305
|
-
context2.add_context(this_onto, id)
|
|
306
|
-
return cls(con=con,
|
|
307
|
-
id=id,
|
|
308
|
-
label=label,
|
|
309
|
-
project=project,
|
|
310
|
-
name=this_onto,
|
|
311
|
-
comment=comment,
|
|
312
|
-
lastModificationDate=last_modification_date,
|
|
313
|
-
context=context2)
|
|
314
|
-
|
|
315
|
-
@classmethod
|
|
316
|
-
def allOntologiesFromJsonObj(cls, con: Connection, json_obj: Any) -> List['Ontology']:
|
|
317
|
-
context = Context(json_obj.get('@context'))
|
|
318
|
-
rdf = context.prefix_from_iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
|
319
|
-
rdfs = context.prefix_from_iri("http://www.w3.org/2000/01/rdf-schema#")
|
|
320
|
-
owl = context.prefix_from_iri("http://www.w3.org/2002/07/owl#")
|
|
321
|
-
xsd = context.prefix_from_iri("http://www.w3.org/2001/XMLSchema#")
|
|
322
|
-
knora_api = context.prefix_from_iri("http://api.knora.org/ontology/knora-api/v2#")
|
|
323
|
-
salsah_gui = context.prefix_from_iri("http://api.knora.org/ontology/salsah-gui/v2#")
|
|
324
|
-
ontos: List['Ontology'] = []
|
|
325
|
-
if json_obj.get('@graph') is not None:
|
|
326
|
-
for o in json_obj['@graph']:
|
|
327
|
-
ontos.append(Ontology.__oneOntologiesFromJsonObj(con, o, context))
|
|
328
|
-
else:
|
|
329
|
-
onto = Ontology.__oneOntologiesFromJsonObj(con, json_obj, context)
|
|
330
|
-
if onto is not None:
|
|
331
|
-
ontos.append(onto)
|
|
332
|
-
return ontos
|
|
333
|
-
|
|
334
|
-
def toJsonObj(self, action: Actions) -> Any:
|
|
335
|
-
rdf = self._context.prefix_from_iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
|
336
|
-
rdfs = self._context.prefix_from_iri("http://www.w3.org/2000/01/rdf-schema#")
|
|
337
|
-
owl = self._context.prefix_from_iri("http://www.w3.org/2002/07/owl#")
|
|
338
|
-
xsd = self._context.prefix_from_iri("http://www.w3.org/2001/XMLSchema#")
|
|
339
|
-
knora_api = self._context.prefix_from_iri("http://api.knora.org/ontology/knora-api/v2#")
|
|
340
|
-
salsah_gui = self._context.prefix_from_iri("http://api.knora.org/ontology/salsah-gui/v2#")
|
|
341
|
-
# this_onto = self._context.prefixFromIri(self._id + "#")
|
|
342
|
-
tmp = {}
|
|
343
|
-
if action == Actions.Create:
|
|
344
|
-
if self._name is None:
|
|
345
|
-
raise BaseError('There must be a valid name given!')
|
|
346
|
-
if self._label is None:
|
|
347
|
-
raise BaseError('There must be a valid label given!')
|
|
348
|
-
if self._project is None:
|
|
349
|
-
raise BaseError('There must be a valid project given!')
|
|
350
|
-
tmp = {
|
|
351
|
-
knora_api + ":ontologyName": self._name,
|
|
352
|
-
knora_api + ":attachedToProject": {
|
|
353
|
-
"@id": self._project
|
|
354
|
-
},
|
|
355
|
-
rdfs + ":label": self._label,
|
|
356
|
-
"@context": self._context.toJsonObj()
|
|
357
|
-
}
|
|
358
|
-
if self._comment is not None:
|
|
359
|
-
tmp[rdfs + ":comment"] = self._comment
|
|
360
|
-
elif action == Actions.Update:
|
|
361
|
-
if self._lastModificationDate is None:
|
|
362
|
-
raise BaseError("'last_modification_date' must be in ontology!")
|
|
363
|
-
tmp = {
|
|
364
|
-
'@id': self._id,
|
|
365
|
-
rdfs + ':label': self._label,
|
|
366
|
-
knora_api + ':lastModificationDate': self._lastModificationDate.toJsonObj(),
|
|
367
|
-
"@context": self._context.toJsonObj()
|
|
368
|
-
}
|
|
369
|
-
if self._label is not None and 'label' in self._changed:
|
|
370
|
-
tmp[rdfs + ':label'] = self._label
|
|
371
|
-
if self._comment is not None and 'comment' in self._changed:
|
|
372
|
-
tmp[rdfs + ':comment'] = self._comment
|
|
373
|
-
return tmp
|
|
374
|
-
|
|
375
|
-
def create(self, dumpjson: Optional[str] = None) -> 'Ontology':
|
|
376
|
-
jsonobj = self.toJsonObj(Actions.Create)
|
|
377
|
-
jsondata = json.dumps(jsonobj, cls=SetEncoder, indent=4)
|
|
378
|
-
result = self._con.post('/v2/ontologies', jsondata)
|
|
379
|
-
return Ontology.fromJsonObj(self._con, result)
|
|
380
|
-
|
|
381
|
-
def update(self) -> 'Ontology':
|
|
382
|
-
jsonobj = self.toJsonObj(Actions.Update)
|
|
383
|
-
jsondata = json.dumps(jsonobj, cls=SetEncoder, indent=4)
|
|
384
|
-
result = self._con.put('/v2/ontologies/metadata', jsondata, 'application/ld+json')
|
|
385
|
-
return Ontology.fromJsonObj(self._con, result)
|
|
386
|
-
|
|
387
|
-
def read(self) -> 'Ontology':
|
|
388
|
-
result = self._con.get('/v2/ontologies/allentities/' + quote_plus(self._id) + '?allLanguages=true')
|
|
389
|
-
return Ontology.fromJsonObj(self._con, result)
|
|
390
|
-
|
|
391
|
-
def delete(self) -> Optional[str]:
|
|
392
|
-
result = self._con.delete('/v2/ontologies/' + quote_plus(self._id),
|
|
393
|
-
params={'lastModificationDate': str(self._lastModificationDate)})
|
|
394
|
-
return result.get('knora-api:result')
|
|
395
|
-
|
|
396
|
-
@staticmethod
|
|
397
|
-
def getAllOntologies(con: Connection) -> List['Ontology']:
|
|
398
|
-
result = con.get('/v2/ontologies/metadata/')
|
|
399
|
-
return Ontology.allOntologiesFromJsonObj(con, result)
|
|
400
|
-
|
|
401
|
-
@staticmethod
|
|
402
|
-
def getProjectOntologies(con: Connection, project_id: str) -> List['Ontology']:
|
|
403
|
-
if project_id is None:
|
|
404
|
-
raise BaseError('Project ID must be defined!')
|
|
405
|
-
result = con.get('/v2/ontologies/metadata/' + quote_plus(project_id) + '?allLanguages=true')
|
|
406
|
-
return Ontology.allOntologiesFromJsonObj(con, result)
|
|
407
|
-
|
|
408
|
-
@staticmethod
|
|
409
|
-
def getOntologyFromServer(con: Connection, shortcode: str, name: str) -> 'Ontology':
|
|
410
|
-
result = con.get("/ontology/" + shortcode + "/" + name + "/v2")
|
|
411
|
-
return Ontology.fromJsonObj(con, result)
|
|
412
|
-
|
|
413
|
-
def createDefinitionFileObj(self):
|
|
414
|
-
ontology = {
|
|
415
|
-
"name": self._name,
|
|
416
|
-
"label": self._label,
|
|
417
|
-
"properties": [],
|
|
418
|
-
"resources": []
|
|
419
|
-
}
|
|
420
|
-
if self._comment is not None:
|
|
421
|
-
ontology["comment"] = self._comment
|
|
422
|
-
for prop in self._property_classes:
|
|
423
|
-
if "knora-api:hasLinkToValue" in prop.superproperties:
|
|
424
|
-
self._skiplist.append(self._name + ":" + prop.name)
|
|
425
|
-
continue
|
|
426
|
-
ontology["properties"].append(prop.createDefinitionFileObj(self.context, self._name))
|
|
427
|
-
|
|
428
|
-
for res in self._resource_classes:
|
|
429
|
-
ontology["resources"].append(res.createDefinitionFileObj(self.context, self._name, self._skiplist))
|
|
430
|
-
|
|
431
|
-
return ontology
|
|
432
|
-
|
|
433
|
-
def print(self) -> None:
|
|
434
|
-
print('Ontology Info:')
|
|
435
|
-
print(' Id: {}'.format(self._id))
|
|
436
|
-
print(' Label: {}'.format(self._label))
|
|
437
|
-
print(' Name: {}'.format(self._name))
|
|
438
|
-
print(' Project: {}'.format(self._project))
|
|
439
|
-
print(' LastModificationDate: {}'.format(str(self._lastModificationDate)))
|
|
440
|
-
print(' Property Classes:')
|
|
441
|
-
if self._property_classes:
|
|
442
|
-
for pc in self._property_classes:
|
|
443
|
-
pc.print(4)
|
|
444
|
-
print(' Resource Classes:')
|
|
445
|
-
if self._resource_classes:
|
|
446
|
-
for rc in self._resource_classes:
|
|
447
|
-
rc.print(4)
|
|
448
|
-
|
dsplib/models/permission.py
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
from enum import Enum, unique
|
|
2
|
-
from typing import List, Set, Dict, Tuple, Optional, Any, Union, Type
|
|
3
|
-
from pystrict import strict
|
|
4
|
-
import re
|
|
5
|
-
|
|
6
|
-
from dsplib.models.group import Group
|
|
7
|
-
from dsplib.models.helpers import BaseError
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@unique
|
|
11
|
-
class PermissionValue(Enum):
|
|
12
|
-
RV = 1
|
|
13
|
-
V = 2
|
|
14
|
-
M = 4
|
|
15
|
-
D = 8
|
|
16
|
-
CR = 16
|
|
17
|
-
|
|
18
|
-
def __str__(self):
|
|
19
|
-
tmp = {
|
|
20
|
-
1: 'RV',
|
|
21
|
-
2: 'V',
|
|
22
|
-
4: 'M',
|
|
23
|
-
8: 'D',
|
|
24
|
-
16: 'CR'
|
|
25
|
-
}
|
|
26
|
-
return tmp[self.value]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@strict
|
|
30
|
-
class PermissionsIterator:
|
|
31
|
-
_permissions: 'Permissions'
|
|
32
|
-
_group: List[str]
|
|
33
|
-
_index: int
|
|
34
|
-
|
|
35
|
-
def __init__(self, permissions: 'Permissions'):
|
|
36
|
-
self._permissions = permissions
|
|
37
|
-
self._index = 0
|
|
38
|
-
|
|
39
|
-
def __next__(self):
|
|
40
|
-
if len(self._permissions.permissions) == 0 and self._index == 0:
|
|
41
|
-
return None, None
|
|
42
|
-
elif self._index < len(self._permissions.permissions):
|
|
43
|
-
tmp = self._prefixes[self._index]
|
|
44
|
-
self._index += 1
|
|
45
|
-
return tmp, self._permissions.permissions[tmp]
|
|
46
|
-
else:
|
|
47
|
-
raise StopIteration
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@strict
|
|
51
|
-
class Permissions:
|
|
52
|
-
_permissions: Union[Dict[PermissionValue, List[str]], None]
|
|
53
|
-
|
|
54
|
-
def __init__(self,
|
|
55
|
-
permissions: Optional[Dict[PermissionValue, List[str]]] = None):
|
|
56
|
-
if permissions is None:
|
|
57
|
-
self._permissions = {}
|
|
58
|
-
else:
|
|
59
|
-
self._permissions = permissions
|
|
60
|
-
|
|
61
|
-
def __getitem__(self, key: PermissionValue) -> Union[List[str], None]:
|
|
62
|
-
return self._permissions.get(key)
|
|
63
|
-
|
|
64
|
-
def __setitem__(self, key: PermissionValue, value: List[str]) -> None:
|
|
65
|
-
self._permissions[key] = value
|
|
66
|
-
|
|
67
|
-
def __delitem__(self, key: PermissionValue) -> None:
|
|
68
|
-
del self._permissions[key]
|
|
69
|
-
|
|
70
|
-
def __missing__(self, key: PermissionValue) -> None:
|
|
71
|
-
return None
|
|
72
|
-
|
|
73
|
-
def __iter__(self) -> PermissionsIterator:
|
|
74
|
-
return PermissionsIterator(self)
|
|
75
|
-
|
|
76
|
-
def __contains__(self, key: PermissionValue) -> bool:
|
|
77
|
-
return key in self._permissions
|
|
78
|
-
|
|
79
|
-
def __str__(self):
|
|
80
|
-
tmpstr = ''
|
|
81
|
-
for permission, groups in self._permissions.items():
|
|
82
|
-
if tmpstr:
|
|
83
|
-
tmpstr += '|'
|
|
84
|
-
tmpstr += str(permission) + ' ' + ",".join(groups)
|
|
85
|
-
return tmpstr
|
|
86
|
-
|
|
87
|
-
def add(self, key: PermissionValue, val: str):
|
|
88
|
-
if self._permissions.get(key) is None:
|
|
89
|
-
self._permissions[key] = [val]
|
|
90
|
-
else:
|
|
91
|
-
self._permissions[key].append(val)
|
|
92
|
-
|
|
93
|
-
def toJsonLdObj(self):
|
|
94
|
-
tmpstr = ''
|
|
95
|
-
for permission, groups in self._permissions.items():
|
|
96
|
-
if tmpstr:
|
|
97
|
-
tmpstr += '|'
|
|
98
|
-
tmpstr += str(permission) + ' ' + ",".join(groups)
|
|
99
|
-
return tmpstr
|
|
100
|
-
|
|
101
|
-
@classmethod
|
|
102
|
-
def fromString(cls, permstr: str):
|
|
103
|
-
tmpstr = permstr.split('|')
|
|
104
|
-
permissions: Dict[PermissionValue, List[str]] = {}
|
|
105
|
-
for s in tmpstr:
|
|
106
|
-
key, *vals = re.split("[\\s,]+", s)
|
|
107
|
-
permissions[PermissionValue[key]] = vals
|
|
108
|
-
return cls(permissions)
|
|
109
|
-
|
|
110
|
-
@property
|
|
111
|
-
def permissions(self) -> Union[Dict[PermissionValue, List[str]], None]:
|
|
112
|
-
return self._permissions
|