From 872efe5eb7f20b322cb26ba673b3e68b1c4f1101 Mon Sep 17 00:00:00 2001 From: marcel Date: Thu, 28 Nov 2024 00:46:17 +0100 Subject: [PATCH] Add platform independent path/URI handling URIs can be stored, e.g. for OWL import. However, Windows paths are not recognized as URIs. Therefore a tool is needed to convert a Windows path into an URI compatible path. Signed-off-by: marcel --- semantic-model/opcua/lib/nodesetparser.py | 2 +- semantic-model/opcua/lib/utils.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/semantic-model/opcua/lib/nodesetparser.py b/semantic-model/opcua/lib/nodesetparser.py index 84ef81bc..bef0cf9e 100644 --- a/semantic-model/opcua/lib/nodesetparser.py +++ b/semantic-model/opcua/lib/nodesetparser.py @@ -314,7 +314,7 @@ def create_header(self): self.g.add((self.ontology_name, OWL.versionIRI, self.versionIRI)) self.g.add((self.ontology_name, OWL.versionInfo, Literal(0.1))) for ontology in self.imported_ontologies: - self.g.add((self.ontology_name, OWL.imports, ontology)) + self.g.add((self.ontology_name, OWL.imports, utils.file_path_to_uri(ontology))) def create_prefixes(self, xml_node, base, opcua_namespace): self.rdf_ns['base'] = Namespace(base) diff --git a/semantic-model/opcua/lib/utils.py b/semantic-model/opcua/lib/utils.py index 83b8174f..6aca1591 100644 --- a/semantic-model/opcua/lib/utils.py +++ b/semantic-model/opcua/lib/utils.py @@ -17,6 +17,7 @@ from urllib.parse import urlparse from rdflib.namespace import RDFS, XSD, OWL, RDF from rdflib import URIRef, Namespace, Graph +from pathlib import Path import re import os @@ -261,6 +262,13 @@ def get_common_supertype(graph, class1, class2): return superclass +def file_path_to_uri(file_path): + if str(file_path).startswith('http'): + return URIRef(str(file_path)) + path = Path(os.path.abspath(str(file_path))) + return URIRef(path.as_uri()) + + class RdfUtils: def __init__(self, basens, opcuans): self.basens = basens