jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1165003 - in /incubator/jena/Jena2/ARQ/trunk: ./ src-dev/dev/ src/arq/cmdline/ src/com/hp/hpl/jena/query/ src/com/hp/hpl/jena/sparql/core/assembler/ src/com/hp/hpl/jena/sparql/util/ src/org/openjena/riot/system/
Date Sun, 04 Sep 2011 12:19:46 GMT
Author: andy
Date: Sun Sep  4 12:19:45 2011
New Revision: 1165003

URL: http://svn.apache.org/viewvc?rev=1165003&view=rev
Log:
Support for setting contect objects on datasets and other things.

Added:
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java  
(with props)
Modified:
    incubator/jena/Jena2/ARQ/trunk/D.ttl
    incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
    incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/CmdARQ.java
    incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/ModSymbol.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ARQ.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/AssemblerUtils.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DatasetAssemblerVocab.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/GraphStoreAssembler.java
    incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/system/PrefixMap.java

Modified: incubator/jena/Jena2/ARQ/trunk/D.ttl
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/D.ttl?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java Sun Sep  4 12:19:45 2011
@@ -40,6 +40,7 @@ import com.hp.hpl.jena.iri.IRI ;
 import com.hp.hpl.jena.iri.IRIFactory ;
 import com.hp.hpl.jena.iri.Violation ;
 import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.query.Query ;
 import com.hp.hpl.jena.query.QueryCancelledException ;
 import com.hp.hpl.jena.query.QueryExecution ;
@@ -59,6 +60,8 @@ import com.hp.hpl.jena.sparql.algebra.Op
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
 import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.core.assembler.AssemblerUtils ;
+import com.hp.hpl.jena.sparql.core.assembler.DatasetAssemblerVocab ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryExecutionBase ;
 import com.hp.hpl.jena.sparql.engine.binding.Binding ;
