You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ca...@apache.org on 2011/06/16 09:38:14 UTC
svn commit: r1136305 - in
/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena:
query/larq/AssemblerLARQ.java sparql/core/assembler/DataSourceAssembler.java
Author: castagna
Date: Thu Jun 16 07:38:14 2011
New Revision: 1136305
URL: http://svn.apache.org/viewvc?rev=1136305&view=rev
Log:
This is for JENA-63 to log if LARQ is not found and to fall back to Lucene in the ARQ distribution.
Added:
incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java (with props)
Modified:
incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/core/assembler/DataSourceAssembler.java
Added: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java?rev=1136305&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java Thu Jun 16 07:38:14 2011
@@ -0,0 +1,105 @@
+/*
+ * (c) Copyright 2010 Talis Information Ltd
+ * (c) Copyright 2010, 2011 Talis Systems Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package com.hp.hpl.jena.query.larq;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.assembler.exceptions.AssemblerException;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.core.assembler.DatasetAssemblerVocab;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+
+public class AssemblerLARQ extends AssemblerBase implements Assembler
+{
+ /** Vocabulary
+ * ja:textIndex ....
+ */
+
+ static { LARQ.init(); }
+
+ @Override
+ public Object open(Assembler a, Resource root, Mode mode)
+ {
+ LARQ.init();
+
+ if ( ! GraphUtils.exactlyOneProperty(root, DatasetAssemblerVocab.pIndex) )
+ throw new AssemblerException(root, "Required: exactly one index property" ) ;
+
+ try
+ {
+ String indexPath = GraphUtils.getAsStringValue(root, DatasetAssemblerVocab.pIndex) ;
+ return make(null, indexPath) ;
+ } catch (Exception ex)
+ {
+ throw new ARQLuceneException("Failed to assemble Lucene index", ex) ;
+ }
+ }
+
+ public static IndexLARQ make (Dataset dataset, String indexPath) throws CorruptIndexException, IOException
+ {
+ Directory directory = FSDirectory.getDirectory(new File(indexPath)) ;
+ IndexReader indexReader = null;
+ if ( dataset != null ) {
+ IndexWriter indexWriter = new IndexWriter(directory, new StandardAnalyzer());
+ IndexBuilderModel larqBuilder = new IndexBuilderString(indexWriter) ;
+ dataset.getDefaultModel().register(larqBuilder);
+ for ( Iterator<String> iter = dataset.listNames() ; iter.hasNext() ; ) {
+ String g = iter.next() ;
+ dataset.getNamedModel(g).register(larqBuilder) ;
+ }
+ indexReader = IndexReader.open(directory) ;
+ } else {
+ indexReader = IndexReader.open(directory) ;
+ }
+ IndexLARQ indexLARQ = new IndexLARQ(indexReader) ;
+ LARQ.setDefaultIndex(indexLARQ) ;
+ return indexLARQ ;
+ }
+
+}
+
+/*
+ * (c) Copyright 2010 Talis Information Ltd
+ * (c) Copyright 2010, 2011 Talis Systems Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
Propchange: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/larq/AssemblerLARQ.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1136305&r1=1136304&r2=1136305&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 Thu Jun 16 07:38:14 2011
@@ -94,9 +94,16 @@ public class DataSourceAssembler extends
public Object createTextIndex (Dataset ds, Resource root)
{
+ Object result = createTextIndex (ds, root, "org.apache.jena.larq.assembler.AssemblerLARQ") ;
+ if ( result == null ) result = createTextIndex (ds, root, "com.hp.hpl.jena.query.larq.AssemblerLARQ") ;
+ return result ;
+ }
+
+ protected Object createTextIndex (Dataset ds, Resource root, String className)
+ {
try
{
- Class<?> clazz = Class.forName("org.apache.jena.larq.assembler.AssemblerLARQ") ;
+ Class<?> clazz = Class.forName(className) ;
if ( root.hasProperty(DatasetAssemblerVocab.pIndex) )
{
try {
@@ -107,11 +114,11 @@ public class DataSourceAssembler extends
Object args[] = new Object[] { ds, index } ;
return method.invoke(clazz, args) ;
} catch (Exception e) {
- Log.warn(DataSourceAssembler.class, "Unable to initialize LARQ: " + e.getMessage()) ;
+ Log.warn(DataSourceAssembler.class, String.format("Unable to initialize LARQ using %s: %s", className, e.getMessage())) ;
}
}
} catch(ClassNotFoundException e) {
- //
+ Log.info(DataSourceAssembler.class, "LARQ initialization: class " + className + " not in the classpath.") ;
}
return null ;