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

add qudt,iaq, endpoint: list_concepts

parent 7ed78323
No related branches found
No related tags found
3 merge requests!129New module for citation as they occur multiple,!121Modified logging, modified logging level, modified flasgger endpoint,!102240 onto incl
...@@ -6,6 +6,7 @@ from flasgger import Swagger ...@@ -6,6 +6,7 @@ from flasgger import Swagger
from flasgger.utils import swag_from from flasgger.utils import swag_from
from flasgger import LazyString, LazyJSONEncoder from flasgger import LazyString, LazyJSONEncoder
from list import list_units, get_uri from list import list_units, get_uri
from list_concept import get_concept
from validate import validator, stringmapper from validate import validator, stringmapper
from gevent.pywsgi import WSGIServer from gevent.pywsgi import WSGIServer
from save import insert_mdb_concepts, insert_mdb_columns_concepts from save import insert_mdb_concepts, insert_mdb_columns_concepts
...@@ -137,6 +138,19 @@ def save_column_concept(): ...@@ -137,6 +138,19 @@ def save_column_concept():
res = {"success": False, "message": str(e)} res = {"success": False, "message": str(e)}
return jsonify(res), 500 return jsonify(res), 500
@app.route('/api/units/getconcept/<cname>', methods=["GET"], endpoint='get_concept')
@swag_from('getconcept.yml')
def get_concept(cname):
logging.debug('endpoint get concept, cname=%s, body=%s', cname, request)
try:
res = get_concept(cname)
logging.debug('get concept resulted in concept: %s', res)
return jsonify(res), 200
except Exception as e:
logging.error('Failed to get concept: %s', e)
res = {"success": False, "message": str(e)}
return jsonify(res), 500
rest_server_port = int(os.getenv("PORT_APP")) rest_server_port = int(os.getenv("PORT_APP"))
eureka_client.init(eureka_server=os.getenv('EUREKA_SERVER', 'http://localhost:9090/eureka/'), eureka_client.init(eureka_server=os.getenv('EUREKA_SERVER', 'http://localhost:9090/eureka/'),
......
...@@ -15,7 +15,11 @@ g.parse('onto/om-2.ttl', format='turtle') ...@@ -15,7 +15,11 @@ g.parse('onto/om-2.ttl', format='turtle')
om = rdflib.Namespace('http://www.ontology-of-units-of-measure.org/resource/om-2/') om = rdflib.Namespace('http://www.ontology-of-units-of-measure.org/resource/om-2/')
rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#') rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
r={} f = rdflib.Graph()
f.namespace_manager.bind('qudt', 'http://qudt.org/2.1/vocab/unit')
f.parse('onto/VOCAB_QUDT-UNITS-ALL-v2.1.ttl', format='turtle')
#qudt = rdflib.Namespace('http://qudt.org/2.1/vocab/unit')
def list_units(string,offset=0): def list_units(string,offset=0):
if bool(re.match('^[a-zA-Z0-9\\s]+$',string)): if bool(re.match('^[a-zA-Z0-9\\s]+$',string)):
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 9 11:25:52 2022
@author: Cornelia Michlits
"""
import rdflib
import re
import sys
g = rdflib.Graph()
g.namespace_manager.bind('iaq', 'https://w3id.org/digitalconstruction/IndoorAirQuality#')
g.parse('onto/iaq.nt', format='nt')
f = rdflib.Graph()
f.namespace_manager.bind('geom', 'http://data.ign.fr/def/geometrie')
f.parse('onto/def--geometrie.ttl', format='turtle')
h = rdflib.Graph()
h.namespace_manager.bind('op', 'http://environment.data.gov.au/def/op')
h.parse('onto/def--op.nt', format='nt')
def get_concept(string,limit=sys.maxsize, offset=0):
if bool(re.match('^[a-zA-Z0-9\-\\\s]+$',string)):
l_query = """
SELECT ?s ?p ?o
WHERE{
?s ?p ?o .
FILTER regex(str(?s),\""""+string+"""\","i")
}LIMIT """+str(limit)+""" OFFSET """+str(offset)
qres1 = g.query(l_query)
res = list()
for row in qres1:
res.append({"S-URI": str(row.s), "P": str(row.p), "O": str(row.o)})
qres2 = f.query(l_query)
for row in qres2:
res.append({"S-URI": str(row.s), "P": str(row.p), "O": str(row.o)})
return res
qres3 = h.query(l_query)
for row in qres3:
res.append({"S-URI": str(row.s), "P": str(row.p), "O": str(row.o)})
return res
else:
return None
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
summary: "Get a list of concepts"
description: "This is a simple API for returning a list of concepts contained in various ontologies."
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "path"
type: "string"
name: "cname"
description: "Enter a table name or attribute name.´"
required: true
responses:
200:
description: "OK"
405:
description: "Invalid input"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment