incubator-clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1074110 - in /incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris: GraphIndexer.scala IndexDefinitionManager.scala VirtualProperty.scala
Date Thu, 24 Feb 2011 11:04:12 GMT
Author: reto
Date: Thu Feb 24 11:04:12 2011
New Revision: 1074110

URL: http://svn.apache.org/viewvc?rev=1074110&view=rev
Log:
CLEREZZA-388: prepared for supporting virtual properties

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

Modified: incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala?rev=1074110&r1=1074109&r2=1074110&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
(original)
+++ incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.scala
Thu Feb 24 11:04:12 2011
@@ -50,7 +50,7 @@ import org.apache.lucene.analysis.Analyz
  * @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
+ * already in BaseGraph, when the definitions changed this should be set to true
  *
  * @author reto
  */
@@ -69,7 +69,7 @@ class GraphIndexer(definitions: TripleCo
 	private[this] val URI_FIELD_NAME = "resource-uri"
 	private[this] val logger = LoggerFactory.getLogger(classOf[GraphIndexer])
 
-	private[this] var type2IndexedProperties = Map[UriRef, Seq[UriRef]]()
+	private[this] var type2IndexedProperties = Map[UriRef, Seq[VirtualProperty]]()
 	private[this] var property2TypeMap = Map[UriRef, mutable.Set[UriRef]]()
 	//private[this] var indexedProperties: Seq[UriRef] = null
 
@@ -77,18 +77,20 @@ class GraphIndexer(definitions: TripleCo
 		val definitionsPreamble = new Preamble(definitions)
 		import definitionsPreamble._
 		val indexDefinitionsResources = CRIS.IndexDefinition/-RDF.`type`
-		type2IndexedProperties = Map((for (d <- indexDefinitionsResources;
-										   tUri = (d/CRIS.indexedType!).asInstanceOf[UriRef])
-						yield (tUri,
-						for (p <- d/CRIS.indexedProperty) yield {
-						 val pUri = (p!).asInstanceOf[UriRef]
-						 if (property2TypeMap.contains(pUri)) {
-							 property2TypeMap(pUri) += (tUri)
-						 } else {
-							 property2TypeMap += (pUri -> mutable.Set(tUri))
-						 }
-						 pUri
-					 })): _*)
+		def type2IndexedPropertiesTuples: Seq[(UriRef, Seq[VirtualProperty])] =
+			for (d <- indexDefinitionsResources;
+					 tUri = (d / CRIS.indexedType !).asInstanceOf[UriRef])
+			yield (tUri,
+				for (p <- d / CRIS.indexedProperty) yield {
+					val pUri = (p !).asInstanceOf[UriRef]
+					if (property2TypeMap.contains(pUri)) {
+						property2TypeMap(pUri) += (tUri)
+					} else {
+						property2TypeMap += (pUri -> mutable.Set(tUri))
+					}
+					new PropertyHolder(pUri)
+				})
+		type2IndexedProperties = Map(type2IndexedPropertiesTuples: _*)
 	}
 	
 	processDefinitions()
@@ -104,7 +106,7 @@ class GraphIndexer(definitions: TripleCo
 			for (e <- events) {
 				val triple = e.getTriple
 				logger.debug("processing addition of type "+triple.getObject)
-        //not understanding why contains isn't working here (why dynamic conversion seems
to be applied)
+				//not understanding why contains isn't working here (why dynamic conversion seems to
be applied)
 				if (type2IndexedProperties.containsKey(triple.getObject)) {
 					scheduleForReindex(triple.getSubject)
 				}
@@ -170,12 +172,12 @@ class GraphIndexer(definitions: TripleCo
 		
 		def resourceToDocument(resource: UriRef, resourceType: UriRef) = {
 			val doc = new Document
-			for (property <- type2IndexedProperties(resourceType)) {
-				logger.debug("indexing "+property+" with values "+(resource/property).length)
-				for (propertyValue <- resource/property) {
-					logger.debug("indexing "+property+" with value "+(propertyValue*))
-					doc.add(new Field(property.getUnicodeString,
-									  propertyValue*,
+			for (vProperty <- type2IndexedProperties(resourceType)) {
+				logger.debug("indexing "+vProperty+" with values "+(vProperty.value(resource)).length)
+				for (propertyValue <- vProperty.value(resource)) {
+					logger.debug("indexing "+vProperty+" with value "+(propertyValue))
+					doc.add(new Field(vProperty.name,
+									  propertyValue,
 									  Field.Store.YES,
 									  Field.Index.NOT_ANALYZED))
 				}
@@ -247,4 +249,4 @@ class GraphIndexer(definitions: TripleCo
 		}
 		result
 	}
-}
+}
\ No newline at end of file

Modified: incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala?rev=1074110&r1=1074109&r2=1074110&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
(original)
+++ incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManager.scala
Thu Feb 24 11:04:12 2011
@@ -34,7 +34,7 @@ trait IndexDefinitionManager {
 
 	/**
 	 * Defines an index for the specified types and properties, removing
-	 * previous index deinitions for that type
+	 * previous index definitions for that type
 	 */
 	def addDefinition(rdfType: UriRef, properties: UriRef*) {
 		deleteDefinition(rdfType)

Added: incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala?rev=1074110&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
(added)
+++ incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
Thu Feb 24 11:04:12 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.UriRef
+import org.apache.clerezza.rdf.scala.utils.RichGraphNode
+import org.apache.clerezza.rdf.scala.utils.Preamble._
+
+abstract class VirtualProperty {
+	def name: String
+	def value(node: RichGraphNode): Seq[String]
+}
+
+class PropertyHolder(property: UriRef) extends VirtualProperty {
+	def name = property.getUnicodeString
+	def value(node: RichGraphNode): Seq[String] = for (v <- node/property) yield v*
+}
+
+class JoinVirtualProperty(properties: List[VirtualProperty]) extends VirtualProperty {
+	def name = "Join of ..."
+	def value(node: RichGraphNode): Seq[String] = Seq("")
+}
+
+class PathVirtualProperty(properties: List[VirtualProperty]) extends VirtualProperty {
+	def name = "Path ..."
+	def value(node: RichGraphNode): Seq[String] = Seq("")
+}
\ No newline at end of file



Mime
View raw message