Skip to content

Commit

Permalink
Add platform independent path/URI handling
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wagmarcel authored and abhijith-hr committed Nov 28, 2024
1 parent 08d05f6 commit 872efe5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion semantic-model/opcua/lib/nodesetparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions semantic-model/opcua/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 872efe5

Please sign in to comment.