@@ -120,6 +123,12 @@ public class RunARQ
     @SuppressWarnings("deprecation")
     public static void main(String[] argv) throws Exception
     {
+        ARQ.init();
+        
+        Dataset ds = (Dataset)AssemblerUtils.build("D.ttl", DatasetAssemblerVocab.tDataset)
;
+        System.out.println(ds.asDatasetGraph().getContext()) ;
+        exit(0) ;        
+        
         Node n = Node.createLiteral("9", null, XSDDatatype.XSDint) ;
         System.out.println(FmtUtils.stringForNode(n, (PrefixMapping)null)) ;
         exit(0) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/CmdARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/CmdARQ.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/CmdARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/CmdARQ.java Sun Sep  4 12:19:45 2011
@@ -20,7 +20,6 @@ public abstract class CmdARQ extends Cmd
     protected CmdARQ(String[] argv)
     {
         super(argv) ;
-        ModSymbol.addPrefixMapping(ARQ.arqSymbolPrefix, ARQ.arqNS) ;
         addModule(modSymbol) ;
         super.add(strictDecl, "--strict", "Operate in strict SPARQL mode (no extensions of
any kind)") ;
         super.modVersion.addClass(ARQ.class) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/ModSymbol.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/ModSymbol.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/ModSymbol.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/arq/cmdline/ModSymbol.java Sun Sep  4 12:19:45 2011
@@ -12,9 +12,8 @@ import java.util.Iterator ;
 import org.openjena.atlas.io.IndentedWriter ;
 
 import com.hp.hpl.jena.query.ARQ ;
-import com.hp.hpl.jena.shared.PrefixMapping ;
-import com.hp.hpl.jena.shared.impl.PrefixMappingImpl ;
 import com.hp.hpl.jena.sparql.util.Context ;
+import com.hp.hpl.jena.sparql.util.MappingRegistry ;
 import com.hp.hpl.jena.sparql.util.Symbol ;
 
 public class ModSymbol implements ArgModuleGeneral
@@ -36,13 +35,6 @@ public class ModSymbol implements ArgMod
     public void checkCommandLine(CmdArgModule cmdLine)
     {}
 
-    public static PrefixMapping symbolPrefixMapping = new PrefixMappingImpl() ;
-    
-    public static void addPrefixMapping(String prefix, String uri)
-    {
-        symbolPrefixMapping.setNsPrefix(prefix, uri) ;
-    }
-    
     public void processArgs(CmdArgModule cmdLine)
     {
         if ( cmdLine.getValues(setDecl) == null || cmdLine.getValues(setDecl).size() == 0
)
@@ -59,8 +51,7 @@ public class ModSymbol implements ArgMod
             String value = frags[1] ;
 
             // Make it a long name.
-            symbolName = symbolPrefixMapping.expandPrefix(symbolName) ;
-
+            symbolName = MappingRegistry.mapPrefixName(symbolName) ;
             Symbol symbol = Symbol.create(symbolName) ;
             context.set(symbol, value) ;
         }

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ARQ.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ARQ.java Sun Sep  4 12:19:45
2011
@@ -23,6 +23,7 @@ import com.hp.hpl.jena.sparql.mgt.Explai
 import com.hp.hpl.jena.sparql.mgt.Explain.InfoLevel ;
 import com.hp.hpl.jena.sparql.mgt.SystemInfo ;
 import com.hp.hpl.jena.sparql.util.Context ;
+import com.hp.hpl.jena.sparql.util.MappingRegistry ;
 import com.hp.hpl.jena.sparql.util.Symbol ;
 
 /** ARQ - miscellaneous settings
@@ -397,7 +398,8 @@ public class ARQ
             globalContext = defaultSettings() ;
             StageBuilder.init() ;
             ARQMgt.init() ;         // After context and after PATH/NAME/VERSION/BUILD_DATE
are set
-
+            MappingRegistry.addPrefixMapping(ARQ.arqSymbolPrefix, ARQ.arqNS) ;
+            
             // This is the pattern for any subsystem to register. 
             String NS = ARQ.PATH ;
 

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/AssemblerUtils.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/AssemblerUtils.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/AssemblerUtils.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/AssemblerUtils.java
Sun Sep  4 12:19:45 2011
@@ -6,22 +6,28 @@
 
 package com.hp.hpl.jena.sparql.core.assembler;
 
-
 import com.hp.hpl.jena.assembler.Assembler ;
 import com.hp.hpl.jena.assembler.JA ;
 import com.hp.hpl.jena.assembler.assemblers.AssemblerGroup ;
 import com.hp.hpl.jena.query.ARQ ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QuerySolution ;
+import com.hp.hpl.jena.query.QuerySolutionMap ;
+import com.hp.hpl.jena.query.ResultSet ;
 import com.hp.hpl.jena.rdf.model.Model ;
 import com.hp.hpl.jena.rdf.model.Resource ;
 import com.hp.hpl.jena.rdf.model.ResourceFactory ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.ARQException ;
 import com.hp.hpl.jena.sparql.mgt.Explain.InfoLevel ;
+import com.hp.hpl.jena.sparql.util.Context ;
+import com.hp.hpl.jena.sparql.util.MappingRegistry ;
+import com.hp.hpl.jena.sparql.util.Symbol ;
 import com.hp.hpl.jena.sparql.util.TypeNotUniqueException ;
 import com.hp.hpl.jena.sparql.util.graph.GraphUtils ;
 import com.hp.hpl.jena.util.FileManager ;
 
-
 public class AssemblerUtils
 {
     // Wrappers for reading things form a file - assumes one of the thing per file. 
@@ -31,7 +37,6 @@ public class AssemblerUtils
         return pm ;
     }
     
-    
     private static boolean initialized = false ; 
     
     static { ARQ.init(); init() ; } 
@@ -87,6 +92,24 @@ public class AssemblerUtils
         { ARQ.setExecutionLogging(level) ; }
         return Assembler.general.open(root) ;
     }
+    
+    public static void setContext(Resource r, Context context)
+    {
+        String qs = "PREFIX ja: <"+JA.getURI()+">\nSELECT * { ?x ja:context [ ja:cxtName
?name ; ja:cxtValue ?value ] }" ;
+        QuerySolutionMap qsm = new QuerySolutionMap() ;
+        qsm.add("x", r) ;
+        QueryExecution qExec = QueryExecutionFactory.create(qs, r.getModel(), qsm) ;
+        ResultSet rs = qExec.execSelect() ;
+        while ( rs.hasNext() )
+        {
+            QuerySolution soln = rs.next() ;
+            String name = soln.getLiteral("name").getLexicalForm() ;
+            String value = soln.getLiteral("value").getLexicalForm() ;  // Works for numbers
as well!
+            name = MappingRegistry.mapPrefixName(name) ;
+            Symbol symbol = Symbol.create(name) ;
+            context.set(symbol, value) ;
+        }
+    }
 }
 
 /*

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java
Sun Sep  4 12:19:45 2011
@@ -46,8 +46,11 @@ public class DataSourceAssembler extends
         // Non-expanding version.
         //DataSource ds = DatasetFactory.create() ;
         
+        
         // Expanding version.
         DatasetGraph dsg = DatasetGraphFactory.createMem() ;
+        AssemblerUtils.setContext(root, dsg.getContext()) ;
+        
         DataSource ds = DatasetFactory.create(dsg) ;
 
         // -------- Default graph

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DatasetAssemblerVocab.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DatasetAssemblerVocab.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DatasetAssemblerVocab.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DatasetAssemblerVocab.java
Sun Sep  4 12:19:45 2011
@@ -26,6 +26,10 @@ public class DatasetAssemblerVocab
     public static final Property pGraphAlt           = ResourceFactory.createProperty(NS,
"graphData") ;
 
     public static final Property pIndex              = ResourceFactory.createProperty(NS,
"textIndex") ;
+    
+    public static final Property pContext            = ResourceFactory.createProperty(NS,
"context") ;
+    public static final Property pCxtName            = ResourceFactory.createProperty(NS,
"cxtName") ;
+    public static final Property pCxtValue           = ResourceFactory.createProperty(NS,
"cxtValue") ;
 }
 
 /*

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/GraphStoreAssembler.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/GraphStoreAssembler.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/GraphStoreAssembler.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/GraphStoreAssembler.java
Sun Sep  4 12:19:45 2011
@@ -21,7 +21,7 @@ public class GraphStoreAssembler extends
     public Object open(Assembler a, Resource root, Mode mode)
     {
         // Same vocabulary as datasets.
-        // Have dispatched on type buy now so can just call the dataset code to build a DataSource.
+        // Have dispatched on type by now so can just call the dataset code to build a DataSource.
         
         GraphStore gs = null ;
         Object ds = super.open(a, root, mode) ;

Added: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java?rev=1165003&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java Sun
Sep  4 12:19:45 2011
@@ -0,0 +1,43 @@
+/**
+ * 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 com.hp.hpl.jena.sparql.util;
+
+import org.openjena.riot.system.PrefixMap ;
+
+/** Assist with naming symbols by URI.
+ *  This class keeps a prefix mapping so that subsystems can register their
+ *  prefix and  
+ */
+public class MappingRegistry
+{
+    private static PrefixMap mapping = new PrefixMap() ;
+    
+    public static void addPrefixMapping(String prefix, String uri)
+    {
+        mapping.add(prefix, uri) ;
+    }
+    
+    public static String mapPrefixName(String prefixName)
+    {
+        String x = mapping.expand(prefixName) ;
+        if ( x == null ) return prefixName ;
+        return x ;
+    }
+}
+

Propchange: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/util/MappingRegistry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/system/PrefixMap.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/system/PrefixMap.java?rev=1165003&r1=1165002&r2=1165003&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/system/PrefixMap.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/system/PrefixMap.java Sun Sep  4
12:19:45 2011
@@ -108,6 +108,14 @@ public class PrefixMap
         return null ;
     }
 
+    /** Expand a prefix named, return null if it can't be expanded */
+    public String expand(String prefixedName) 
+    { 
+        int i = prefixedName.indexOf(':') ;
+        if ( i < 0 ) return null ;
+        return expand(prefixedName.substring(0,i),
+                      prefixedName.substring(i+1)) ;
+    }
     
     /** Expand a prefix, return null if it can't be expanded */
     public String expand(String prefix, String localName) 



Mime
View raw message