Author: reto
Date: Wed Jan 19 23:06:24 2011
New Revision: 1061051

URL: http://svn.apache.org/viewvc?rev=1061051&view=rev
Log:
CLEREZZA-388: initila graphindexing now optional. added manager trait to manage 
definitions.

Added:
    
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
Modified:
    
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/pom.xml
    
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
    
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/ResourceFinder.scala

Modified: 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/pom.xml?rev=1061051&r1=1061050&r2=1061051&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/pom.xml
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/pom.xml
 Wed Jan 19 23:06:24 2011
@@ -88,7 +88,7 @@
                                <artifactId>maven-bundle-plugin</artifactId>
                                <configuration>
                                        <instructions>
-                                               
<Export-Package>org.apache.clerezza.rdf.cris.*</Export-Package>
+                                               
<Export-Package>org.apache.clerezza.rdf.cris</Export-Package>
                                                
<Bundle-SymbolicName>org.apache.clerezza.rdf.cris</Bundle-SymbolicName>
                                        </instructions>
                                </configuration>

Modified: 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala?rev=1061051&r1=1061050&r2=1061051&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
 Wed Jan 19 23:06:24 2011
@@ -44,15 +44,21 @@ import scala.actors.TIMEOUT
  *
  * Creates and provides access to indexed resources described in a graph.
  *
+ * @param definitions a TripleCollection used to look up IndexDefinitions
+ * @param baseGraph the TripleCollection containing the resources to be indexed
+ * @param index the place to store the lucene index
+ * @param createNewIndex true if the index shall be (re)created based on the 
data
+ * already in BaseGrap, when the definitions changed this should be set to true
+ *
  * @author reto
  */
 //while implemented in scala we don't expose any scala-library classes in the
 //public interface
 class GraphIndexer(definitions: TripleCollection, 
-                                  baseGraph: TripleCollection, index: 
Directory) extends ResourceFinder {
+                                  baseGraph: TripleCollection, index: 
Directory, createNewIndex: Boolean) extends ResourceFinder {
 
        def this(definitions: TripleCollection, baseGraph: TripleCollection) {
-               this(definitions, baseGraph, new RAMDirectory)
+               this(definitions, baseGraph, new RAMDirectory, true)
        }
 
        private val URI_FIELD_NAME = "resource-uri"
@@ -175,7 +181,7 @@ class GraphIndexer(definitions: TripleCo
                }
        }
 
-       def indexExistingResources() {
+       def reCreateIndex() {
                val basePreamble = new Preamble(baseGraph)
                import basePreamble._
                val instances = (for (indexedType <- indexedTypes) yield 
(indexedType)/-RDF.`type`).flatten
@@ -186,7 +192,9 @@ class GraphIndexer(definitions: TripleCo
 
        }
 
-       indexExistingResources()
+       if (createNewIndex) {
+               reCreateIndex()
+       }
 
        def findResources(conditions: Condition*) = {
                val booleanQuery = new BooleanQuery()

Added: 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala?rev=1061051&view=auto
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
 (added)
+++ 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
 Wed Jan 19 23:06:24 2011
@@ -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 org.apache.clerezza.rdf.cris
+
+import org.apache.clerezza.rdf.core.BNode
+import org.apache.clerezza.rdf.core.MGraph
+import org.apache.clerezza.rdf.core.TripleCollection
+import org.apache.clerezza.rdf.core.UriRef
+import org.apache.clerezza.rdf.ontologies.RDF
+import org.apache.clerezza.rdf.scala.utils.Preamble
+import org.apache.clerezza.rdf.utils.GraphNode
+import ontologies._
+
+trait IndexDefinitionManager {
+
+       def definitionGraph: MGraph
+
+       /**
+        * Defines an index for the specified types and properties, removing
+        * previous index deinitions for that type
+        */
+       def addDefinition(rdfType: UriRef, properties: UriRef*) {
+               deleteDefinition(rdfType)
+               val node = new GraphNode(new BNode(), definitionGraph)
+               node.addProperty(RDF.`type`, CRIS.IndexDefinition)
+               node.addProperty(CRIS.indexedType, rdfType)
+               for (p <- properties) node.addProperty(CRIS.indexedProperty, p)
+       }
+
+       /**
+        * remove index definitions for the specified rdf type
+        */
+       def deleteDefinition(rdfType: UriRef) {
+               val preamble = new Preamble(definitionGraph)
+               import preamble._
+               for (id <- rdfType/-CRIS.indexedType) {
+                       id.deleteNodeContext()
+               }
+       }
+}

Modified: 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/ResourceFinder.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/ResourceFinder.scala?rev=1061051&r1=1061050&r2=1061051&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/ResourceFinder.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/ResourceFinder.scala
 Wed Jan 19 23:06:24 2011
@@ -27,6 +27,9 @@ import org.apache.lucene.search.Wildcard
 import java.util.List
 
 trait ResourceFinder {
+       
+       def reCreateIndex()
+
        def findResources(conditions: Condition*): List[Resource]
 
        def findResources(property: UriRef, pattern: String): List[Resource] = {


Reply via email to