def test_meta_output(self): """ Generate a context AND a jsonld for the metamodel and make sure it parses as RDF """ jsonld_path = os.path.join(testscriptstempdir, 'metajson.jsonld') rdf_path = os.path.join(testscriptstempdir, 'metardf.ttl') meta_context_path = os.path.join(testscriptstempdir, 'metacontext.jsonld') # Generate an image of the metamodel gen = ContextGenerator(source_yaml_path) base = gen.schema.id if base[-1] not in '/#': base += '/' base += gen.schema.name with open(meta_context_path, 'w') as tfile: tfile.write(gen.serialize()) with open(jsonld_path, 'w') as tfile: tfile.write(JSONLDGenerator(source_yaml_path, fmt=JSONLDGenerator.valid_formats[0])\ .serialize(context=meta_context_path)) g = Graph() g.load(jsonld_path, format="json-ld") g.serialize(rdf_path, format="ttl") g.bind('meta', METAMODEL_NAMESPACE) new_ttl = g.serialize(format="turtle").decode() new_g = Graph() new_g.parse(data=new_ttl, format="turtle") self.check_size(g, new_g, URIRef(base), 11, 79, 11, "meta")
def test_meta_output(self): """ Generate a context AND a jsonld for the metamodel and make sure it parses as RDF """ tmp_jsonld_path = self.temp_file_path('metajson.jsonld') tmp_rdf_path = self.temp_file_path('metardf.ttl') tmp_meta_context_path = self.temp_file_path('metacontext.jsonld') # Generate an image of the metamodel gen = ContextGenerator(env.meta_yaml, importmap=env.import_map) base = gen.schema.id if base[-1] not in '/#': base += '/' base += gen.schema.name # Generate context with open(tmp_meta_context_path, 'w') as tfile: tfile.write(gen.serialize()) # Generate JSON with open(tmp_jsonld_path, 'w') as tfile: tfile.write( jsonldgen.JSONLDGenerator( env.meta_yaml, fmt=jsonldgen.JSONLDGenerator.valid_formats[0], importmap=env.import_map).serialize( context=tmp_meta_context_path)) # Convert JSON to TTL g = Graph() g.load(tmp_jsonld_path, format="json-ld") g.serialize(tmp_rdf_path, format="ttl") g.bind('meta', METAMODEL_NAMESPACE) new_ttl = g.serialize(format="turtle").decode() # Make sure that the generated TTL matches the JSON-LD (probably not really needed, as this is more of a test # of rdflib than our tooling but it doesn't hurt new_g = Graph() new_g.parse(data=new_ttl, format="turtle") # Make sure that both match the expected size (classes, slots, types, and model name for error reporting) self.check_size(g, new_g, URIRef(base), 15, 112, 13, "meta")