package example; import gr.forth.ics.rdfsuite.services.ChangeImpactAnalyzer; import gr.forth.ics.rdfsuite.services.ChangeImpactAnalyzer.NamespaceClosure; import gr.forth.ics.rdfsuite.services.Delta; import gr.forth.ics.rdfsuite.services.DeltaFunction; import gr.forth.ics.rdfsuite.services.Deps; import gr.forth.ics.rdfsuite.services.DiffGenerator; import gr.forth.ics.rdfsuite.services.Format; import gr.forth.ics.rdfsuite.services.RdfDocument; import gr.forth.ics.rdfsuite.services.Triple; import gr.forth.ics.rdfsuite.services.util.IOUtils; import gr.forth.ics.swkmclient.Client; import gr.forth.ics.swkmclient.ClientFactory; import java.io.File; import java.util.Arrays; import java.util.EnumMap; import java.util.Map; public class ComparisonAndChangeImpactExample { public static void main(String[] args) { //Create a client by reading services.properties from classpath //and using the default database configuration of the server Client c = ClientFactory.newClientByConfiguration().withDefaultSettings(); //Start with a clean database, for demonstration purposes. //Of course, this functionality can be disabled through configuration c.debug().eraseDatabase(); //Assume two different versions of a model, described in two RDF/XML files //Store them using the Importer. RdfDocument firstVersion = new RdfDocument("http://example~_~v1#", IOUtils.readFileAsString(new File("data/diff/AddClass1_a.rdf")), Format.RDF_XML); c.importer().store(Arrays.asList(firstVersion), Deps.WITHOUT); RdfDocument secondVersion = new RdfDocument("http://example~_~v2#", IOUtils.readFileAsString(new File("data/diff/AddClass1_b.rdf")), Format.RDF_XML); c.importer().store(Arrays.asList(secondVersion), Deps.WITHOUT); //Now we will try to compare these stored documents //These are the different modes that the Comparison service supports DeltaFunction[] functions = { DeltaFunction.Delta_explicit, DeltaFunction.Delta_closure, DeltaFunction.Delta_dense, DeltaFunction.Delta_dense_and_closure }; //Lets try all of them, and see the generated (through the comparison) Delta //Store the generated deltas, to also show the Change Impact service Map deltas = new EnumMap(DeltaFunction.class); DiffGenerator diffGenerator = c.diffGenerator(); for (DeltaFunction function : functions) { System.out.println("Using: " + function); Delta delta = diffGenerator.diff( Arrays.asList(firstVersion.getURI()), Arrays.asList(secondVersion.getURI()), function); printDelta(delta); deltas.put(function, delta); } ChangeImpactAnalyzer impactAnalyzer = c.changeImpact(); for (DeltaFunction function : deltas.keySet()) { System.out.println("Using delta derived by: " + function); Delta delta = deltas.get(function); Delta impact = impactAnalyzer.changeImpact(delta, Arrays.asList(firstVersion.getURI()), NamespaceClosure.OFF); printDelta(impact); } } private static void printDelta(Delta delta) { System.out.println("Delta:\nAdded triples"); for (Triple triple : delta.getAdded()) { printTriple(triple); } System.out.println("\nDeleted triples"); for (Triple triple : delta.getAdded()) { printTriple(triple); } } private static void printTriple(Triple triple) { System.out.printf("<%s> <%s> <%s>\n", triple.getSubject(), triple.getPredicate(), triple.getObject()); } }