Permalink
Browse files

added BSD licence, moved rdf2jsonld tool into a tools package and sta…

…rted a playground style app
  • Loading branch information...
1 parent 6b9c2a3 commit bcd2f0d08ff33a221b4630d48303247326b7936b @tristan committed May 22, 2012
View
24 LICENCE
@@ -0,0 +1,24 @@
+Copyright (c) 2012, Deutsche Forschungszentrum für Künstliche Intelligenz GmbH
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the <organization> nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -98,9 +98,13 @@
<configuration>
<programs>
<program>
- <mainClass>de.dfki.km.json.jsonld.RDF2JSONLD</mainClass>
+ <mainClass>de.dfki.km.json.jsonld.tools.RDF2JSONLD</mainClass>
<name>rdf2jsonld</name>
</program>
+ <program>
+ <mainClass>de.dfki.km.json.jsonld.tools.Playground</mainClass>
+ <name>jsonldplayground</name>
+ </program>
</programs>
</configuration>
</plugin>
@@ -0,0 +1,128 @@
+package de.dfki.km.json.jsonld.tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import de.dfki.km.json.JSONUtils;
+import de.dfki.km.json.jsonld.JSONLDProcessor;
+
+public class Playground {
+
+ static boolean validOption(String opt) {
+ return "--ignorekeys".equals(opt) || "--expand".equals(opt) || "--compact".equals(opt) || "--frame".equals(opt) || "--normalize".equals(opt)
+ || "--simplify".equals(opt);
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ try {
+ if (args.length < 2 || !args[0].startsWith("--")) {
+ usage();
+ } else {
+
+ JSONLDProcessor p = new JSONLDProcessor();
+ Object inobj = null;
+ Object frobj = null;
+ String opt = null;
+ for (int i = 0; i < args.length;) {
+ if ("--ignorekeys".equals(args[i])) {
+ i++;
+ while (i < args.length && !validOption(args[i])) {
+ p.ignoreKeyword(args[i++]);
+ }
+ } else if (validOption(args[i])) {
+ if (opt != null) {
+ System.out.println("Error: can only do one operation on the input at a time");
+ usage();
+ return;
+ }
+ opt = args[i];
+ i++;
+ if (args.length <= i) {
+ System.out.println("Error: missing file names after argument " + args[i - 1]);
+ usage();
+ return;
+ }
+ File in = new File(args[i++]);
+ if (!in.exists()) {
+ System.out.println("Error: file \"" + args[i - 1] + "\" doesn't exist");
+ usage();
+ return;
+ }
+ inobj = JSONUtils.fromInputStream(new FileInputStream(in));
+ if ("--frame".equals(args[i - 2])) {
+ if (args.length <= i) {
+ System.out.println("Error: missing frame file");
+ usage();
+ return;
+ }
+ in = new File(args[i++]);
+ if (!in.exists()) {
+ System.out.println("Error: file \"" + args[i - 1] + "\" doesn't exist");
+ usage();
+ return;
+ }
+ frobj = JSONUtils.fromInputStream(new FileInputStream(in));
+ }
+ } else {
+ System.out.println("Invalid option: " + args[i]);
+ usage();
+ return;
+ }
+ }
+
+ if (opt == null) {
+ System.out.println("Error: missing processing option");
+ usage();
+ return;
+ }
+
+ Object outobj = null;
+ if ("--expand".equals(opt)) {
+ outobj = p.expand(inobj);
+ } else if ("--compact".equals(opt)) {
+ outobj = p.compact(new HashMap<String, Object>(), inobj);
+ } else if ("--normalize".equals(opt)) {
+ outobj = p.normalize(inobj);
+ } else if ("--frame".equals(opt)) {
+ if (frobj == null) {
+ System.out.println("Error: no frame file specified");
+ usage();
+ return;
+ } else {
+ outobj = p.frame(inobj, frobj);
+ }
+ } else if ("--simplify".equals(opt)) {
+ outobj = p.simplify((Map) inobj);
+ } else {
+ System.out.println("Error: invalid option \"" + opt + "\"");
+ usage();
+ return;
+ }
+
+ System.out.println(JSONUtils.toPrettyString(outobj));
+ }
+ } catch (Exception e) {
+ System.out.println("ERROR: " + e.getMessage());
+ usage();
+ return;
+ }
+ }
+
+ private static void usage() {
+ System.out.println("Usage: jsonldplayground <options>");
+ System.out.println("\tinput: a filename or URL to the rdf input (in rdfxml or n3)");
+ System.out.println("\toptions:");
+ System.out.println("\t\t--ignorekeys <keys to ignore> : a (space separated) list of keys to ignore (e.g. @geojson)");
+ System.out.println("\t\t--expand <input>: expand the input jsonld");
+ System.out.println("\t\t--compact <input> : compact the input jsonld");
+ System.out.println("\t\t--normalize <input> : normalize the input jsonld");
+ System.out.println("\t\t--frame <input> <frame> : frame the input jsonld with the frame file");
+ System.out.println("\t\t--simplify : simplify the input jsonld");
+ System.exit(1);
+ }
+}

0 comments on commit bcd2f0d

Please sign in to comment.