You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2011/03/06 09:41:41 UTC

svn commit: r1078424 - in /incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src: main/scala/org/apache/clerezza/rdf/cris/ test/scala/org/apache/clerezza/rdf/cris/

Author: reto
Date: Sun Mar  6 08:41:41 2011
New Revision: 1078424

URL: http://svn.apache.org/viewvc?rev=1078424&view=rev
Log:
CLEREZZA-388: basic structure and failing test for path-virtual properties

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
    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=1078424&r1=1078423&r2=1078424&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 08:41:41 2011
@@ -88,12 +88,17 @@ class GraphIndexer(definitionGraph: Trip
 					import collection.JavaConversions._
 					new JoinVirtualProperty(propertyList)
 				} else {
-					//TODO add other cases
-					if ((r!).isInstanceOf[UriRef]) {
-						new PropertyHolder((r!).asInstanceOf[UriRef])
-					} else {
-						throw new RuntimeException(r+" is not of a knows VirtualProperty type and its not a UriRef  (it's a "+(r!).getClass)
-					}
+					if (r.hasProperty(RDF.`type`, CRIS.PathVirtualProperty)) {
+            import collection.JavaConversions._
+            new PathVirtualProperty(propertyList)
+          } else {
+            //TODO add other cases
+            if ((r!).isInstanceOf[UriRef]) {
+              new PropertyHolder((r!).asInstanceOf[UriRef])
+            } else {
+              throw new RuntimeException(r+" is not of a knows VirtualProperty type and its not a UriRef  (it's a "+(r!).getClass)
+            }
+          }
 				}
 		}
 		val indexDefinitionsResources = CRIS.IndexDefinition/-RDF.`type`

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=1078424&r1=1078423&r2=1078424&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 Sun Mar  6 08:41:41 2011
@@ -57,7 +57,20 @@ trait IndexDefinitionManager {
           definitionGraph.add(new TripleImpl(virtualProperty, CRIS.propertyList, listBNode))
           val rdfList = new RdfList(listBNode, definitionGraph)
           for (p <- l) {
-						println("adding "+p)
+            rdfList.add(asResource(p))
+          }
+          virtualProperty
+        }
+        case PathVirtualProperty(l) => {
+					if (l.size == 0) {
+						throw new RuntimeException("vp "+vp+" conatins an empty list")
+					}
+          val virtualProperty = new BNode
+          definitionGraph.add(new TripleImpl(virtualProperty, RDF.`type`, CRIS.PathVirtualProperty))
+          val listBNode = new BNode
+          definitionGraph.add(new TripleImpl(virtualProperty, CRIS.propertyList, listBNode))
+          val rdfList = new RdfList(listBNode, definitionGraph)
+          for (p <- l) {
             rdfList.add(asResource(p))
           }
           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=1078424&r1=1078423&r2=1078424&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 08:41:41 2011
@@ -39,6 +39,7 @@ class GraphIndexerTest {
 	val definitions = new SimpleMGraph
 	val dataGraph = new SimpleMGraph
 	var service: GraphIndexer = null
+  val ownsPetProperty = new UriRef("http://example.org/pet#owns")
 
 	def createPerson(firstName: String, lastName: String) {
 		val node = new GraphNode(new UriRef(Util.createURN5), dataGraph)
@@ -74,6 +75,12 @@ class GraphIndexerTest {
 		node.addPropertyValue(FOAF.firstName, "William")
 		node.addPropertyValue(FOAF.lastName, "Smith")
     node.addPropertyValue(RDFS.comment, "A person with two names")
+    //and a pet
+    val pet = new BNode
+    node.addProperty(ownsPetProperty, pet)
+    val p = new Preamble(dataGraph)
+    import p._
+    pet.addPropertyValue(FOAF.name, "Silvio")
 		service = new GraphIndexer(definitions, dataGraph)
 	}
 
@@ -232,4 +239,19 @@ class GraphIndexerTest {
 		  Assert.assertEquals(3, results.size)
     }
 	}
+
+  @Test
+  def partProperty {
+    import VirtualProperties._
+		val pathProperty = PathVirtualProperty(List(ownsPetProperty, FOAF.name))
+    val indexDefinitionManager = new IndexDefinitionManager {
+      val definitionGraph = definitions
+    }
+		indexDefinitionManager.addDefinition(FOAF.Person, FOAF.firstName, FOAF.lastName, pathProperty)
+    service.reCreateIndex();
+		{
+			val results = service.findResources(pathProperty,"Silvio")
+			Assert.assertEquals(1, results.size)
+		}
+  }
 }