001: /*
002: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026: *
027: * $Id: rdfcompare.java,v 1.11 2008/01/02 12:08:16 andy_seaborne Exp $
028: */
029:
030: package jena;
031:
032: import com.hp.hpl.jena.rdf.model.*;
033:
034: import java.net.URL;
035: import java.io.FileInputStream;
036:
037: /** A program which read two RDF models and determines if they are the same.
038: *
039: * <p>This program will read two RDF models, in a variety of languages,
040: * and compare them. Input can be read either from a URL or from a file.
041: * The program writes its results to the standard output stream and sets
042: * its exit code to 0 if the models are equal, to 1 if they are not and
043: * to -1 if it encounters an error.</p>
044: *
045: * <p></p>
046: *
047: * <pre>java jena.rdfcompare model1 model2 [lang1 [lang2]]
048: *
049: * model1 and model2 can be file names or URL's
050: * lang1 and lang2 specify the language of the input and can be:
051: * RDF/XML
052: * N-TRIPLE
053: * N3
054: * </pre>
055: *
056: * @author bwm
057: * @version $Name: $ $Revision: 1.11 $ $Date: 2008/01/02 12:08:16 $
058: */
059: public class rdfcompare extends java.lang.Object {
060:
061: /**
062: * @param args the command line arguments
063: */
064: public static void main(String args[]) {
065:
066: if (args.length < 2 || args.length > 4) {
067: usage();
068: System.exit(-1);
069: }
070:
071: String in1 = args[0];
072: String in2 = args[1];
073: String lang1 = "RDF/XML";
074: if (args.length > 2) {
075: lang1 = args[2];
076: }
077: String lang2 = "N-TRIPLE";
078: if (args.length == 4) {
079: lang2 = args[3];
080: }
081:
082: System.out.println(in1 + " " + in2 + " " + lang1 + " " + lang2);
083: try {
084: Model m1 = ModelFactory.createDefaultModel();
085: Model m2 = ModelFactory.createDefaultModel();
086:
087: read(m1, in1, lang1);
088: read(m2, in2, lang2);
089:
090: if (m1.isIsomorphicWith(m2)) {
091: System.out.println("models are equal");
092: System.out.println();
093: System.exit(0);
094: } else {
095: System.out.println("models are unequal");
096: System.out.println();
097: System.exit(1);
098: }
099: } catch (Exception e) {
100: System.err.println("Unhandled exception:");
101: System.err.println(" " + e.toString());
102: System.exit(-1);
103: }
104: }
105:
106: protected static void usage() {
107: System.err.println("usage:");
108: System.err
109: .println(" java jena.rdfcompare source1 source2 [lang1 [lang2]]");
110: System.err.println();
111: System.err
112: .println(" source1 and source2 can be URL's or filenames");
113: System.err.println(" lang1 and lang2 can take values:");
114: System.err.println(" RDF/XML");
115: System.err.println(" N-TRIPLE");
116: System.err.println(" N3");
117: System.err
118: .println(" lang1 defaults to RDF/XML, lang2 to N-TRIPLE");
119: System.err.println();
120: }
121:
122: protected static void read(Model model, String in, String lang)
123: throws java.io.FileNotFoundException {
124: try {
125: URL url = new URL(in);
126: model.read(in, lang);
127: } catch (java.net.MalformedURLException e) {
128: model.read(new FileInputStream(in), "", lang);
129: }
130: }
131: }
|