Skip to content

Commit

Permalink
now converts IRI to URI before writing into BatchML
Browse files Browse the repository at this point in the history
now converts URI from BAtchML to IRI before comparing to AAS
  • Loading branch information
ReggaeUlli committed Dec 13, 2023
1 parent bf28ed6 commit d129ec5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
3 changes: 2 additions & 1 deletion server/OntologyAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand All @@ -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)
}]
Expand Down
3 changes: 2 additions & 1 deletion server/RecipeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

Expand Down
81 changes: 74 additions & 7 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d129ec5

Please sign in to comment.