Skip to content
Snippets Groups Projects
Commit d72b2469 authored by Andreas Schärtl's avatar Andreas Schärtl
Browse files

experimental: add script for generating a simple RDF tree

We use this to test out transitive queries w/ GraphDB.
parent d621945b
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/env python3
from typing import List
NS = 'http://example.org/rdf/'
PREDICATE = '<http://example.org/rdf/has_edge_to>'
class Node:
def __init__(self, name: str, children=[]):
self.name = name
self.children = children
def to_rdf(self) -> str:
rdf = ''
for child in self.children:
rdf += self.rdf_uri() + '\n'
rdf += ' ' + PREDICATE + '\n'
rdf += ' ' + child.rdf_uri() + ' .' + '\n\n'
rdf += child.to_rdf()
return rdf
def rdf_uri(self) -> str:
return '<%s%s>' % (NS, self.name)
def ttl_header() -> str:
owl_transitive_property = '<http://www.w3.org/2002/07/owl#TransitiveProperty>'
rdf_type = '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'
header = ''
header += PREDICATE + '\n'
header += ' ' + rdf_type + '\n'
header += ' ' + owl_transitive_property + ' .' + '\n\n'
return header
def main():
C = Node('C')
D = Node('D')
B = Node('B', [C, D])
G = Node('G')
F = Node('F', [G])
E = Node('E', [F])
A = Node('A', [B, E])
header = ttl_header()
print(header, end='')
triplets = A.to_rdf()
print(triplets.rstrip())
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit, BrokenPipeError):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment