Commit eb753384 authored by ALVISET's avatar ALVISET
Browse files

advanced refactoring

parent 77f97e5e
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
.idea/
venv-bash/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
.idea/
venv-bash/
This diff is collapsed.
This diff is collapsed.
from rdflib import Graph, Literal, BNode, DCAT, SOSA, SSN, RDF
import urllib.parse
from rdflib.namespace import *
import rdflib.term
class GraphWrapper():
"""This class is designed to serve as an intermediate to insert new triples in a graph"""
def __init__(self, prefixes):
self.prefixes = prefixes
self.graph = Graph()
self.__bind_graph__()
def __bind_graph__(self):
for prefix in self.prefixes:
self.graph.bind(prefix[0], prefix[1])
def create_uri(self, args):
"""
@param namespace: rdflib.namespace
@param args: string()
@return: rdflib.term.URIRef
"""
full_string = ""
namespace = args[0]
i = 0
for element in args:
if i == 0: i += 1; continue
if element == None: continue
full_string += urllib.parse.quote(element)
if full_string != "":
return namespace[full_string]
else:
return None
def add_triple(self, subject, predicate, object):
"""
Wrapper to simplify triple addition to the graph without doing manual operations on the nodes every time
@param subject: rdflib.term.URIRef
@param predicate: rdflib.term.URIRef
@param object: rdflib.term.URIRef | rdflib.Literal | list | str
"""
if isinstance(object, rdflib.Literal) or isinstance(object, rdflib.term.URIRef):
self.graph.add((subject, predicate, object))
elif type(object) == list:
self.graph.add((subject, predicate, self.create_uri(object)))
elif type(object) == str:
self.graph.add((subject, predicate, Literal(object)))
def add_triples(self, dictionary):
"""
Method to add a dictionary if triples where the key is the subject containing a list of tuples where the
first element is the predicate and the second element is the object
@param dictionary: dict
"""
for key in dictionary.keys():
for definer in dictionary[key]:
self.add_triple(key, definer[0], definer[1])
\ No newline at end of file
from rdflib import Graph, Literal, BNode, DCAT, SOSA, SSN, RDF
import urllib.parse
from rdflib.namespace import *
import rdflib.term
class GraphWrapper():
"""This class is designed to serve as an intermediate to insert new triples in a graph"""
def __init__(self, prefixes):
self.prefixes = prefixes
self.graph = Graph()
self.__bind_graph__()
def __bind_graph__(self):
for prefix in self.prefixes:
self.graph.bind(prefix[0], prefix[1])
def create_uri(self, args):
"""
@param namespace: rdflib.namespace
@param args: string()
@return: rdflib.term.URIRef
"""
full_string = ""
namespace = args[0]
i = 0
for element in args:
if i == 0: i += 1; continue
if element == None: continue
full_string += urllib.parse.quote(element)
if full_string != "":
return namespace[full_string]
else:
return None
def add_triple(self, subject, predicate, object):
"""
Wrapper to simplify triple addition to the graph without doing manual operations on the nodes every time
@param subject: rdflib.term.URIRef
@param predicate: rdflib.term.URIRef
@param object: rdflib.term.URIRef | rdflib.Literal | list | str
"""
if isinstance(object, rdflib.Literal) or isinstance(object, rdflib.term.URIRef):
self.graph.add((subject, predicate, object))
elif type(object) == list:
self.graph.add((subject, predicate, self.create_uri(object)))
elif type(object) == str:
self.graph.add((subject, predicate, Literal(object)))
def add_triples(self, dictionary):
"""
Method to add a dictionary if triples where the key is the subject containing a list of tuples where the
first element is the predicate and the second element is the object
@param dictionary: dict
"""
for key in dictionary.keys():
for definer in dictionary[key]:
self.add_triple(key, definer[0], definer[1])
def serialize(self, destination=None, format="xml", base=None, encoding=None, *args):
return self.graph.serialize(destination, format, base, encoding, *args)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment