Author: reto
Date: Sun Mar  6 21:42:24 2011
New Revision: 1078588

URL: http://svn.apache.org/viewvc?rev=1078588&view=rev
Log:
CLEREZZA-388: added test for modification od indirect property, currently 
failing with RuntimeException

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/VirtualProperty.scala
    
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/GraphIndexerTest.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=1078588&r1=1078587&r2=1078588&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
 Sun Mar  6 21:42:24 2011
@@ -156,11 +156,23 @@ class GraphIndexer(definitionGraph: Trip
                        import scala.collection.JavaConversions._
                        for (e <- events) {
                                val triple = e.getTriple
-                               val resource = triple.getSubject
-                               val types = for (tn <- resource/RDF.`type`) 
yield tn! ;
-                               if (types.exists(t => 
type2IndexedProperties.containsKey(t))) {
-                                       scheduleForReindex(resource)
-                               }
+                               def followInversePaths(resource: Resource, 
pathToIndexedResource: List[UriRef]): Seq[Resource] = {
+          if (pathToIndexedResource.size == 0) {
+            Seq[Resource]()
+          } else {
+            throw new RuntimeException("modification of indirect properties 
not yet supported")
+          }
+        }
+        val predicate = triple.getPredicate
+        val vProperties = property2IncludingVProperty(predicate)
+        val indexedResources/*: Seq[Resource]*/ = (for (vProperty <- 
vProperties)
+          yield followInversePaths(triple.getSubject, 
vProperty.pathToIndexedResource(predicate))).flatten
+                               for (resource <- indexedResources) {
+          val types = for (tn <- resource/RDF.`type`) yield tn!;
+          if (types.exists(t => type2IndexedProperties.containsKey(t))) {
+            scheduleForReindex(resource)
+          }
+        }
                        }
                }
        }, new FilterTriple(null, null, null) {

Modified: 
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=1078588&r1=1078587&r2=1078588&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
 Sun Mar  6 21:42:24 2011
@@ -37,13 +37,27 @@ abstract class VirtualProperty {
         */
        val stringKey: String
        def value(node: RichGraphNode): Seq[String]
-  val baseProperties: Set[UriRef]
+
+  /**
+   * The RDF properties that are used to compute the value of this virtual 
property
+   */
+  protected[cris] val baseProperties: Set[UriRef]
+
+  /**
+   * The shortest path of inverse RDF properties from property to the indexed 
resource, this is an
+   * empty List for PropertyHolders, for properties in a PathVirtualProperties 
this is a list with the elements
+   * passed to its constructor till the first occurrence of property in 
reverse order.<br/>
+   * This method just returns the shortest path as virtual properties with the 
same base property in
+   * different positions are assumed to be very rare.
+   */
+  protected[cris] def pathToIndexedResource(property: UriRef): List[UriRef]
 }
 
 case class PropertyHolder(property: UriRef) extends VirtualProperty {
        val stringKey = property.getUnicodeString
        def value(node: RichGraphNode): Seq[String] = for (v <- node/property) 
yield v*
   val baseProperties = Set(property)
+  protected[cris] def pathToIndexedResource(property: UriRef) = List[UriRef]()
 }
 
 case class JoinVirtualProperty(properties: List[VirtualProperty]) extends 
VirtualProperty {
@@ -53,6 +67,17 @@ case class JoinVirtualProperty(propertie
   }).mkString(" ")
        def value(node: RichGraphNode): Seq[String] = Seq(singleValue(node))
   val baseProperties = (for (p <- properties) yield 
p.baseProperties).flatten.toSet
+  protected[cris] def pathToIndexedResource(property: UriRef) = {
+    (for (p <- properties) yield {
+      p.pathToIndexedResource(property)
+    }).foldLeft(List[UriRef]())((p1,p2) => {
+      if (p1.size > p2.size) {
+        p1
+      } else {
+        p2
+      }
+    })
+  }
 }
 
 case class PathVirtualProperty(properties: List[UriRef]) extends 
VirtualProperty {
@@ -68,6 +93,7 @@ case class PathVirtualProperty(propertie
    getPathResults(node, properties)
   }
   val baseProperties = properties.toSet
+  protected[cris] def pathToIndexedResource(property: UriRef) =  
properties.span(p => p != property)._1
 }
 
 object VirtualProperty {

Modified: 
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/GraphIndexerTest.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/GraphIndexerTest.scala?rev=1078588&r1=1078587&r2=1078588&view=diff
==============================================================================
--- 
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/GraphIndexerTest.scala
 (original)
+++ 
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/GraphIndexerTest.scala
 Sun Mar  6 21:42:24 2011
@@ -267,5 +267,12 @@ class GraphIndexerTest {
                  val results = service.findResources(pathProperty,"Silvio")
                  Assert.assertEquals(2, results.size)
     }
+    //lets give that pet an additional name
+    pet.addPropertyValue(FOAF.name, "Fifi")
+    Thread.sleep(1000);
+    {
+                 val results = service.findResources(pathProperty,"Fifi")
+                 Assert.assertEquals(1, results.size)
+    }
   }
 }


Reply via email to