jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [12/20] jena git commit: JENA-1108 : jena-cmds module
Date Tue, 05 Jan 2016 12:46:06 GMT
http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfcopy.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfcopy.java b/jena-cmds/src/main/java/jena/rdfcopy.java
new file mode 100644
index 0000000..a998c37
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfcopy.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.net.*;
+import java.io.*;
+
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.shared.JenaException ;
+
+/** A program which read an RDF model and copy it to the standard output stream.
+ *
+ *  <p>This program will read an RDF model, in a variety of languages,
+ *     and copy it to the output stream in a possibly different language.
+ *     Input can be read either from a URL or from a file.
+ *     The program writes its results to the standard output stream and sets
+ *     its exit code to 0 if the program terminate normally,  and
+ *     to -1 if it encounters an error.</p>
+ *
+ *  <p></p>
+ *
+ *  <pre>java jena.rdfcopy model [inlang [outlang]]
+ *
+ *       model1 and model2 can be file names or URL's
+ *       inlang and outlang specify the language of the input and output
+ *       respectively and can be:
+ *           RDF/XML
+ *           N-TRIPLE
+ *           TURTLE
+ *           N3
+ *       The input language defaults to RDF/XML and the output language
+ *       defaults to N-TRIPLE.
+ *  </pre>
+ */
+public class rdfcopy extends java.lang.Object {
+
+    static { setCmdLogging(); }
+
+	/**
+	* @param args the command line arguments
+	*/
+	public static void main(String ... args) {
+		if ( ( args.length < 1 ) || ( "-h".equals(args[0]) ) ) {
+			usage();
+			System.exit(-1);
+		}
+
+		String in = args[0];
+		String inlang = "RDF/XML";
+		int j;
+		for (j = 1; j < args.length && args[j].contains( "=" ); j++)
+        {}
+		int lastInProp = j;
+		if (j < args.length) {
+			inlang = args[j];
+		}
+		j++;
+		String outlang = "N-TRIPLE";
+		
+		for (; j < args.length && args[j].contains( "=" ); j++)
+		{}
+		
+		int lastOutProp = j;
+		if (j < args.length) {
+			outlang = args[j];
+		}
+		if (j + 1 < args.length) {
+         //   System.err.println(j+"<<"+args.length);
+			usage();
+			System.exit(-1);
+		}
+
+		try {
+			Model m = ModelFactory.createDefaultModel();
+            String base = in ;
+			RDFReader rdr = m.getReader(inlang);
+			for (j = 1; j < lastInProp; j++) {
+				int eq = args[j].indexOf("=");
+				rdr.setProperty(
+					args[j].substring(0, eq),
+					args[j].substring(eq + 1));
+			}
+            
+            try {
+                rdr.read(m, in);
+            } catch (JenaException ex)
+            {
+                if ( ! ( ex.getCause() instanceof MalformedURLException ) )
+                    throw ex ;
+                // Tried as a URL.  Try as a file name.
+                // Make absolute
+                File f = new File(in) ;
+                base = "file:///"+f.getCanonicalPath().replace('\\','/') ;
+                rdr.read(m, new FileInputStream(in), base) ;
+            }
+			RDFWriter w = m.getWriter(outlang);
+			j++;
+			for (; j < lastOutProp; j++) {
+				int eq = args[j].indexOf("=");
+				w.setProperty(
+					args[j].substring(0, eq),
+					args[j].substring(eq + 1));
+			}
+			w.write(m, System.out, null) ;
+			System.exit(0);
+		} catch (Exception e) {
+			System.err.println("Unhandled exception:");
+			System.err.println("    " + e.toString());
+			System.exit(-1);
+		}
+	}
+
+	protected static void usage() {
+		System.err.println("usage:");
+		System.err.println("    java jena.rdfcopy in {inprop=inval}* [ inlang  {outprop=outval}*
outlang]]");
+		System.err.println();
+		System.err.println("    in can be a URL or a filename");
+		System.err.println("    inlang and outlang can take values:");
+		System.err.println("      RDF/XML");
+        System.err.println("      RDF/XML-ABBREV");
+        System.err.println("      N-TRIPLE");
+        System.err.println("      TURTLE");
+		System.err.println("      N3");
+		System.err.println(
+			"    inlang defaults to RDF/XML, outlang to N-TRIPLE");
+        System.err.println("    The legal values for inprop and outprop depend on inlang
and outlang.");
+        System.err.println("    The legal values for inval and outval depend on inprop and
outprop.");
+		System.err.println();
+	}
+
+	protected static void read(Model model, String in, String lang)
+		throws java.io.FileNotFoundException {
+		try {
+			URL url = new URL(in);
+			model.read(in, lang);
+		} catch (java.net.MalformedURLException e) {
+			model.read(new FileInputStream(in), "", lang);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rdfparse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rdfparse.java b/jena-cmds/src/main/java/jena/rdfparse.java
new file mode 100644
index 0000000..0ba1eb6
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rdfparse.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package jena;
+
+import static org.apache.jena.atlas.logging.LogCtl.setCmdLogging;
+
+import java.lang.reflect.Constructor ;
+
+import org.apache.jena.rdfxml.xmlinput.NTriple ;
+import org.apache.jena.shared.Command ;
+
+/** A command line interface into ARP.
+ * Creates NTriple's or just error messages.
+ * <pre>
+ * java &lt;class-path&gt; jena.rdfparse ( [ -[xstfu]][ -b xmlBase -[eiw] NNN[,NNN...]
] [ file ] [ url ] )...
+ * 
+ * java &lt;class-path&gt; jena.rdfparse --test
+ * 
+ * java &lt;class-path&gt; jena.rdfparse --internal-test
+ * </pre>
+ * 
+ * <p>
+ * The last two forms are for testing. <code>--test</code> runs ARP
+ * against the RDF Core Working Group tests found at w3.org.
+ * <code>--internal-test</code> uses a cached copy from within the jena.jar.
+ * </p>
+ * All options, files and URLs can be intemingled in any order.
+ * They are processed from left-to-right.
+ * <dl>
+ * file    </dt><dd>  Converts (embedded) RDF in XML file into N-triples
+ * </dd><dt>
+ * url  </dt><dd>     Converts (embedded) RDF from URL into N-triples
+ * </dd><dt>
+ * -b uri </dt><dd>   Sets XML Base to the absolute URI.
+ * </dd><dt>
+ * -r    </dt><dd>    Content is RDF (no embedding, rdf:RDF tag may be omitted).
+ * </dd><dt>
+ * -t  </dt><dd>      No n-triple output, error checking only.
+ * </dd><dt>
+ * -x   </dt><dd>     Lax mode - warnings are suppressed.
+ * </dd><dt>
+ * -s    </dt><dd>    Strict mode - most warnings are errors.
+ * </dd><dt>
+ * -u     </dt><dd>   Allow unqualified attributes (defaults to warning).
+ * </dd><dt>
+ * -f    </dt><dd>    All errors are.error - report first one only.
+ * </dd><dt>
+ * -b url </dt><dd>   Sets XML Base to the absolute url.
+ * </dd><dt>
+ * -e NNN[,NNN...]</dt><dd>
+ * Treats numbered warning conditions as errrors.
+ * </dd><dt>
+ * -w NNN[,NNN...]</dt><dd>
+ * Treats numbered error conditions as warnings.
+ * </dd><dt>
+ * -i NNN[,NNN...]
+ * </dt><dd>
+ * Ignores numbered error/warning conditions.
+ * </dl>
+ */
+
+public class rdfparse {
+
+    static { setCmdLogging(); }
+
+    /** Either start an RDF/XML to NTriple converter, or run test suite.
+	 * @param args The command-line arguments.
+	 */
+	public static void main( String... args ) throws Exception {
+		if (args.length == 1 && (args[0].equals( "--test" ) || args[0].equals( "--internal-test"
))) 
+            runTests( args[0].equals( "--test" ) );
+        else
+		    NTriple.main( args );
+	}
+
+    /**
+         wrapped this way so JUnit not a compile-time requirement.
+    */
+    protected static void runTests( boolean internetTest ) throws Exception { 
+        Class<?> rdfparse = Class.forName( "jena.test.rdfparse" );
+        Constructor<?> constructor = rdfparse.getConstructor( new Class[] {boolean.class}
);
+        Command c = (Command) constructor.newInstance( new Object[] { internetTest } );
+        c.execute();
+//        ARPTests.internet = internetTest;
+//        TestRunner.main( new String[] { "-noloading", ARPTests.class.getName()});
+        }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/jena/rset.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/jena/rset.java b/jena-cmds/src/main/java/jena/rset.java
new file mode 100644
index 0000000..6db2a1c
--- /dev/null
+++ b/jena-cmds/src/main/java/jena/rset.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package jena;
+
+public class rset {
+    public static void main(String... args) {
+        arq.rset.main(args);
+    }
+}


Mime
View raw message