GitBucket
Pull requests
Issues
Snippets
Sign in
alex
/
RdfDiff.scala
Fork
0
Created at Thu Nov 23 18:36:19 UTC 2017
Download ZIP
HTTP
Embed
Embed this snippet in your website.
HTTP
Clone with Git using the repository's web address.
Code
Revision
Forks
Alex Tucker
revised this
on 24 Nov 2017
b1c5134
RdfDiff.scala
import java.io.{File, StringWriter} import java.net.URI import org.apache.jena.riot.RDFDataMgr case class Config(uris: Seq[URI] = Seq.empty) object RdfDiff extends App { val packageVersion: String = getClass.getPackage.getImplementationVersion() val parser = new scopt.OptionParser[Config]("rdfdiff") { head("rdfdiff", packageVersion) arg[URI]("<URI>") minOccurs(1) maxOccurs(2) hidden() action { (x, c) => c.copy(uris = c.uris :+ x) } help("help") text("Parses each file/URL as RDF and shows the differences between the resulting set of statements.") } parser.parse(args, Config()) match { case Some(Config(Seq(uriA, uriB))) => val a = RDFDataMgr.loadModel(uriA.toString) val b = RDFDataMgr.loadModel(uriB.toString) if (a isIsomorphicWith b) { println("Graphs are isomorphic.") System.exit(0) } else { val sw = new StringWriter() sw.write("<<<<\n") a.difference(b).write(sw, "TURTLE") sw.write("\n----\n") b.difference(a).write(sw, "TURTLE") sw.write("\n>>>>\n") println(sw.toString) System.exit(1) } case _ => System.exit(2) } }
import java.io.{File, StringWriter} import java.net.URI import org.apache.jena.riot.RDFDataMgr case class Config(uris: Seq[URI] = Seq.empty) object RdfDiff extends App { val packageVersion: String = getClass.getPackage.getImplementationVersion() val parser = new scopt.OptionParser[Config]("rdfdiff") { head("rdfdiff", packageVersion) arg[URI]("<URI>") minOccurs(1) maxOccurs(2) hidden() action { (x, c) => c.copy(uris = c.uris :+ x) } help("help") text("Parses each file/URL as RDF and shows the differences between the resulting set of statements.") } parser.parse(args, Config()) match { case Some(Config(Seq(uriA, uriB))) => /* if (args.length < 2) { println("""Usage: rdfdiff [fileA/URL_A] [fileB/URL_B] Parses each file/URL as RDF and shows the differences between the resulting set of statements. """) System.exit(2) } */ val a = RDFDataMgr.loadModel(uriA.toString) val b = RDFDataMgr.loadModel(uriB.toString) if (a isIsomorphicWith b) { println("Graphs are isomorphic.") System.exit(0) } else { val sw = new StringWriter() sw.write("<<<<\n") a.difference(b).write(sw, "TURTLE") sw.write("\n----\n") b.difference(a).write(sw, "TURTLE") sw.write("\n>>>>\n") println(sw.toString) System.exit(1) } case _ => System.exit(2) } }
Alex Tucker
revised this
on 23 Nov 2017
aa2fc8d
RdfDiff.scala
import java.io.{File, StringWriter} import java.net.URI import org.apache.jena.riot.RDFDataMgr case class Config(uris: Seq[URI] = Seq.empty) object RdfDiff extends App { val packageVersion: String = getClass.getPackage.getImplementationVersion() val parser = new scopt.OptionParser[Config]("rdfdiff") { head("rdfdiff", packageVersion) arg[URI]("<URI>") minOccurs(1) maxOccurs(2) hidden() action { (x, c) => c.copy(uris = c.uris :+ x) } help("help") text("Parses each file/URL as RDF and shows the differences between the resulting set of statements.") } parser.parse(args, Config()) match { case Some(Config(Seq(uriA, uriB))) => /* if (args.length < 2) { println("""Usage: rdfdiff [fileA/URL_A] [fileB/URL_B] Parses each file/URL as RDF and shows the differences between the resulting set of statements. """) System.exit(2) } */ val a = RDFDataMgr.loadModel(uriA.toString) val b = RDFDataMgr.loadModel(uriB.toString) if (a isIsomorphicWith b) { println("Graphs are isomorphic.") System.exit(0) } else { val sw = new StringWriter() sw.write("<<<<\n") a.difference(b).write(sw, "TURTLE") sw.write("\n----\n") b.difference(a).write(sw, "TURTLE") sw.write("\n>>>>\n") println(sw.toString) System.exit(1) } case _ => System.exit(2) } }