Skip to content
Snippets Groups Projects
Commit 79d4e4f5 authored by Marc Feger's avatar Marc Feger
Browse files

Add unchecked files

parent 7cb94194
No related branches found
No related tags found
No related merge requests found
from tokenize import String
from typing import Dict
class Decapper(object):
def __init__(self, value: Dict) -> None:
"""
This class unpacks the value of a result dict.
"""
self.value = value
def unpack(self) -> String:
"""
This method unpacks the value.
:return: The value as String
"""
return self.value['value']
from tokenize import String
from typing import Dict
from SPARQLWrapper import SPARQLWrapper, JSON
from src.lib.reader import FileReader
class SPARQLEngine(object):
def __init__(self, entrypoint: String, query: String) -> None:
"""
This class sends a SPARQL query to a specific entrypoint.
:param entrypoint: The entrypoint where the query will be send to.
:param query: The query to be send.
"""
self.entrypoint = entrypoint
self.query = query
self.engine = SPARQLWrapper(self.entrypoint)
self.results = None
def get_json(self) -> Dict:
"""
This method returns the results as JSON.
:return: JSON representation of the results.
"""
self.engine.setQuery(
FileReader(self.query).as_string()
)
self.engine.setReturnFormat(JSON)
self.results = self.engine.query().convert()
return self.results
def get_json_test(self) -> Dict:
"""
This method returns the results as JSON.
:return: JSON representation of the results.
"""
self.engine.setQuery(
self.query
)
self.engine.setReturnFormat(JSON)
self.results = self.engine.query().convert()
return self.results
from tokenize import String
class NTriple(object):
def __init__(self, subject: String, predicate: String, value: String):
"""
This class represents a N-Triple Statement.
"""
self.subject = subject
self.predicate = predicate
self.value = value
def as_string(self) -> String:
"""
This method returns the triple as a string.
:return: String version of the triple.
"""
return "<{subject}> <{predicate}> <{value}> ." \
.format(subject=self.subject,
predicate=self.predicate,
value=self.value)
import json
from tokenize import String
from typing import Dict
class FileReader(object):
def __init__(self, source: String):
"""
This class can read a file in a certain location.
:param source: Where is the file stored ?
"""
self.source = source
def as_string(self) -> String:
"""
This method reads a file at a certain location and returns it as a string.
:return: The content of the source as a string.
"""
with open(self.source, 'r') as content_file:
return content_file.read()
def as_json(self) -> Dict:
"""
This method reads a file which contains a json string.
Then it will assemble the josn.
:return: Dict
"""
with open(self.source) as json_file:
return json.load(json_file)
import json
from tokenize import String
class FileWriter(object):
def __init__(self, destination: String, data) -> None:
"""
This class can write a certain data to a specific location.
:param destination: Where to store the data.
:param data: The data to be stored.
"""
self.destination = destination
self.data = data
def as_json(self) -> None:
"""
This method writes the data as json to the destination.
:return: None
"""
with open(self.destination, 'w+') as outfile:
json.dump(self.data["results"]["bindings"], outfile)
def as_string(self) -> None:
"""
This method writes the data as a string linewise to the destination.
:return: None
"""
with open(self.destination, 'w') as out_file:
for d in self.data:
out_file.write(str(d))
from enum import Enum
class ResultKeys(Enum):
movie = 'Movie'
title = 'Title'
director = 'Director'
author = 'Author'
cast = 'Cast'
published = 'Published'
genre = 'Genre'
duration = 'Duration'
description = 'Description'
production_company = 'ProductionCompany'
line_separator = '|'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment