Page MenuHomec4science

knora_base.py
No OneTemporary

File Metadata

Created
Sat, Nov 9, 02:11

knora_base.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This instantiates the knora base ontology.
"""
# Copyright (C) University of Basel 2019 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
from os.path import isfile, isdir, exists, dirname
import re
from rdflib import Graph, URIRef, Literal, BNode, OWL, RDF, RDFS
import sys
if dirname(__file__) not in sys.path:
sys.path.append(dirname(__file__))
from config import KNORA_BASE_ONTOLOGY_FILE
__author__ = "Christian Steiner"
__maintainer__ = __author__
__copyright__ = 'University of Basel'
__email__ = "christian.steiner@unibas.ch"
__status__ = "Development"
__license__ = "GPL v3"
__version__ = "0.0.1"
class KnoraBase:
""" Instantiates the knora base ontology from its ttl-definition.
"""
def __init__(self):
self.kb = Graph()
self.kb.parse(KNORA_BASE_ONTOLOGY_FILE, format="turtle")
for s in self.kb.subjects(predicate=RDF.type, object=OWL.Class):
self.__setattr__(s.split('#')[1], s)
for s in self.kb.subjects(predicate=RDF.type, object=OWL.ObjectProperty):
self.__setattr__(s.split('#')[1], s)
def __getattribute__(self, item):
try:
return object.__getattribute__(self, item)._value
except AttributeError as e:
return object.__getattribute__(self, item)
def __setattr__(self, key, value):
"""
:param key:
:param value:
:return:
"""
try:
object.__getattribute__(self, key)._value = value
except Exception as e:
return object.__setattr__(self, key, value)
KNORA_BASE = KnoraBase()

Event Timeline