You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/01/05 13:46:09 UTC

[15/20] jena git commit: JENA-1108 : jena-cmds module

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
new file mode 100644
index 0000000..5960f02
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneral.java
@@ -0,0 +1,119 @@
+/*
+ * 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 arq.cmdline;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.query.LabelExistsException ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.util.DatasetUtils ;
+
+/** ModDataset: arguments to build a dataset - 
+ * see also ModDatasetAssembler which extends ModDataset
+ * with a description parameter. */ 
+
+public class ModDatasetGeneral extends ModDataset
+{
+    // See also ModDatasetAssembler
+    protected final ArgDecl graphDecl      = new ArgDecl(ArgDecl.HasValue, "graph") ;
+    protected final ArgDecl dataDecl      = new ArgDecl(ArgDecl.HasValue, "data") ;
+    protected final ArgDecl namedGraphDecl = new ArgDecl(ArgDecl.HasValue, "named", "namedgraph", "namedGraph", "namedData", "nameddata") ;
+    //protected final ArgDecl dataFmtDecl    = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
+    //protected final ArgDecl dirDecl        = new ArgDecl(ArgDecl.HasValue, "dir") ;
+    
+    private List<String> dataURLs                = null ;
+    private List<String> graphURLs               = null ;
+    private List<String> namedGraphURLs          = null ;
+    protected ModDatasetGeneral() {}
+    
+    @Override
+    public void registerWith(CmdGeneral cl)
+    {
+        cl.getUsage().startCategory("Dataset") ;
+        cl.add(dataDecl,
+               "--data=FILE",
+               "Data for the datset - triple or quad formats") ;
+        cl.add(graphDecl,
+               "--graph=FILE",
+               "Graph for default graph of the datset") ;
+        cl.add(namedGraphDecl,
+               "--namedGraph=FILE",
+               "Add a graph into the dataset as a named graph") ;
+    }
+    
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        dataURLs = cmdLine.getValues(dataDecl) ;
+        graphURLs = cmdLine.getValues(graphDecl) ;
+        namedGraphURLs = cmdLine.getValues(namedGraphDecl) ;
+    }
+    
+    @Override
+    public Dataset createDataset()
+    {
+        // If nothing specified to the module.  Leave alone and hope the query has FROM/FROM NAMED
+        if (  ( dataURLs == null || dataURLs.size() == 0) &&
+              (graphURLs == null || graphURLs.size() == 0) &&
+              (namedGraphURLs == null || namedGraphURLs.size() == 0 ) )
+            return null ;
+        
+        Dataset ds = DatasetFactory.createTxnMem() ;
+        addGraphs(ds) ;
+        dataset = ds ;
+        return dataset ;
+    }
+        
+    protected void addGraphs(Dataset ds)
+    {
+        try {
+            if ( dataURLs != null ) 
+            {
+                for ( String url : dataURLs )
+                    RDFDataMgr.read(ds, url) ;
+            }
+            
+            if ( (graphURLs != null) || (namedGraphURLs != null) )
+                ds = DatasetUtils.addInGraphs(ds, graphURLs, namedGraphURLs, null) ;
+        } 
+        catch (LabelExistsException ex)
+        { throw new CmdException(ex.getMessage()) ; }
+        catch (JenaException ex)
+        { throw ex ; }
+        catch (Exception ex)
+        { throw new CmdException("Error creating dataset", ex) ; }
+    }
+
+    public List<String> getGraphURLs()
+    {
+        return graphURLs ;
+    }
+
+    public List<String> getNamedGraphURLs()
+    {
+        return namedGraphURLs ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
new file mode 100644
index 0000000..c6ec7b5
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModDatasetGeneralAssembler.java
@@ -0,0 +1,56 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+
+import org.apache.jena.query.Dataset ;
+
+/** Add assembler to a general dataset description */
+public class ModDatasetGeneralAssembler extends ModDatasetGeneral
+{
+    public ModDatasetGeneralAssembler() {}
+    
+    private ModDatasetAssembler modAssembler = new ModDatasetAssembler() ;
+    
+    @Override
+    public Dataset createDataset()
+    {
+        Dataset ds = modAssembler.createDataset() ;
+        if ( ds == null )
+            ds = super.createDataset() ;
+        return ds ;
+    }
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        modAssembler.registerWith(cmdLine) ;
+        super.registerWith(cmdLine) ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        modAssembler.processArgs(cmdLine) ;
+        super.processArgs(cmdLine) ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModEngine.java b/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
new file mode 100644
index 0000000..998d656
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModEngine.java
@@ -0,0 +1,110 @@
+/*
+ * 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 arq.cmdline;
+
+import java.util.List ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.sparql.engine.main.QueryEngineMain ;
+import org.apache.jena.sparql.engine.main.QueryEngineMainQuad ;
+import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
+import org.apache.jena.sparql.engine.ref.QueryEngineRefQuad ;
+
+
+public class ModEngine extends ModBase
+{
+    // Special case of a "ModEnvironment"
+    // Alters the ARQ environment but provides nothing at execution time.
+    // Combine with ModSymbol?
+    
+    protected final ArgDecl engineDecl = new ArgDecl(ArgDecl.HasValue, "engine") ;
+    protected final ArgDecl unEngineDecl = new ArgDecl(ArgDecl.HasValue,
+                                                       "unengine",
+                                                       "unEngine",
+                                                       "removeEngine",
+                                                       "removeengine"
+                                                       ) ;
+    
+    private boolean timing = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Query Engine") ;
+        cmdLine.add(engineDecl, "--engine=EngineName", "Register another engine factory[ref]") ; 
+        cmdLine.add(unEngineDecl, "--unengine=EngineName", "Unregister an engine factory") ;
+    }
+    
+    public void checkCommandLine(CmdGeneral cmdLine)
+    {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+       
+        List<String> engineDecls = cmdLine.getValues(engineDecl) ;
+        
+//        if ( x.size() > 0 )
+//            QueryEngineRegistry.get().factories().clear() ;
+
+        for ( String engineName : engineDecls )
+        {
+			switch (engineName.toLowerCase()) {
+				case "reference":
+				case "ref":
+					QueryEngineRef.register();
+					continue;
+				case "refQuad":
+					QueryEngineRefQuad.register();
+					continue;
+				case "main":
+					QueryEngineMain.register();
+					continue;
+				case "quad":
+					QueryEngineMainQuad.register();
+					continue;
+				}
+			throw new CmdException("Engine name not recognized: " + engineName);
+		}
+
+        List<String> unEngineDecls = cmdLine.getValues(unEngineDecl) ;
+        for (String engineName : unEngineDecls)
+        {
+	        	switch (engineName.toLowerCase()) {
+				case "reference":
+				case "ref":
+					QueryEngineRef.register();
+					continue;
+				case "refQuad":
+					QueryEngineRefQuad.register();
+					continue;
+				case "main":
+					QueryEngineMain.register();
+					QueryEngineMainQuad.register();
+					continue;      
+	        }
+        		throw new CmdException("Engine name not recognized: "+engineName) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModFormat.java b/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
new file mode 100644
index 0000000..b73215e
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModFormat.java
@@ -0,0 +1,91 @@
+/*
+ * 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 arq.cmdline;
+
+
+import java.util.Arrays;
+import java.util.List;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+public class ModFormat extends ModBase
+{
+    protected final 
+    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "fmt", "format") ;
+
+    private String format = "N-TRIPLES" ;
+    
+    public ModFormat() {}
+    
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(resultsFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsFmtDecl) ;
+            format = lookup(rFmt) ;
+            if ( format == null )
+                cmdline.cmdError("Unrecognized format: "+rFmt) ;
+        }
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Output format") ;
+        cmdLine.add(resultsFmtDecl,
+                    "--format",
+                    "Format (Result sets: text, XML, JSON; Graph: RDF serialization)") ;  
+    }
+
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    public String getFormat() { return format ; } 
+    
+    public String getFormat(String defaultFormat)
+    { 
+        if ( format == null )
+            return defaultFormat ;
+        return format ;
+    }
+  
+    private String lookup(String fmt)
+    {
+    		return formats.stream().filter(fmt::equalsIgnoreCase).findFirst().orElse("TURTLE");
+    }
+
+    static final List<String> formats = Arrays.asList(
+        "RDF/XML",
+        "RDF/XML-ABBREV",
+        "N-TRIPLE",
+        "N-TRIPLES",
+        "N3",
+        "N3-PP" ,
+        "N3-PLAIN" ,
+        "N3-TRIPLES" ,
+        "N3-TRIPLE" ,
+        "TURTLE" ,
+        //"Turtle" ,
+        "TTL"
+        ) ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModItem.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModItem.java b/jena-cmds/src/main/java/arq/cmdline/ModItem.java
new file mode 100644
index 0000000..c7ee7c1
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModItem.java
@@ -0,0 +1,80 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.sparql.sse.Item ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.util.FileManager ;
+
+public class ModItem extends ModBase
+{
+    protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
+
+    private String filename = null ;
+    private String parseString = null ; 
+    private Item item = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Item") ;
+        cmdLine.add(queryFileDecl, "--file=", "File") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        if ( cmdLine.contains(queryFileDecl) )
+        {
+            filename = cmdLine.getValue(queryFileDecl) ;
+            parseString = FileManager.get().readWholeFileAsUTF8(filename) ;
+            return ;
+        }
+    
+        if ( cmdLine.getNumPositional() == 0 && filename == null )
+            cmdLine.cmdError("No query string or query file") ;
+
+        if ( cmdLine.getNumPositional() > 1 )
+            cmdLine.cmdError("Only one query string allowed") ;
+    
+        if ( cmdLine.getNumPositional() == 1 && filename != null )
+            cmdLine.cmdError("Either query string or query file - not both") ;
+
+        if ( filename == null )
+        {
+            String qs = cmdLine.getPositionalArg(0) ;
+            parseString = cmdLine.indirect(qs) ;
+        }
+    }
+    
+    public Item getItem()
+    {
+        if ( item != null )
+            return item ;
+        // Need to get the (outer) prologue.
+        item = SSE.parseItem(parseString) ;
+        return item ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java b/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
new file mode 100644
index 0000000..ecc82ca
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModLangOutput.java
@@ -0,0 +1,150 @@
+/*
+ * 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 arq.cmdline;
+
+import java.io.PrintStream ;
+import java.util.HashSet ;
+import java.util.Set ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFFormat ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RDFWriterRegistry ;
+import org.apache.jena.riot.system.StreamRDFWriter ;
+
+public class ModLangOutput extends ModBase
+{
+    protected ArgDecl argOutput       = new ArgDecl(ArgDecl.HasValue, "out", "output") ;
+    protected ArgDecl argPretty       = new ArgDecl(ArgDecl.HasValue, "formatted", "pretty", "fmt") ;
+    protected ArgDecl argStream       = new ArgDecl(ArgDecl.HasValue, "stream") ;
+    protected ArgDecl argCompress     = new ArgDecl(ArgDecl.NoValue, "compress") ;
+    private boolean compressedOutput = false ;
+    private RDFFormat streamOutput    = null ;
+    private RDFFormat formattedOutput = null ;
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Output control") ;
+        cmdLine.add(argOutput,    "--output=FMT",     "Output in the given format, streaming if possible.") ;
+        cmdLine.add(argPretty,    "--formatted=FMT",  "Output, using pretty printing (consumes memory)") ;
+        cmdLine.add(argStream,    "--stream=FMT",     "Output, using a streaming format") ;
+        cmdLine.add(argCompress,  "--compress",       "Compress the output with gzip") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine) {
+        if ( cmdLine.contains(argPretty) ) {
+            String langName = cmdLine.getValue(argPretty) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
+            if ( formattedOutput == null ) {
+                System.err.println("Language '"+lang.getLabel()+"' not registered.") ;
+                printRegistered(System.err) ;
+                throw new CmdException("No output set: '"+langName+"'") ;
+            }
+        }
+        
+        if ( cmdLine.contains(argStream) ) {
+            String langName = cmdLine.getValue(argStream) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
+            if ( streamOutput == null ) {
+                System.err.println("Language '"+lang.getLabel()+"' not registered for streaming.") ;
+                printRegistered(System.err) ;
+                throw new CmdException("No output set: '"+langName+"'") ;
+            }
+        }
+        
+        if ( cmdLine.contains(argOutput) ) {
+            String langName = cmdLine.getValue(argOutput) ;
+            Lang lang = RDFLanguages.nameToLang(langName) ;
+            if ( lang == null )
+                throw new CmdException("Not recognized as an RDF language : '"+langName+"'") ;
+            
+            if ( StreamRDFWriter.registered(lang) ) {
+                streamOutput = StreamRDFWriter.defaultSerialization(lang) ;
+            } else {
+                formattedOutput = RDFWriterRegistry.defaultSerialization(lang) ;
+                if ( formattedOutput == null ) {
+                    System.err.println("Language '"+lang.getLabel()+"' not recognized.") ;
+                    printRegistered(System.err) ;
+                    throw new CmdException("No output set: '"+langName+"'") ;
+                }
+            }
+        }
+        
+        if ( cmdLine.contains(argCompress))
+            compressedOutput = true ;
+        
+        if ( streamOutput == null && formattedOutput == null )
+            streamOutput = RDFFormat.NQUADS ;
+    }
+
+    private static Set<Lang>  hiddenLanguages = new HashSet<>() ;
+    static {
+        hiddenLanguages.add(Lang.RDFNULL) ;
+        hiddenLanguages.add(Lang.CSV) ;
+    }
+    
+    private static void printRegistered(PrintStream out) {
+        out.println("Streaming languages:") ;
+        Set<Lang> seen = new HashSet<>() ;
+        for ( RDFFormat fmt : StreamRDFWriter.registered()) {
+            Lang lang = fmt.getLang() ;
+            if ( hiddenLanguages.contains(lang)) 
+                continue ;
+            if ( seen.contains(lang) )
+                continue ;
+            seen.add(lang) ;
+            out.println("   "+lang.getLabel()) ;
+        }
+        System.err.println("Non-streaming languages:") ;
+        for ( RDFFormat fmt : RDFWriterRegistry.registered() ) {
+            Lang lang = fmt.getLang() ;
+            if ( hiddenLanguages.contains(lang)) 
+                continue ;
+            if ( seen.contains(lang) )
+                continue ;
+            seen.add(lang) ;
+            out.println("   "+lang.getLabel()) ;
+        }
+    }
+    
+    public RDFFormat getOutputStreamFormat() {
+        return streamOutput ;
+    }
+    
+    public RDFFormat getOutputFormatted() {
+        return formattedOutput ;
+    }
+    
+    public boolean compressedOutput() {
+        return compressedOutput ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
new file mode 100644
index 0000000..212807d
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModLangParse.java
@@ -0,0 +1,180 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.iri.IRI ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.system.IRIResolver ;
+import org.apache.jena.util.FileManager ;
+
+public class ModLangParse extends ModBase
+{
+    private ArgDecl argCheck    = new ArgDecl(ArgDecl.NoValue, "check") ;
+    private ArgDecl argNoCheck  = new ArgDecl(ArgDecl.NoValue, "nocheck", "noCheck") ;
+    private ArgDecl argSink     = new ArgDecl(ArgDecl.NoValue, "sink", "null") ;
+
+    private ArgDecl argStrict   = new ArgDecl(ArgDecl.NoValue, "strict") ;
+    private ArgDecl argValidate = new ArgDecl(ArgDecl.NoValue, "validate") ;
+    
+    private ArgDecl argSkip     = new ArgDecl(ArgDecl.NoValue, "skip") ;
+    private ArgDecl argNoSkip   = new ArgDecl(ArgDecl.NoValue, "noSkip") ;
+    private ArgDecl argStop     = new ArgDecl(ArgDecl.NoValue, "stopOnError", "stoponerror", "stop") ;
+    
+    private ArgDecl argBase     = new ArgDecl(ArgDecl.HasValue, "base") ;
+    
+    private ArgDecl argRDFS     = new ArgDecl(ArgDecl.HasValue, "rdfs") ;
+    
+    private ArgDecl argSyntax     = new ArgDecl(ArgDecl.HasValue, "syntax") ;
+
+    private  String rdfsVocabFilename   = null ;
+    private  Model  rdfsVocab           = null ;
+    private  String baseIRI             = null ;
+    private boolean explicitCheck       = false ;
+    private boolean explicitNoCheck     = false ;
+    private boolean skipOnBadTerm       = false ;
+    private boolean stopOnBadTerm       = false ;
+    private boolean bitbucket           = false ; 
+    private boolean strict              = false ;
+    private boolean validate            = false ;
+    private Lang lang                   = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Parser control") ;
+        cmdLine.add(argSink,    "--sink",           "Parse but throw away output") ;
+        cmdLine.add(argSyntax,  "--syntax=NAME",    "Set syntax (otherwise syntax guessed from file extension)") ;
+        cmdLine.add(argBase,    "--base=URI",       "Set the base URI (does not apply to N-triples and N-Quads)") ;
+        cmdLine.add(argCheck,   "--check",          "Addition checking of RDF terms") ; // (default: off for N-triples, N-Quads, on for Turtle and TriG)") ;
+        cmdLine.add(argStrict,  "--strict",         "Run with in strict mode") ;
+        cmdLine.add(argValidate,"--validate",       "Same as --sink --check --strict") ;
+        cmdLine.add(argRDFS,    "--rdfs=file",      "Apply some RDFS inference using the vocabulary in the file") ;
+        
+        cmdLine.add(argNoCheck, "--nocheck",        "Turn off checking of RDF terms") ;
+//        cmdLine.add(argSkip,    "--noSkip",         "Skip (do not output) triples failing the RDF term tests") ;
+//        cmdLine.add(argNoSkip,  "--skip",           "Include triples failing the RDF term tests (not recommended)") ;
+        cmdLine.add(argStop,    "--stop",           "Stop parsing on encountering a bad RDF term") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine) {
+        if ( cmdLine.contains(argValidate) ) {
+            validate = true ;
+            strict = true ;
+            explicitCheck = true ;
+            bitbucket = true ;
+        }
+
+        if ( cmdLine.contains(argSyntax) ) {
+            String syntax = cmdLine.getValue(argSyntax) ;
+            Lang lang$ = RDFLanguages.nameToLang(syntax) ;
+            if ( lang$ == null )
+                throw new CmdException("Can not detemine the syntax from '" + syntax + "'") ;
+            this.lang = lang$ ;
+        }
+
+        if ( cmdLine.contains(argCheck) )
+            explicitCheck = true ;
+
+        if ( cmdLine.contains(argNoCheck) )
+            explicitNoCheck = true ;
+
+        if ( cmdLine.contains(argStrict) )
+            strict = true ;
+
+        if ( cmdLine.contains(argSkip) )
+            skipOnBadTerm = true ;
+        if ( cmdLine.contains(argNoSkip) )
+            skipOnBadTerm = false ;
+
+        if ( cmdLine.contains(argBase) ) {
+            baseIRI = cmdLine.getValue(argBase) ;
+            IRI iri = IRIResolver.resolveIRI(baseIRI) ;
+            if ( iri.hasViolation(false) )
+                throw new CmdException("Bad base IRI: " + baseIRI) ;
+            if ( !iri.isAbsolute() )
+                throw new CmdException("Base IRI must be an absolute IRI: " + baseIRI) ;
+        }
+
+        if ( cmdLine.contains(argStop) )
+            stopOnBadTerm = true ;
+
+        if ( cmdLine.contains(argSink) )
+            bitbucket = true ;
+
+        if ( cmdLine.contains(argRDFS) ) {
+            try {
+                rdfsVocabFilename = cmdLine.getArg(argRDFS).getValue() ;
+                rdfsVocab = FileManager.get().loadModel(rdfsVocabFilename) ;
+            } catch (RiotException ex) {
+                throw new CmdException("Error in RDFS vocabulary: " + rdfsVocabFilename) ;
+            } catch (Exception ex) {
+                throw new CmdException("Error: " + ex.getMessage()) ;
+            }
+        }
+    }
+
+    public boolean explicitChecking() {
+        return explicitCheck ;
+    }
+
+    public boolean explicitNoChecking() {
+        return explicitNoCheck ;
+    }
+
+    public boolean strictMode() {
+        return strict ;
+    }
+
+    public boolean validate() {
+        return validate ;
+    }
+
+    public boolean skipOnBadTerm() {
+        return skipOnBadTerm ;
+    }
+
+    public boolean stopOnBadTerm() {
+        return stopOnBadTerm ;
+    }
+
+    public boolean toBitBucket() {
+        return bitbucket ;
+    }
+
+    public String getBaseIRI() {
+        return baseIRI ;
+    }
+
+    public Model getRDFSVocab() {
+        return rdfsVocab ;
+    }
+
+    public Lang getLang() {
+        return lang ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java b/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
new file mode 100644
index 0000000..290df7c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModQueryIn.java
@@ -0,0 +1,156 @@
+/*
+ * 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 arq.cmdline ;
+
+import java.io.IOException ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdException;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.query.Query ;
+import org.apache.jena.query.QueryFactory ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.util.FileUtils ;
+
+public class ModQueryIn extends ModBase {
+    protected final ArgDecl queryFileDecl   = new ArgDecl(ArgDecl.HasValue, "query", "file") ;
+    protected final ArgDecl querySyntaxDecl = new ArgDecl(ArgDecl.HasValue, "syntax", "syn", "in") ;
+    protected final ArgDecl queryBaseDecl   = new ArgDecl(ArgDecl.HasValue, "base") ;
+
+    private Syntax          defaultQuerySyntax     = Syntax.syntaxARQ ;
+    private Syntax          querySyntax     = null ;
+    private String          queryFilename   = null ;
+    private String          queryString     = null ;
+    private Query           query           = null ;
+    private String          baseURI         = null ;
+
+    public ModQueryIn(Syntax defaultSyntax) {
+        defaultQuerySyntax = defaultSyntax ;
+        querySyntax = defaultSyntax ;
+    }
+
+    @Override
+    public void registerWith(CmdGeneral cmdLine) {
+        cmdLine.getUsage().startCategory("Query") ;
+        cmdLine.add(queryFileDecl,   "--query, --file",  "File containing a query") ;
+        cmdLine.add(querySyntaxDecl, "--syntax, --in",   "Syntax of the query") ;
+        cmdLine.add(queryBaseDecl,   "--base",           "Base URI for the query") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException {
+        if ( cmdline.contains(queryBaseDecl) )
+            baseURI = cmdline.getValue(queryBaseDecl) ;
+
+        if ( cmdline.contains(queryFileDecl) ) {
+            queryFilename = cmdline.getValue(queryFileDecl) ;
+            querySyntax = Syntax.guessFileSyntax(queryFilename, defaultQuerySyntax) ;
+        }
+
+        if ( cmdline.getNumPositional() == 0 && queryFilename == null )
+            cmdline.cmdError("No query string or query file") ;
+
+        if ( cmdline.getNumPositional() > 1 )
+            cmdline.cmdError("Only one query string allowed") ;
+
+        if ( cmdline.getNumPositional() == 1 && queryFilename != null )
+            cmdline.cmdError("Either query string or query file - not both") ;
+
+        if ( queryFilename == null ) {
+            // One positional argument.
+            String qs = cmdline.getPositionalArg(0) ;
+            if ( cmdline.matchesIndirect(qs) )
+                querySyntax = Syntax.guessFileSyntax(qs, defaultQuerySyntax) ;
+
+            queryString = cmdline.indirect(qs) ;
+        }
+
+        // Set syntax
+        if ( cmdline.contains(querySyntaxDecl) ) {
+            // short name
+            String s = cmdline.getValue(querySyntaxDecl) ;
+            Syntax syn = Syntax.lookup(s) ;
+            if ( syn == null )
+                cmdline.cmdError("Unrecognized syntax: " + s) ;
+            querySyntax = syn ;
+        }
+    }
+
+    public Syntax getQuerySyntax() {
+        return querySyntax ;
+    }
+
+    public Query getQuery() {
+        if ( query != null )
+            return query ;
+
+        if ( queryFilename != null && queryString != null ) {
+            System.err.println("Both query string and query file name given") ;
+            throw new TerminationException(1) ;
+        }
+
+        if ( queryFilename == null && queryString == null ) {
+            System.err.println("No query string and no query file name given") ;
+            throw new TerminationException(1) ;
+        }
+
+        try {
+            if ( queryFilename != null ) {
+                if ( queryFilename.equals("-") ) {
+                    try {
+                        // Stderr?
+                        queryString = FileUtils.readWholeFileAsUTF8(System.in) ;
+                        // And drop into next if
+                    } catch (IOException ex) {
+                        throw new CmdException("Error reading stdin", ex) ;
+                    }
+                } else {
+                    query = QueryFactory.read(queryFilename, baseURI, getQuerySyntax()) ;
+                    return query ;
+                }
+            }
+
+            query = QueryFactory.create(queryString, baseURI, getQuerySyntax()) ;
+            return query ;
+        } catch (ARQInternalErrorException intEx) {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null ) {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+            throw new TerminationException(99) ;
+        }
+        catch (JenaException ex) {
+            System.err.println(ex.getMessage()) ;
+            throw new TerminationException(2) ;
+        } catch (Exception ex) {
+            System.out.flush() ;
+            ex.printStackTrace(System.err) ;
+            throw new TerminationException(98) ;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java b/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
new file mode 100644
index 0000000..d32f6c0
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModQueryOut.java
@@ -0,0 +1,92 @@
+/*
+ * 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 arq.cmdline;
+
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.query.Query ;
+import org.apache.jena.query.Syntax ;
+import org.apache.jena.sparql.util.QueryOutputUtils ;
+
+public class ModQueryOut extends ModBase
+{
+    protected final ArgDecl queryOutputSyntaxDecl  = new ArgDecl(ArgDecl.HasValue, "out", "format") ;
+    protected final ArgDecl queryNumberDecl        = new ArgDecl(ArgDecl.NoValue, "num", "number") ;
+
+    private Syntax outputSyntax = Syntax.syntaxSPARQL ;
+    private boolean lineNumbers = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Output") ;
+        cmdLine.add(queryOutputSyntaxDecl, "--out, --format",  "Output syntax") ;
+        cmdLine.add(queryNumberDecl, "--num", "Print line numbers") ;
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(queryOutputSyntaxDecl) )
+        {
+            // short name
+            String s = cmdline.getValue(queryOutputSyntaxDecl) ;
+            Syntax syn = Syntax.lookup(s) ;
+            if ( syn == null )
+                cmdline.cmdError("Unrecognized syntax: "+s) ;
+            outputSyntax = syn ; 
+        }        
+        
+        lineNumbers = cmdline.contains(queryNumberDecl) ;
+    }
+    
+    public Syntax getOutputSyntax()
+    {
+        return outputSyntax ;
+    }
+
+    public void output(Query query)
+    { output(out(), query) ; }
+    
+    public void output(IndentedWriter out, Query query)
+    { QueryOutputUtils.printQuery(out, query, outputSyntax) ; }
+    
+    public void outputOp(Query query, boolean printOptimized)
+    { outputOp(out(), query, printOptimized) ; }
+
+    public void outputOp(IndentedWriter out, Query query, boolean printOptimized)
+    { QueryOutputUtils.printOp(out, query, printOptimized) ; }
+    
+    public void outputQuad(Query query, boolean printOptimized)
+    { outputQuad(out(), query, printOptimized) ; }
+    
+    public void outputQuad(IndentedWriter out, Query query, boolean printOptimized)
+    { QueryOutputUtils.printQuad(out, query, printOptimized) ; }
+    
+    private IndentedWriter out()
+    {
+        return new IndentedWriter(System.out, lineNumbers) ;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModRemote.java b/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
new file mode 100644
index 0000000..97f03eb
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModRemote.java
@@ -0,0 +1,75 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+
+public class ModRemote extends ModBase
+{
+    protected final 
+    ArgDecl serviceDecl = new ArgDecl(ArgDecl.HasValue, "service") ;
+    
+    // Or --serviceType GET, POST, SOAP
+    protected final 
+    ArgDecl postServiceDecl = new ArgDecl(ArgDecl.NoValue, "post", "POST") ;
+    
+    private String serviceURL ;
+    private boolean usePost ;
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+    
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        serviceURL = cmdLine.getValue(serviceDecl) ;
+        usePost = cmdLine.contains(postServiceDecl) ;
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Remote") ;
+        cmdLine.add(serviceDecl,
+                    "--service=",
+                    "Service endpoint URL") ;
+        cmdLine.add(postServiceDecl,
+                    "--post",
+                    "Force use of HTTP POST") ;
+
+    }
+
+    public String getServiceURL()
+    {
+        return serviceURL ;
+    }
+
+    public boolean usePost()
+    {
+        return usePost ;
+    }
+    
+    
+    
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java b/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
new file mode 100644
index 0000000..c560767
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModResultsIn.java
@@ -0,0 +1,138 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.query.ResultSetFactory ;
+import org.apache.jena.shared.NotFoundException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.resultset.ResultsFormat ;
+
+public class ModResultsIn extends ModBase
+{
+    protected final ArgDecl resultsInputFmtDecl = new ArgDecl(ArgDecl.HasValue, "in") ;
+    protected final ArgDecl fileDecl = new ArgDecl(ArgDecl.HasValue, "file") ;
+
+    private ResultsFormat inputFormat = ResultsFormat.FMT_TEXT ;
+    private String resultsFilename = null ;
+    private ResultSet resultSet = null ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Results") ;
+        cmdLine.add(fileDecl,
+                    "--file",
+                    "Input file") ;
+        cmdLine.add(resultsInputFmtDecl,
+                    "--in",
+                    "Results format (XML, JSON; RDF serialization)") ;  
+    }
+
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        // Input file.
+        if ( cmdline.contains(fileDecl) )
+            resultsFilename = cmdline.getValue(fileDecl) ;
+        
+        if ( cmdline.getNumPositional() == 0 && resultsFilename == null )
+            cmdline.cmdError("No results file") ;
+
+        if ( cmdline.getNumPositional() > 1 )
+            cmdline.cmdError("Only one result set file allowed") ;
+            
+        if ( cmdline.getNumPositional() == 1 && resultsFilename != null )
+            cmdline.cmdError("Either result set file or --file - not both") ;
+
+        if ( resultsFilename == null )
+            // One positional argument.
+            resultsFilename = cmdline.getPositionalArg(0) ;
+        
+        // Guess format
+        if ( resultsFilename != null )
+            inputFormat = ResultsFormat.guessSyntax(resultsFilename) ;
+
+        // Set format
+        if ( cmdline.contains(resultsInputFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsInputFmtDecl) ;
+            inputFormat = ResultsFormat.lookup(rFmt) ;
+            if ( inputFormat == null )
+                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
+        }
+    }
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+    
+    
+    public ResultSet getResultSet()
+    {
+        if ( resultSet != null )
+            return resultSet ;
+        
+        if ( resultsFilename == null )
+        {
+            System.err.println("No result file name" ) ;
+            throw new TerminationException(1) ;
+        }
+
+        try
+        {
+            if ( resultsFilename.equals("-") )
+                return ResultSetFactory.load(System.in, inputFormat) ;
+            ResultSet rs = ResultSetFactory.load(resultsFilename, inputFormat) ;
+            if ( rs == null )
+            {
+                System.err.println("Failed to read the result set") ;
+                throw new TerminationException(9) ;
+            }
+            resultSet = rs ;
+            return resultSet ;
+        }
+        catch (NotFoundException ex)
+        {
+            System.err.println("File not found: "+resultsFilename) ;
+            throw new TerminationException(9) ;
+        }
+        catch (ARQInternalErrorException intEx)
+        {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null )
+            {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+            throw new TerminationException(99) ;
+        }
+    }
+
+    
+    public ResultsFormat getInputFormat() { return inputFormat ; }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java b/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
new file mode 100644
index 0000000..938be5f
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModResultsOut.java
@@ -0,0 +1,70 @@
+/*
+ * 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 arq.cmdline;
+
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.query.ResultSet ;
+import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.sparql.resultset.ResultsFormat ;
+import org.apache.jena.sparql.util.QueryExecUtils ;
+
+public class ModResultsOut extends ModBase
+{
+    protected final 
+    ArgDecl resultsFmtDecl = new ArgDecl(ArgDecl.HasValue, "results", "out", "rfmt") ;
+
+    private ResultsFormat resultsFormat = ResultsFormat.FMT_UNKNOWN ;
+    
+    @Override
+    public void processArgs(CmdArgModule cmdline) throws IllegalArgumentException
+    {
+        if ( cmdline.contains(resultsFmtDecl) )
+        {
+            String rFmt = cmdline.getValue(resultsFmtDecl) ;
+            resultsFormat = ResultsFormat.lookup(rFmt) ;
+            if ( resultsFormat == null )
+                cmdline.cmdError("Unrecognized output format: "+rFmt) ;
+        }
+    }
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Results") ;
+        cmdLine.add(resultsFmtDecl,
+                    "--results=",
+                    "Results format (Result set: text, XML, JSON, CSV, TSV; Graph: RDF serialization)") ;  
+    }
+
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    public void printResultSet(ResultSet resultSet, Prologue prologue)
+    {
+        QueryExecUtils.outputResultSet(resultSet, prologue, resultsFormat) ;
+    }
+    
+    public ResultsFormat getResultsFormat() { return resultsFormat ; }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java b/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
new file mode 100644
index 0000000..b465644
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModSymbol.java
@@ -0,0 +1,26 @@
+/*
+ * 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 arq.cmdline;
+
+/** Set Context items
+ *  @deprecated Use ModContext.
+ */
+@Deprecated
+public class ModSymbol extends ModContext {
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/cmdline/ModTime.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/cmdline/ModTime.java b/jena-cmds/src/main/java/arq/cmdline/ModTime.java
new file mode 100644
index 0000000..03a2096
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/cmdline/ModTime.java
@@ -0,0 +1,73 @@
+/*
+ * 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 arq.cmdline;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.atlas.lib.Timer ;
+
+
+public class ModTime extends ModBase
+{
+
+    protected final ArgDecl timeDecl = new ArgDecl(ArgDecl.NoValue, "time") ;
+    
+    protected Timer timer = new Timer() ;
+    
+    private boolean timing = false ;
+    
+    @Override
+    public void registerWith(CmdGeneral cmdLine)
+    {
+        cmdLine.getUsage().startCategory("Time") ;
+        cmdLine.add(timeDecl, "--time", "Time the operation") ;
+    }
+    
+    public void checkCommandLine(CmdArgModule cmdLine)
+    {}
+
+    @Override
+    public void processArgs(CmdArgModule cmdLine)
+    {
+        timing = cmdLine.contains(timeDecl) ;
+    }
+    
+    public boolean timingEnabled() { return timing ; }
+    
+    public void setTimingEnabled(boolean timingEnabled) { timing = timingEnabled ; }
+    
+    public void startTimer()
+    { timer.startTimer() ; } 
+    
+    public long endTimer()
+    { return timer.endTimer() ; } 
+    
+    public long readTimer() 
+    { return timer.readTimer() ; }
+    
+    public long getTimeInterval()
+    { return timer.getTimeInterval() ; }
+    
+    public String timeStr(long timeInterval)
+    { return Timer.timeStr(timeInterval) ; }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/iri.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/iri.java b/jena-cmds/src/main/java/arq/iri.java
new file mode 100644
index 0000000..2d5232c
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/iri.java
@@ -0,0 +1,57 @@
+/*
+ * 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 arq;
+
+import java.util.Iterator ;
+
+
+import org.apache.jena.iri.IRI ;
+import org.apache.jena.iri.IRIFactory ;
+import org.apache.jena.iri.Violation ;
+import org.apache.jena.riot.system.IRIResolver ;
+
+public class iri
+{
+
+    public static void main(String[] args)
+    {
+        //IRIFactory iriFactory = IRIFactory.iriImplementation() ;
+        IRIFactory iriFactory = IRIResolver.iriFactory ;
+        
+        boolean first = true ;
+        for ( String iriStr : args )
+        {
+            if ( ! first )
+                System.out.println() ;
+            first = false ;
+            
+            IRI iri = iriFactory.create(iriStr) ;
+            System.out.println(iriStr + " ==> "+iri) ;
+            if ( iri.isRelative() )
+                System.out.println("Relative: "+iri.isRelative()) ;
+
+            Iterator<Violation> vIter = iri.violations(true) ;
+            for ( ; vIter.hasNext() ; )
+            {
+                System.out.println(vIter.next().getShortMessage()) ;
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/juuid.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/juuid.java b/jena-cmds/src/main/java/arq/juuid.java
new file mode 100644
index 0000000..ccd6fd1
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/juuid.java
@@ -0,0 +1,173 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdArgModule;
+import jena.cmd.CmdGeneral;
+import jena.cmd.ModBase;
+
+import org.apache.jena.shared.uuid.* ;
+
+public class juuid extends CmdGeneral
+{
+    ModJUUID modJUUID = new ModJUUID() ;
+    int number = 1 ;
+    boolean resetEachTime = false ;
+    int uuidType = 0 ;
+    boolean asURN = false ;
+    boolean asURI = false ;
+    boolean asPlain = false ;
+
+    public static void main (String [] argv)
+    {
+        new juuid(argv).mainAndExit() ;
+    }
+    
+    private juuid(String argv[])
+    {
+        super(argv) ;
+        super.addModule(modJUUID) ;
+    }
+
+    @Override
+    protected String getSummary()
+    {
+        return getCommandName()+" [--num=N] [--reset] [--type={1|4}]" ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        if ( uuidType == UUID_V1.version )
+            JenaUUID.setFactory(new UUID_V1_Gen()) ;
+        if ( uuidType == UUID_V4.version )
+            JenaUUID.setFactory(new UUID_V4_Gen()) ;
+
+        for ( int i = 0 ; i < number ; i++ )
+        {
+            if ( resetEachTime && i != 0)
+                JenaUUID.reset() ;
+            JenaUUID uuid = JenaUUID.generate() ;
+            String str = null ;
+            if ( asURN )
+                str = uuid.asURN() ; 
+            else if ( asURI )
+                str = uuid.asURI() ; 
+            else if ( asPlain )
+                str = uuid.asString() ; 
+            if ( str == null )
+                str = uuid.asString() ;
+            System.out.println(str) ;
+        }
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return "uuid" ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        
+    }
+    
+    static ArgDecl argDeclNum      = new ArgDecl(ArgDecl.HasValue,  "num", "n") ;
+    static ArgDecl argDeclReset    = new ArgDecl(ArgDecl.NoValue,   "reset") ;
+    static ArgDecl argDeclGen      = new ArgDecl(ArgDecl.HasValue,  "gen", "scheme", "type", "ver") ;
+    static ArgDecl argDeclURN      = new ArgDecl(ArgDecl.NoValue,   "urn") ;
+    static ArgDecl argDeclURI      = new ArgDecl(ArgDecl.NoValue,   "uri") ;
+    static ArgDecl argDeclPlain    = new ArgDecl(ArgDecl.NoValue,   "plain") ;
+
+    class ModJUUID extends ModBase
+    {
+        @Override
+        public void registerWith(CmdGeneral cmdLine)
+        {
+            cmdLine.add(argDeclNum) ;
+            cmdLine.add(argDeclReset) ;
+            cmdLine.add(argDeclGen) ;
+            cmdLine.add(argDeclURN) ;
+            cmdLine.add(argDeclURI) ;
+            cmdLine.add(argDeclPlain) ;
+        }
+        
+        @Override
+        public void processArgs(CmdArgModule cmdLine)
+        {
+            String numStr = null ;
+            
+            if ( getNumPositional() > 1)
+                cmdError("Too many positional arguments") ;
+            
+            if ( cmdLine.contains(argDeclNum) )
+            {
+                if ( getNumPositional() != 0 )
+                    cmdError("--num and positional arguments don't go together") ;
+                numStr = getValue(argDeclNum) ;
+            }
+            
+            if ( numStr == null && cmdLine.getNumPositional() == 1 )
+                numStr = cmdLine.getPositionalArg(0) ;
+            
+            if ( numStr != null )
+            {
+                try
+                {
+                    number = Integer.parseInt(numStr) ;
+                    if ( number < 0 || number > 10000 )
+                        cmdLine.cmdError("Number out of range:" + numStr);
+                }
+                catch (NumberFormatException e)
+                {
+                    cmdLine.cmdError("Bad argument: " + numStr);
+                }
+            }
+
+            resetEachTime = cmdLine.contains(argDeclReset) ;
+            
+            if ( contains(argDeclGen) ) 
+            {
+                String s = getValue(argDeclGen) ;
+                if ( s.equalsIgnoreCase("time") || s.equalsIgnoreCase("1"))
+                    uuidType = UUID_V1.version ;
+                else if ( s.equalsIgnoreCase("random") || s.equalsIgnoreCase("rand") || s.equalsIgnoreCase("4"))
+                    uuidType = UUID_V4.version ;
+                else
+                    cmdError("Unrecognized UUID scheme: "+s) ;
+            }
+            
+            if ( contains(argDeclURN) || contains(argDeclURI) || contains(argDeclPlain) )
+            {
+                asURN = contains(argDeclURN) ;
+                asURI = contains(argDeclURI) ;
+                asPlain = contains(argDeclPlain) ;
+            }
+            else
+            {
+                // Defaults
+                asURN = true ;
+                asURI = false ;
+                asPlain = false ;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/load.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/load.java b/jena-cmds/src/main/java/arq/load.java
new file mode 100644
index 0000000..b5d75c8
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/load.java
@@ -0,0 +1,120 @@
+/*
+ * 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 arq;
+
+import java.util.Iterator ;
+import java.util.List ;
+
+import arq.cmdline.CmdUpdate ;
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.modify.request.UpdateLoad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.sparql.util.graph.GraphLoadMonitor ;
+import org.apache.jena.update.UpdateExecutionFactory ;
+import org.apache.jena.update.UpdateRequest ;
+
+public class load extends CmdUpdate
+{
+    static private final ArgDecl graphNameArg = new ArgDecl(ArgDecl.HasValue, "--graph") ;
+    static private final ArgDecl dumpArg = new ArgDecl(ArgDecl.NoValue, "--dump") ;
+    
+    String graphName = null ;
+    List<String> loadFiles = null ;
+    boolean dump = false ;
+    
+    public static void main (String... argv)
+    { new load(argv).mainRun() ; }
+    
+    protected load(String[] argv)
+    {
+        super(argv) ;
+        super.add(graphNameArg, "--graph=IRI", "Graph IRI (loads default graph if absent)") ;
+        super.add(dumpArg, "--dump", "Dump the resulting graph store") ;
+    }
+
+    @Override
+    protected void processModulesAndArgs()
+    {
+        if ( containsMultiple(graphNameArg) )
+            throw new CmdException("At most one --graph allowed") ;
+        
+        graphName = getValue(graphNameArg) ;
+        loadFiles = super.getPositional() ;
+        dump = contains(dumpArg) ;
+        super.processModulesAndArgs() ;
+    }
+    
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+    
+    @Override
+    protected String getSummary() { return getCommandName()+" --desc=assembler [--dump] --update=<request file>" ; }
+
+    @Override
+    protected void execUpdate(DatasetGraph graphStore)
+    {
+        if ( loadFiles.size() == 0 )
+            throw new CmdException("Nothing to do") ;
+        
+        UpdateRequest req = new UpdateRequest() ;
+        for ( String filename : loadFiles )
+        {
+            UpdateLoad loadReq = new UpdateLoad( filename, graphName );
+            req.add( loadReq );
+        }
+        
+        if ( true )
+        {
+            // Need a better way
+            monitor(graphStore.getDefaultGraph()) ;
+            for ( Iterator<Node> iter = graphStore.listGraphNodes() ; iter.hasNext() ; )
+            {
+                Graph g = graphStore.getGraph(iter.next()) ;
+                monitor(g) ;
+            }
+        }
+        
+        UpdateExecutionFactory.create(req, graphStore).execute() ;
+        
+        if ( dump )
+        {
+            IndentedWriter out = IndentedWriter.stdout ;
+            SSE.write(graphStore) ;
+            out.flush();
+        }
+    }
+
+    private void monitor(Graph graph)
+    {
+        GraphLoadMonitor m = new GraphLoadMonitor(20000,false) ;
+        //m.setSummaryLabel(getCommandName()) ;
+        graph.getEventManager().register(m)  ;
+    }
+    
+    @Override
+    protected DatasetGraph dealWithNoDataset() {
+        throw new CmdException("No dataset provided") ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/qexpr.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/qexpr.java b/jena-cmds/src/main/java/arq/qexpr.java
new file mode 100644
index 0000000..2408907
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/qexpr.java
@@ -0,0 +1,223 @@
+/*
+ * 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 arq;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+import jena.cmd.CmdLineArgs;
+import jena.cmd.TerminationException;
+
+import org.apache.jena.Jena ;
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.query.QueryParseException ;
+import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.ARQConstants ;
+import org.apache.jena.sparql.core.Prologue ;
+import org.apache.jena.sparql.engine.ExecutionContext ;
+import org.apache.jena.sparql.expr.Expr ;
+import org.apache.jena.sparql.expr.ExprEvalException ;
+import org.apache.jena.sparql.expr.ExprLib ;
+import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.sparql.function.FunctionEnv ;
+import org.apache.jena.sparql.sse.WriterSSE ;
+import org.apache.jena.sparql.util.ExprUtils ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+
+/** A program to execute expressions from the command line. */
+
+public class qexpr
+{
+    // TODO Convert to extends CmdArgModule 
+    static { LogCtl.setCmdLogging(); }
+
+    public static void main (String... argv)
+    {
+        try {
+            main2(argv) ;
+        }
+        catch (TerminationException ex) { System.exit(ex.getCode()) ; }
+        catch (CmdException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            if ( ex.getCause() != null )
+                ex.getCause().printStackTrace(System.err) ;
+        }
+        
+    }
+    
+    public static void execAndReturn(String... argv)
+    {
+        try {
+            main2(argv) ;
+        }
+        catch (TerminationException ex) { return ; }
+        catch (CmdException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            if ( ex.getCause() != null )
+                ex.getCause().printStackTrace(System.err) ;
+        }
+    }
+        
+    public static void main2(String... argv)
+    {
+        
+        CmdLineArgs cl = new CmdLineArgs(argv) ;
+        
+        ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help") ;
+        cl.add(helpDecl) ;
+        
+        ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose") ;
+        cl.add(verboseDecl) ;
+        
+        ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V") ;
+        cl.add(versionDecl) ;
+        
+        ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet") ;
+        cl.add(quietDecl) ;
+
+        ArgDecl reduceDecl =  new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify" ) ;
+        cl.add(reduceDecl) ;
+
+        ArgDecl strictDecl =  new ArgDecl(ArgDecl.NoValue, "strict") ;
+        cl.add(strictDecl) ;
+        
+        ArgDecl printDecl =  new ArgDecl(ArgDecl.HasValue, "print") ;
+        cl.add(printDecl) ;
+
+        try {
+            cl.process() ;
+        } catch (IllegalArgumentException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            usage(System.err) ;
+            throw new CmdException() ;
+        }
+
+        if ( cl.contains(helpDecl) )
+        {
+            usage() ;
+            throw new TerminationException(0) ;
+        }
+        
+        if ( cl.contains(versionDecl) )
+        {
+            System.out.println("ARQ Version: "+ARQ.VERSION+" (Jena: "+Jena.VERSION+")") ;
+            throw new TerminationException(0) ;
+        }
+ 
+        // ==== General things
+        boolean verbose = cl.contains(verboseDecl) ;
+        boolean quiet = cl.contains(quietDecl) ;
+
+        if ( cl.contains(strictDecl) )
+            ARQ.setStrictMode() ;
+        
+        boolean actionCopySubstitute = cl.contains(reduceDecl) ;
+        boolean actionPrintPrefix = false ;
+        boolean actionPrintSPARQL = false ; 
+        boolean actionPrint = cl.contains(printDecl) ;
+
+        for ( String v : cl.getValues( printDecl ) )
+        {
+            if ( v.equalsIgnoreCase( "prefix" ) || v.equalsIgnoreCase( "op" ) )
+            {
+                actionPrintPrefix = true;
+            }
+            else if ( v.equalsIgnoreCase( "expr" ) )
+            {
+                actionPrintSPARQL = true;
+            }
+            else
+            {
+                System.err.println( "Unknown print form: " + v );
+                throw new TerminationException( 0 );
+            }
+        }
+
+        // ==== Do it
+        
+        for ( int i = 0 ; i < cl.getNumPositional() ; i++ )
+        {
+            String exprStr = cl.getPositionalArg(i) ;
+            exprStr = cl.indirect(exprStr) ;
+            
+            try {
+                PrefixMapping pmap = PrefixMapping.Factory.create()  ;
+                pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap()) ;
+                pmap.setNsPrefix("", "http://example/") ;
+                pmap.setNsPrefix("ex", "http://example/ns#") ;
+//              Node n = asNode() ;
+//              return makeNode(n) ;
+
+                Expr expr = ExprUtils.parse(exprStr, pmap) ;
+                if ( verbose )
+                    System.out.print(expr.toString()+" => ") ;
+                
+                if ( actionPrint )
+                {
+                    if ( actionPrintSPARQL )
+                        System.out.println(ExprUtils.fmtSPARQL(expr)) ;
+                    if ( actionPrintPrefix )
+                        WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap)) ;
+                    continue ;
+                }
+                
+                try {
+                    if ( actionCopySubstitute )
+                    {
+                        Expr e = ExprLib.foldConstants(expr) ;
+                        System.out.println(e) ;
+                    }
+                    else
+                    {
+                        // Default action
+                        ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime()) ;
+                        FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null) ; 
+                        NodeValue r = expr.eval(null, env) ;
+                        //System.out.println(r.asQuotedString()) ;
+                        Node n = r.asNode() ;
+                        String s = NodeFmtLib.displayStr(n) ;
+                        System.out.println(s) ;
+                    }
+                } catch (ExprEvalException ex)
+                {
+                    System.out.println("Exception: "+ex.getMessage()) ;
+                    throw new TerminationException(2) ;
+                }
+            } catch (QueryParseException ex)
+            {
+                System.err.println("Parse error: "+ex.getMessage()) ;
+                throw new TerminationException(2) ;
+            }
+        }
+    }
+    
+    static void usage() { usage(System.out) ; }
+    
+    static void usage(java.io.PrintStream out)
+    {
+        out.println("Usage: [--print=[prefix|expr]] expression") ;
+    }
+
+ }

