From d129ec54dffedc2e79cb707e79bc5663accda7e0 Mon Sep 17 00:00:00 2001 From: Sebastian Ulrich Date: Wed, 13 Dec 2023 01:51:18 +0100 Subject: [PATCH] now converts IRI to URI before writing into BatchML now converts URI from BAtchML to IRI before comparing to AAS --- server/OntologyAPI.py | 3 +- server/RecipeAPI.py | 3 +- server/server.py | 81 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/server/OntologyAPI.py b/server/OntologyAPI.py index f39022d..1a26009 100644 --- a/server/OntologyAPI.py +++ b/server/OntologyAPI.py @@ -6,6 +6,7 @@ from Functions import upload_file import owlready2 import json +from django.utils.encoding import iri_to_uri, uri_to_iri ONTO_FOLDER = "ontologies/" UPLOAD_FOLDER = './upload/' @@ -18,7 +19,7 @@ def recursivly_add_subclasses(super_class): "otherInfoID":"SemanticDescription", "description":["URI referencing the Ontology Class definition"], "otherValue":[{ - "valueString": super_class.iri, + "valueString": iri_to_uri(super_class.iri), "dataType":"uriReference", "key":str(super_class) }] diff --git a/server/RecipeAPI.py b/server/RecipeAPI.py index 76ded6f..336f505 100644 --- a/server/RecipeAPI.py +++ b/server/RecipeAPI.py @@ -2,6 +2,7 @@ import os import xml.etree.ElementTree as ET from lxml import etree +from django.utils.encoding import iri_to_uri, uri_to_iri recipe_api = Blueprint('recipe_api', __name__) @@ -33,7 +34,7 @@ def get_all_recipe_capabilities(file_content): if otherInfoId.text == "SemanticDescription": capabilities.append({ "ID": processElement.find(ns+'ID').text, - "IRI":otherInfo.find(ns+'OtherValue').find(ns+'ValueString').text + "IRI": uri_to_iri(otherInfo.find(ns+'OtherValue').find(ns+'ValueString').text) }) return capabilities diff --git a/server/server.py b/server/server.py index 5ddbe92..299448e 100644 --- a/server/server.py +++ b/server/server.py @@ -98,14 +98,15 @@ def static_files(filename): response.headers['Content-Type'] = mimetype return response - @app.route('/check/capabilities/basic', methods=['POST']) + ''' + @app.route('/CapabilityMatching/AAS/basic', methods=['POST']) def check_capabilities_basic(): """Endpoint to check if all needed capabilities of a recipe can be realized by a given AAS. --- tags: - - Check Capabilitys + - Capability Matching parameters: - - name: aasx + - name: aas in: formData type: file required: true @@ -152,19 +153,20 @@ def check_capabilities_basic(): string = "There are Capability IRIS in Recipe that are not in AASX (negative case)." print(string) return make_response(string + str(unique_recipe_capabilities.difference(unique_aasx_capabilities)), 400) + ''' - @app.route('/check/capabilities/complex', methods=['POST']) + @app.route('/CapabilityMatching/AAS', methods=['POST']) def check_capabilities_complex(): - """Endpoint to check which ProcessElements of a given could be realized by which resources. + """Endpoint to match Capabilities of a zip file with ".xml" AAS files and a general Recipe. --- tags: - - Check Capabilitys + - Capability Matching parameters: - name: aasx in: formData type: file required: true - description: aasx or zip file of aasx files + description: aas or zip file of aas files - name: recipe in: formData type: file @@ -219,8 +221,73 @@ def check_capabilities_complex(): string = "There are no Capability IRIS in Recipe that can be realized by an given AAS." print(string) return make_response(string, 200) + + @app.route('/CapabilityMatching/AASX', methods=['POST']) + def capability_Matching_AASX(): + """Endpoint to Match Capabilities of an AASX and a General Recipe. + --- + tags: + - Capability Matching + parameters: + - name: aasx + in: formData + type: file + required: true + description: aas or zip file of aas files + - name: recipe + in: formData + type: file + required: true + responses: + 200: + description: The requested File + examples: + rgb: ['red', 'green', 'blue'] + """ + found_capabilities = [] + if 'recipe' not in request.files: + print("no file given") + flash('No file part') + return make_response(request.url, 400) + recipe = request.files['recipe'] + recipe_content = recipe.read() + recipe_capabilities = get_all_recipe_capabilities(recipe_content) + unique_recipe_capabilities = set(item['IRI'] for item in recipe_capabilities) + + if 'aasx' not in request.files: + print("no file given") + flash('No file part') + return make_response(request.url, 400) + aasx_zip = request.files['aasx'] + aasx_files = extract_zip(aasx_zip) + for element in unique_recipe_capabilities: + for filename in aasx_files: + aasx = aasx_files[filename] + aasx_capabilities = get_all_aas_capabilities(aasx) + unique_aasx_capabilities = set(item['IRI'] for item in aasx_capabilities) + if element in unique_aasx_capabilities: + print("found capability: " + element) + aasxids = get_aasx_id(aasx) + found_capabilities.append("capability: "+element+" can be realized by aas: " + str(aasxids)) + else: + print("did not find capability"+ element) + # Extract unique IDs from list A and list B + #unique_aasx_capabilities = set(item['IRI'] for item in aasx_capabilities) + #unique_recipe_capabilities = set(item['IRI'] for item in recipe_capabilities) + + # Check if all IDs in recipe are in aasx + if len(found_capabilities)>0: + string="" + for capability in found_capabilities: + string = string + capability + "\r\n" + print(string) + return make_response(string, 200) + else: + string = "There are no Capability IRIS in Recipe that can be realized by an given AAS." + print(string) + return make_response(string, 200) app.register_blueprint(ontology_api) app.register_blueprint(recipe_api)