use of org.hl7.fhir.rdf.ModelComparer in project kindling by HL7.
the class ExampleInspector method checkJsonLd.
private void checkJsonLd() throws IOException {
String s1 = "{\r\n" + " \"@type\": \"fhir:Claim\",\r\n" + " \"@id\": \"http://hl7.org/fhir/Claim/760152\",\r\n" + " \"decimal\": 123.45,\r\n" + " \"@context\": {\r\n" + " \"fhir\": \"http://hl7.org/fhir/\",\r\n" + " \"xsd\": \"http://www.w3.org/2001/XMLSchema#\",\r\n" + " \"decimal\": {\r\n" + " \"@id\": \"fhir:value\",\r\n" + " \"@type\": \"xsd:decimal\"\r\n" + " }\r\n" + " }\r\n" + "}\r\n";
String s2 = "{\r\n" + " \"@type\": \"fhir:Claim\",\r\n" + " \"@id\": \"http://hl7.org/fhir/Claim/760152\",\r\n" + " \"decimal\": \"123.45\",\r\n" + " \"@context\": {\r\n" + " \"fhir\": \"http://hl7.org/fhir/\",\r\n" + " \"xsd\": \"http://www.w3.org/2001/XMLSchema#\",\r\n" + " \"decimal\": {\r\n" + " \"@id\": \"fhir:value\",\r\n" + " \"@type\": \"xsd:decimal\"\r\n" + " }\r\n" + " }\r\n" + "}\r\n";
Model m1 = ModelFactory.createDefaultModel();
Model m2 = ModelFactory.createDefaultModel();
m1.read(new StringReader(s1), null, "JSON-LD");
m2.read(new StringReader(s2), null, "JSON-LD");
List<String> diffs = new ModelComparer().setModel1(m1, "j1").setModel2(m2, "j2").compare();
if (!diffs.isEmpty()) {
System.out.println("not isomorphic");
for (String s : diffs) {
System.out.println(" " + s);
}
}
}
use of org.hl7.fhir.rdf.ModelComparer in project kindling by HL7.
the class ExampleInspector method validateRDF.
private void validateRDF(String fttl, String fjld, String rt) throws FileNotFoundException, IOException {
if (VALIDATE_RDF && new File(fjld).exists()) {
FileInputStream f = new FileInputStream(fjld);
int size = f.available();
f.close();
if (size > 1000000)
return;
// replace @context with the contents of the right context file
JsonObject json = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(fjld));
json.remove("@context");
json.add("@context", jsonLdDefns.get("@context"));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jcnt = gson.toJson(json);
// TextFile.stringToFile(jcnt, "c:\\temp\\jsonld\\"+rt+".jsonld");
// parse to a model
Model mj = ModelFactory.createDefaultModel();
mj.read(new StringReader(jcnt), null, "JSON-LD");
// read turtle file into Jena
Model mt = RDFDataMgr.loadModel(fttl);
// use ShEx to validate turtle file - TODO
shex.validate(mt);
// List<String> diffs = new ModelComparer().setModel1(mt, "ttl").setModel2(mj, "json").compare();
// if (!diffs.isEmpty()) {
// System.out.println("not isomorphic");
// for (String s : diffs) {
// System.out.println(" "+s);
// }
// RDFDataMgr.write(new FileOutputStream("c:\\temp\\json.nt"), mj, RDFFormat.NTRIPLES_UTF8);
// RDFDataMgr.write(new FileOutputStream("c:\\temp\\ttl.nt"), mt, RDFFormat.NTRIPLES_UTF8);
// }
}
}
Aggregations