Skip to content
Snippets Groups Projects
Commit 76a523ce authored by Matthias Stefan Bodenbenner's avatar Matthias Stefan Bodenbenner
Browse files

9.0.1- bug fixes & small refactoring

parent 99c01cf9
Branches
Tags 9.0.1
No related merge requests found
Pipeline #346060 passed
[![Build](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/badges/master/pipeline.svg)](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/commits/master)
# Python Unified Device Interface
Current stable version: 9.0.0
Current stable version: 9.0.1
## Installation
1. Install the WZL-UDI package via pip
......@@ -53,10 +53,14 @@ https://doi.org/10.1117/12.2527461
The authors acknowledge funding from the LaVA project (Large Volume Applications, contract 17IND03 of the European Metrology Programme for Innovation and Research EMPIR). The EMPIR initiative is co-funded by the European Union’s Horizon 2020 research and innovation programme and the EMPIR Participating States.
Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany's Excellence Strategy – EXC-2023 Internet of Production – 390621612.
Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Project-ID 432233186 -- AIMS.
## Recent changes
**9.0.1** - 2024-01-11
- bug fix of semantic name resolution
**9.0.0** - 2024-01-10
- added semantic features
- the device can return profiles, metadata and data defined and structured according to semantic web standards using RDF and SHACL
......
......@@ -7,4 +7,4 @@ rdflib==7.0.0
sphinx==3.5.2
sphinx-rtd-theme==1.0.0
strict-rfc3339==0.7
wzl-mqtt~=2.6.0
\ No newline at end of file
wzl-mqtt~=2.6.1
\ No newline at end of file
......@@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(name='wzl-udi',
version='9.0.0',
version='9.0.1',
url='https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python',
project_urls={
"Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python/-/issues",
......@@ -25,7 +25,7 @@ setup(name='wzl-udi',
'Deprecated~=1.2.13',
'nest-asyncio~=1.5.6',
'strict-rfc3339==0.7',
'wzl-mqtt~=2.5.3',
'wzl-mqtt~=2.6.1',
'rdflib~=7.0.0'
],
zip_safe=False)
......@@ -180,7 +180,7 @@ class HTTPServer(object):
semantic = request.query['semantic']
if len(splitted_request) > 0 and splitted_request[0] == Semantics.prefix:
item, semantic = self.root.resolve_semantic_path(splitted_request[1:])
item, semantic = self.root.resolve_semantic_path(splitted_request[1])
else:
try:
item = self.root[splitted_request]
......
......@@ -395,20 +395,13 @@ class Component(Element):
raise DeviceException('The provided kind of semantic information cannot be returned.')
return result
def resolve_semantic_path(self, path: List[str]):
def resolve_semantic_path(self, suffix: str) -> (Element, str):
try:
super().resolve_semantic_path(path)
return super().resolve_semantic_path(suffix)
except ChildNotFoundException:
triples = list(self._metadata.triples((None, Namespaces.rdf.type, None)))
triples = list(filter(lambda x: x[2] == Namespaces.ssn.System, triples))
assert len(triples) > 0
if path[0] == triples[0][0].split('/')[-1] and len(path) == 1:
return self, 'metadata'
for child in self.children:
try:
return child.resolve_semantic_path(path)
return child.resolve_semantic_path(suffix)
except ChildNotFoundException:
continue
......
......@@ -112,12 +112,11 @@ class Element(ABC):
def serialize_semantics(self, kind: str) -> rdflib.Graph:
...
def resolve_semantic_path(self, path: List[str]) -> ('Element', str):
if len(path) == 0:
raise ChildNotFoundException('Could not resolve the semantic path.')
if path[0] == f'{self._profilename}Shape' and len(path) == 1:
def resolve_semantic_path(self, suffix: str) -> ('Element', str):
if suffix == f'{self._profilename}Shape':
return self, 'profile'
elif suffix == self.semantic_name.split('/')[-1]:
return self, 'metadata'
raise ChildNotFoundException('Could not resolve the semantic path.')
......
......@@ -195,7 +195,7 @@ class Function(Element):
# This method does nothing intentionally, as we do not have any semantic definition for function
return None
def resolve_semantic_path(self, path: List[str]) -> ('Element', str):
def resolve_semantic_path(self, suffix: str) -> (Element, str):
# This method does nothing intentionally, as we do not have any semantic definition for function
raise ChildNotFoundException('Could not resolve the semantic path.')
......
......@@ -6,8 +6,6 @@ import rdflib
from deprecated import deprecated
from .datatype import Datatype
from .element import Element
from .error import ChildNotFoundException
from .figure import Figure
from .semantics import Semantics, Namespaces
from ..utils import root_logger
......@@ -223,22 +221,10 @@ class Measurement(Figure):
raise DeviceException('The provided kind of semantic information cannot be returned.')
return result
def resolve_semantic_path(self, path: List[str]) -> (Element, str):
try:
super().resolve_semantic_path(path)
except ChildNotFoundException:
triples = list(self._metadata.triples((None, Namespaces.rdf.type, None)))
triples = list(filter(lambda x: x[2] == Namespaces.sosa.ObservableProperty, triples))
assert len(triples) > 0
if path[0] == triples[0][0].split('/')[-1] and len(path) == 1:
return self, 'metadata'
raise ChildNotFoundException('Could not resolve the semantic path.')
@property
def semantic_name(self) -> str:
if self._metadata is None:
return ""
subject = next(self._metadata.subjects(predicate=Namespaces.rdf.type, object=Namespaces.sosa.ObservableProperty))
subject = next(
self._metadata.subjects(predicate=Namespaces.rdf.type, object=Namespaces.sosa.ObservableProperty))
return subject.toPython()
......@@ -6,7 +6,7 @@ from typing import Dict, Callable, Any, List
import rdflib
from .datatype import Datatype
from .error import ReadOnlyException, ChildNotFoundException
from .error import ReadOnlyException
from .figure import Figure
from .semantics import Semantics, Namespaces
from ..utils import root_logger
......@@ -154,19 +154,6 @@ class Parameter(Figure):
raise DeviceException('The provided kind of semantic information cannot be returned.')
return result
def resolve_semantic_path(self, path: List[str]) -> ('Element', str):
try:
super().resolve_semantic_path(path)
except ChildNotFoundException:
triples = list(self._metadata.triples((None, Namespaces.rdf.type, None)))
triples = list(filter(lambda x: x[2] == Namespaces.ssn.Property, triples))
assert len(triples) > 0
if path[0] == triples[0][0].split('/')[-1] and len(path) == 1:
return self, 'metadata'
raise ChildNotFoundException('Could not resolve the semantic path.')
@property
def semantic_name(self) -> str:
if self._metadata is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment