Skip to content
Snippets Groups Projects
Commit 7eaa3d18 authored by Cornelia Michlits's avatar Cornelia Michlits
Browse files

#104 add om ontology, validation function

parent b9964b47
No related branches found
No related tags found
4 merge requests!81New stable release,!43Merge dev to master,!33Draft: merge dev to master,!32Add units-service to dev
# Units Service
Suggest and validates units of measurements defined in Ontology of units of Measure (OM) [1] is used.
[1] https://github.com/HajoRijgersberg/OM
This diff is collapsed.
...@@ -4,3 +4,4 @@ py-eureka-client==0.9.1 ...@@ -4,3 +4,4 @@ py-eureka-client==0.9.1
docker==5.0.0 docker==5.0.0
sqlalchemy==1.4.15 sqlalchemy==1.4.15
gevent==21.8.0 gevent==21.8.0
rdflib==6.0.1
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 2 23:31:39 2021
@author: Cornelia Michlits
"""
import rdflib
g = rdflib.Graph()
g.namespace_manager.bind('om', 'http://www.ontology-of-units-of-measure.org/resource/om-2/')
g.parse('onto/om-2.ttl', format='turtle')
om = rdflib.Namespace('http://www.ontology-of-units-of-measure.org/resource/om-2/')
_exhausted = object()
def validator(value):
#input str
tmp = str(om)+value
t_uri = rdflib.term.URIRef(tmp)
if next(g.triples((t_uri,None,None)), _exhausted) is _exhausted:
return 'invalid unit'
else:
return 'valid unit'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment