from rdflib import Graph
from rdflib import Namespace
from rdflib.namespace import RDF
from rdflib import ConjunctiveGraph, URIRef
from rdflib.namespace import RDFS


g = Graph()
#g.parse("../Ontologies/Mokos_18_1_7_47 copy.ttl", format="turtle")

#print(len(g)) # prints 2

file2 = open(r"D:\Text\MyFile2.txt","w+") 

RDO_instances = Namespace("http://delab.csd.auth.gr/ontologies/2018/RDO-instances#")
RBO = Namespace("http://delab.csd.auth.gr/ontologies/2018/RBO#")
RDO = Namespace("http://delab.csd.auth.gr/ontologies/2018/RDO#")
LO = URIRef("http://delab.csd.auth.gr/ontologies/2018/LO")

g.load("../Ontologies/Mokos_18_1_7_47.ttl", format="turtle")
n = "http://delab.csd.auth.gr/ontologies/2018/SAO#System"

for subj, obj in g.subject_objects(predicate=RDFS.subClassOf):
    ##if n in subj:
     #   print (obj.rsplit('#')[-1])
    #else:
    lol = subj + "$"+ obj + "\n"
    file2.write(lol)

#    print("{} is a person".format(s))

#for s, p, o in g.triples((None,  RDF.type, None)):
#    file2.write("{} is a {} \n".format(s, o))


#add unique id
#new_req = RDO_instances.EEMR
#add the S1-S5 or M1-M16 etc
#new_req_2 = RBO.M16
#new_req_3 = RBO.M17


#g.bind('RDO_instances', RDO_instances)

#g.add((new_req, RDF.type, new_req_2))
#g.add((new_req, RDF.type, new_req_3))
#print(g.serialize(format="turtle").decode("utf-8"))

#save in file
#g.serialize(destination='output.txt', format='turtle')