http://git-wip-us.apache.org/repos/asf/jena/blob/498b2264/jena-cmds/src/main/java/arq/qparse.java
----------------------------------------------------------------------
diff --git a/jena-cmds/src/main/java/arq/qparse.java b/jena-cmds/src/main/java/arq/qparse.java
new file mode 100644
index 0000000..749ab66
--- /dev/null
+++ b/jena-cmds/src/main/java/arq/qparse.java
@@ -0,0 +1,269 @@
+/*
+ * 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 arq;
+
+import java.io.PrintStream ;
+import java.util.Iterator ;
+
+import jena.cmd.ArgDecl;
+import jena.cmd.CmdException;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.query.* ;
+import org.apache.jena.shared.JenaException ;
+import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.core.QueryCheckException ;
+import org.apache.jena.sparql.lang.ParserBase ;
+import org.apache.jena.sparql.resultset.ResultSetException ;
+import org.apache.jena.sparql.util.QueryOutputUtils ;
+import org.apache.jena.sparql.util.QueryUtils ;
+
+import arq.cmdline.CmdARQ ;
+import arq.cmdline.ModEngine ;
+import arq.cmdline.ModQueryIn ;
+import arq.cmdline.ModQueryOut ;
+
+/** A program to parse and print a query. */
+
+public class qparse extends CmdARQ
+{
+    protected ModQueryIn    modQuery        = new ModQueryIn(Syntax.syntaxSPARQL_11) ;
+    protected ModQueryOut   modOutput       = new ModQueryOut() ; 
+    protected ModEngine     modEngine       = new ModEngine() ;
+    protected final ArgDecl argDeclPrint    = new ArgDecl(ArgDecl.HasValue, "print") ;
+    protected final ArgDecl argDeclOpt      = new ArgDecl(ArgDecl.NoValue, "opt", "optimize") ;
+    protected final ArgDecl argDeclExplain  = new ArgDecl(ArgDecl.NoValue, "explain") ;
+    
+    protected boolean printNone             = false ;
+    protected boolean printQuery            = false ;
+    protected boolean printOp               = false ;
+    protected boolean printOpt              = false ;
+    protected boolean printQuad             = false ;
+    protected boolean printQuadOpt          = false ;
+    protected boolean printPlan             = false ;
+    
+    public static void main(String... argv)
+    {
+        new qparse(argv).mainRun() ;
+    }
+    
+    public qparse(String[] argv)
+    {
+        super(argv) ;
+        super.addModule(modQuery) ;
+        super.addModule(modOutput) ;
+        super.addModule(modEngine) ;
+        super.getUsage().startCategory(null) ;
+        super.add(argDeclPrint, "--print", "Print in various forms [query, op, quad, plan]") ;
+        super.add(argDeclExplain, "--explain", "Print with algebra-level optimization") ;
+        super.add(argDeclOpt, "--opt", "[deprecated]") ; 
+    }
+    
+    @Override
+    protected void processModulesAndArgs()
+    {
+        super.processModulesAndArgs() ;
+        
+        if ( contains(argDeclOpt) )
+            printOpt = true ;
+        if ( contains(argDeclExplain) )
+        {
+            printQuery = true ;
+            printOpt = true ;
+        }
+
+        for ( String arg : getValues( argDeclPrint ) )
+        {
+            if ( arg.equalsIgnoreCase( "query" ) )
+            {
+                printQuery = true;
+            }
+            else if ( arg.equalsIgnoreCase( "op" ) ||
+                arg.equalsIgnoreCase( "alg" ) ||
+                arg.equalsIgnoreCase( "algebra" ) )
+            {
+                printOp = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quad" ) )
+            {
+                printQuad = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quads" ) )
+            {
+                printQuad = true;
+            }
+            else if ( arg.equalsIgnoreCase( "plan" ) )
+            {
+                printPlan = true;
+            }
+            else if ( arg.equalsIgnoreCase( "opt" ) )
+            {
+                printOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "optquad" ) )
+            {
+                printQuadOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "quadopt" ) )
+            {
+                printQuadOpt = true;
+            }
+            else if ( arg.equalsIgnoreCase( "none" ) )
+            {
+                printNone = true;
+            }
+            else
+            {
+                throw new CmdException(
+                    "Not a recognized print form: " + arg + " : Choices are: query, op, quad, opt, optquad" );
+            }
+        }
+        
+        if ( ! printQuery && ! printOp && ! printQuad && ! printPlan && ! printOpt && ! printQuadOpt && ! printNone )
+            printQuery = true ;
+    }
+
+    static String usage = qparse.class.getName()+" [--in syntax] [--out syntax] [--print=FORM] [\"query\"] | --query <file>" ;
+    
+    @Override
+    protected String getSummary()
+    {
+        return usage ;
+    }
+    
+    static final String divider = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ;
+    //static final String divider = "" ;
+    boolean needDivider = false ;
+    private void divider()
+    {
+        if ( needDivider ) System.out.println(divider) ;
+        needDivider = true ;
+    }
+    
+    @Override
+    protected void exec()
+    {
+        try{
+            Query query = modQuery.getQuery() ;
+            try {
+                LogCtl.disable(ParserBase.ParserLoggerName) ;
+                QueryUtils.checkQuery(query, true) ;
+            } catch (QueryCheckException ex)
+            {
+                System.err.println() ;
+                System.err.println("**** Check failure: "+ex.getMessage()) ;
+                if ( ex.getCause() != null )
+                    ex.getCause().printStackTrace(System.err) ;
+            }
+            finally { LogCtl.set(ParserBase.ParserLoggerName, "INFO") ; }
+
+            
+            // Print the query out in some syntax
+            if ( printQuery )
+            { divider() ; modOutput.output(query) ; }
+
+            // Print internal forms.
+            if ( printOp )
+            { divider() ; modOutput.outputOp(query, false) ; }
+            
+            if ( printQuad )
+            { divider() ; modOutput.outputQuad(query, false) ; }
+            
+            if ( printOpt )
+            { divider() ; modOutput.outputOp(query, true) ; }
+            
+            if ( printQuadOpt )
+            { divider() ; modOutput.outputQuad(query, true) ; }
+            
+            if ( printPlan )
+            { 
+                divider() ;
+                // This forces internal query initialization - must be after QueryUtils.checkQuery
+                QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral()) ;
+                QueryOutputUtils.printPlan(query, qExec) ; 
+            }
+        }
+        catch (ARQInternalErrorException intEx)
+        {
+            System.err.println(intEx.getMessage()) ;
+            if ( intEx.getCause() != null )
+            {
+                System.err.println("Cause:") ;
+                intEx.getCause().printStackTrace(System.err) ;
+                System.err.println() ;
+            }
+            intEx.printStackTrace(System.err) ;
+        }
+        catch (ResultSetException ex)
+        {
+            System.err.println(ex.getMessage()) ;
+            ex.printStackTrace(System.err) ;
+        }
+        catch (QueryException qEx)
+        {
+            //System.err.println(qEx.getMessage()) ;
+            throw new CmdException("Query Exeception", qEx) ;
+        }
+        catch (JenaException ex) { 
+            ex.printStackTrace() ;
+            throw ex ; } 
+        catch (CmdException ex) { throw ex ; } 
+        catch (Exception ex)
+        {
+            throw new CmdException("Exception", ex) ;
+        }
+    }
+
+    @Override
+    protected String getCommandName() { return Lib.className(this) ; }
+
+//    static String usage = qparse.class.getName()+
+//            " [--in syntax] [--out syntax] [\"query\" | --query <file>\n"+
+//            "  where syntax is one of ARQ, SPARQL\n" +
+//            "Other options: \n"+
+//            "  --num on|off   Line number ('on' by default)\n"+
+//            "  -n             Same as --num=off\n"+
+//            "  --base URI     Set the base URI for resolving relative URIs\n"+
+//            "  --plain        No pretty printing\n"+
+//            "  --parse        Parse only - don't print\n"+
+//            "  ---planning    Turn planning on/off\n"+
+//            "  --show X       Show internal structure (X = query or plan)\n" ;
+    
+    static void writeSyntaxes(String msg, PrintStream out)
+    {
+        if ( msg != null )
+            out.println(msg) ;
+        for ( Iterator<String> iter = Syntax.querySyntaxNames.keys() ; iter.hasNext() ; )
+        {
+            String k = iter.next() ;
+            Syntax v = Syntax.lookup(k) ;
+            k = padOut(k,10) ;
+            out.println("  "+k+"  "+v) ;
+        }
+    }
+    // printf ... java 1.5 .. mutter,mutter
+    static String padOut(String x, int len)
+    {
+        StringBuilder r = new StringBuilder(x) ;
+        for ( int i = x.length() ; i <= len ; i++ )
+            r.append(" ") ;
+        return r.toString() ; 
+    }
+}