Beispiel #1
0
 def reset_etk_doc(self,
                   doc_id: str = "http://isi.edu/default-ns/projects"):
     """
     reset the doc object and return it. Called at initialization and after outputting triples.
     """
     kg_schema = KGSchema()
     kg_schema.add_schema("@prefix : <http://isi.edu/> .", "ttl")
     self.etk = ETK(kg_schema=kg_schema, modules=ETKModule)
     self.doc = self.etk.create_document({}, doc_id=doc_id)
     for k, v in wiki_namespaces.items():
         if k in self.prefix_dict:
             self.doc.kg.bind(k, self.prefix_dict[k])
         else:
             self.doc.kg.bind(k, v)
Beispiel #2
0
 def serialize_prefix(self):
     """
     This function should be called only once after the doc object is initialized.
     In order to serialize the prefix at the very begining it has to be printed per the change of rdflib 4.2.2->5.0.0
     Relevent issue: https://github.com/RDFLib/rdflib/issues/965
     """
     for k, v in wiki_namespaces.items():
         if k in self.prefix_dict:
             line = "@prefix " + k + ": <" + self.prefix_dict[k] + "> .\n"
         else:
             line = "@prefix " + k + ": <" + v + "> .\n"
         self.fp.write(line)
     self.fp.write("\n")
     self.fp.flush()
     self.reset()