jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sal...@apache.org
Subject [1/3] jena git commit: Compacted and simplified changes to jena-text to support ppd-text-index.
Date Fri, 13 Mar 2015 20:27:33 GMT
Repository: jena
Updated Branches:
  refs/heads/master 797c52a71 -> 7952d35ba


Compacted and simplified changes to jena-text
to support ppd-text-index.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/3ff763ac
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/3ff763ac
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/3ff763ac

Branch: refs/heads/master
Commit: 3ff763ac184dd49bdc3b6ceff9acb778aac29eae
Parents: 8a67230
Author: Chris Dollin <ehog.hedge@googlemail.com>
Authored: Wed Mar 11 15:13:43 2015 +0000
Committer: Chris Dollin <ehog.hedge@googlemail.com>
Committed: Wed Mar 11 15:13:43 2015 +0000

----------------------------------------------------------------------
 .../jena/query/text/DatasetGraphText.java       |  2 +-
 .../org/apache/jena/query/text/TextIndex.java   |  1 +
 .../apache/jena/query/text/TextIndexLucene.java | 13 +++++++
 .../apache/jena/query/text/TextIndexSolr.java   |  5 +++
 .../text/assembler/TextDatasetAssembler.java    | 37 ++++++++++++++------
 5 files changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3ff763ac/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
index f856681..f746a71 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/DatasetGraphText.java
@@ -142,6 +142,7 @@ public class DatasetGraphText extends DatasetGraphMonitor implements Transaction
      */
     @Override
     public void commit() {
+    	super.getMonitor().finish() ;
         // Phase 1
         if (readWriteMode.get() == ReadWrite.WRITE) {
             try {
@@ -167,7 +168,6 @@ public class DatasetGraphText extends DatasetGraphMonitor implements Transaction
             throw new TextIndexException(t);
         }
         readWriteMode.set(null);
-        super.getMonitor().finish() ;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/3ff763ac/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
index 3aabd5b..7d3092e 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
@@ -36,6 +36,7 @@ public interface TextIndex extends Closeable //, Transactional
     
     // Update operations
     void addEntity(Entity entity) ;
+    void updateEntity(Entity entity) ;
     
     
     // read operations

http://git-wip-us.apache.org/repos/asf/jena/blob/3ff763ac/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
index 12ff1ea..7d42d9d 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
@@ -38,6 +38,7 @@ import org.apache.lucene.index.DirectoryReader ;
 import org.apache.lucene.index.IndexReader ;
 import org.apache.lucene.index.IndexWriter ;
 import org.apache.lucene.index.IndexWriterConfig ;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.queryparser.classic.ParseException ;
 import org.apache.lucene.queryparser.classic.QueryParser ;
 import org.apache.lucene.queryparser.classic.QueryParserBase ;
@@ -188,6 +189,18 @@ public class TextIndexLucene implements TextIndex {
             throw new TextIndexException(ex) ;
         }
     }
+    
+    @Override public void updateEntity(Entity entity) {
+        if ( log.isDebugEnabled() )
+            log.debug("Update entity: " + entity) ;
+        try {
+        	Document doc = doc(entity);
+        	Term term = new Term(docDef.getEntityField(), entity.getId());
+        	indexWriter.updateDocument(	term, doc);
+        } catch (IOException e) {
+            throw new TextIndexException(e) ;
+        }
+    }
 
     @Override
     public void addEntity(Entity entity) {

http://git-wip-us.apache.org/repos/asf/jena/blob/3ff763ac/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
index 45571bc..84bd11a 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
@@ -53,6 +53,11 @@ public class TextIndexSolr implements TextIndex
         this.solrServer = server ;
         this.docDef = def ;
     }
+
+	@Override
+	public void updateEntity(Entity entity) {
+		throw new RuntimeException("TextIndexSolr.updateEntity not implemented.");
+	}
     
     @Override
     public void prepareCommit() { }

http://git-wip-us.apache.org/repos/asf/jena/blob/3ff763ac/jena-text/src/main/java/org/apache/jena/query/text/assembler/TextDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/assembler/TextDatasetAssembler.java
b/jena-text/src/main/java/org/apache/jena/query/text/assembler/TextDatasetAssembler.java
index 7fb30cb..f3eea7c 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/assembler/TextDatasetAssembler.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/assembler/TextDatasetAssembler.java
@@ -32,6 +32,7 @@ import com.hp.hpl.jena.assembler.assemblers.AssemblerBase ;
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.rdf.model.Resource ;
 import com.hp.hpl.jena.sparql.ARQConstants ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
 import com.hp.hpl.jena.sparql.core.assembler.DatasetAssembler ;
 import com.hp.hpl.jena.sparql.util.Loader ;
 import com.hp.hpl.jena.sparql.util.graph.GraphUtils ;
@@ -65,22 +66,36 @@ public class TextDatasetAssembler extends AssemblerBase implements Assembler
         TextDocProducer textDocProducer = null ;
         if (null != textDocProducerNode) {
             Class<?> c = Loader.loadClass(textDocProducerNode.getURI(), TextDocProducer.class)
;
-            try
-            {
-                Constructor<?> ctor = c.getConstructor(TextIndex.class) ;
-                textDocProducer = (TextDocProducer)ctor.newInstance(textIndex) ;
-            }
-            catch (Exception ex)
-            {
-                String className = textDocProducerNode.getURI().substring(ARQConstants.javaClassURIScheme.length())
;
-                Log.warn(Loader.class, "Exception during instantiation '"+className+"': "+ex.getMessage())
;
-                return null ;
+            
+            String className = textDocProducerNode.getURI().substring(ARQConstants.javaClassURIScheme.length())
;
+            Constructor<?> dyadic = getConstructor(c, DatasetGraph.class, TextIndex.class);
+            Constructor<?> monadic = getConstructor(c, TextIndex.class);
+            
+            try {
+            	if (dyadic != null) {
+            		textDocProducer = (TextDocProducer) dyadic.newInstance(ds.asDatasetGraph(),
textIndex) ;
+            	} else if (monadic != null) {
+            		textDocProducer = (TextDocProducer) monadic.newInstance(textIndex) ;
+            	} else {
+            		Log.warn(Loader.class, "Exception during instantiation '"+className+"' no TextIndex
or DatasetGraph,Index constructor" );
+            	}
+            } catch (Exception ex) {
+            	Log.warn(Loader.class, "Exception during instantiation '"+className+"': "+ex.getMessage())
;
+            	return null ;            	
             }
         }
         
         Dataset dst = TextDatasetFactory.create(ds, textIndex, true, textDocProducer) ;
         return dst ;
-        
     }
+	
+	private Constructor<?> getConstructor(Class<?> c, Class<?> ...types) {
+		try {
+			return c.getConstructor(types);
+		} catch (NoSuchMethodException e) {			
+			return null;	
+		}
+	}
+	
 }
 


Mime
View raw message