Author: reto
Date: Mon Feb 28 11:10:21 2011
New Revision: 1075291
URL: http://svn.apache.org/viewvc?rev=1075291&view=rev
Log:
CLEREZZA-388: string serialization of virtaul properties
Added:
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.scala
Modified:
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/main/scala/org/apache/clerezza/rdf/cris/VirtualProperty.scala
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/WilcardCondition.scala
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=1075291&r1=1075290&r2=1075291&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
Mon Feb 28 11:10:21 2011
@@ -19,14 +19,12 @@
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._
+import org.apache.clerezza.rdf.core._
+import impl.TripleImpl
+import org.apache.clerezza.rdf.utils.{RdfList, GraphNode}
trait IndexDefinitionManager {
@@ -36,12 +34,33 @@ trait IndexDefinitionManager {
* Defines an index for the specified types and properties, removing
* previous index definitions for that type
*/
- def addDefinition(rdfType: UriRef, properties: UriRef*) {
+ def addDefinition(rdfType: UriRef, firstProperty: UriRef, properties:
UriRef*) {
+ val virtualProperties = for (u <- (firstProperty :: properties.toList))
yield new PropertyHolder(u)
+ addDefinition(rdfType, virtualProperties: _*)
+ }
+ def addDefinition(rdfType: UriRef, properties: VirtualProperty*) {
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)
+ //returns either the holded property, or the resource describing the
virtual property
+ def asResource(vp: VirtualProperty): Resource = {
+ vp match {
+ case PropertyHolder(p) => p
+ case JoinVirtualProperty(l) => {
+ val virtualProperty = new BNode
+ definitionGraph.add(new TripleImpl(virtualProperty, RDF.`type`,
CRIS.JoinVirtualProperty))
+ val listBNode = new BNode
+ definitionGraph.add(new TripleImpl(virtualProperty,
CRIS.JoinVirtualProperty, listBNode))
+ val rdfList = new RdfList(listBNode, definitionGraph)
+ for (p <- l) {
+ rdfList.add(asResource(p))
+ }
+ virtualProperty
+ }
+ }
+ }
+ for (p <- properties) node.addProperty(CRIS.indexedProperty,
asResource(p))
}
/**
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=1075291&r1=1075290&r2=1075291&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
Mon Feb 28 11:10:21 2011
@@ -33,18 +33,18 @@ abstract class VirtualProperty {
def value(node: RichGraphNode): Seq[String]
}
-class PropertyHolder(property: UriRef) extends VirtualProperty {
+case class PropertyHolder(property: UriRef) extends VirtualProperty {
val stringKey = property.getUnicodeString
def value(node: RichGraphNode): Seq[String] = for (v <- node/property)
yield v*
}
-class JoinVirtualProperty(properties: List[VirtualProperty]) extends
VirtualProperty {
+case class JoinVirtualProperty(properties: List[VirtualProperty]) extends
VirtualProperty {
val stringKey = "J"+VirtualProperty.listDigest(properties)
def value(node: RichGraphNode): Seq[String] = Seq("")
}
-class PathVirtualProperty(properties: List[VirtualProperty]) extends
VirtualProperty {
- val stringKey = "P"+VirtualProperty.listDigest(properties)
+case class PathVirtualProperty(properties: List[VirtualProperty]) extends
VirtualProperty {
+ val stringKey = "J"+VirtualProperty.listDigest(properties)
def value(node: RichGraphNode): Seq[String] = Seq("")
}
@@ -55,4 +55,7 @@ object VirtualProperty {
}).mkString("|")
Util.sha1(longString)
}
+}
+object VirtualProperties {
+ implicit def property2Virtual(property: UriRef) = new
PropertyHolder(property)
}
\ No newline at end of file
Modified:
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/WilcardCondition.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/WilcardCondition.scala?rev=1075291&r1=1075290&r2=1075291&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/WilcardCondition.scala
(original)
+++
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/WilcardCondition.scala
Mon Feb 28 11:10:21 2011
@@ -32,3 +32,7 @@ case class WildcardCondition(property: V
property.stringKey, pattern))
}
+
+object WildcardCondition {
+ def apply(uriRefProperty: UriRef, pattern: String) = new
WildcardCondition(uriRefProperty, pattern)
+}
\ No newline at end of file
Added:
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.scala?rev=1075291&view=auto
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.scala
(added)
+++
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/test/scala/org/apache/clerezza/rdf/cris/IndexDefinitionManagerTest.scala
Mon Feb 28 11:10:21 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.impl.SimpleMGraph
+import org.apache.clerezza.rdf.utils.GraphNode
+import org.apache.clerezza.rdf.core.{BNode, UriRef}
+import org.apache.clerezza.rdf.ontologies.{FOAF, RDF}
+import org.apache.clerezza.rdf.cris.ontologies.CRIS
+import org.junit.{Assert, Test}
+
+class IndexDefinitionManagerTest {
+
+ @Test
+ def createDefinitionGraph() {
+ val manuallyCreatedGraph = new SimpleMGraph
+ def createDefinition(rdfType: UriRef, properties: UriRef*) {
+ val node = new GraphNode(new BNode,
manuallyCreatedGraph)
+ node.addProperty(RDF.`type`, CRIS.IndexDefinition)
+ node.addProperty(CRIS.indexedType, rdfType)
+ for (p <- properties) {
+ node.addProperty(CRIS.indexedProperty, p)
+ }
+ }
+
+ val indexManagerGraph = new SimpleMGraph
+ val indexDefinitionManager = new IndexDefinitionManager {
+ val definitionGraph = indexManagerGraph
+ }
+ indexDefinitionManager.addDefinition(FOAF.Person, FOAF.firstName,
FOAF.lastName)
+ createDefinition(FOAF.Person, FOAF.firstName, FOAF.lastName)
+ Assert.assertEquals(manuallyCreatedGraph.getGraph,
indexManagerGraph.getGraph)
+ }
+
+ @Test
+ def createJoinIndexProperty() {
+ import VirtualProperties._
+ val indexManagerGraph = new SimpleMGraph
+ val indexDefinitionManager = new IndexDefinitionManager {
+ val definitionGraph = indexManagerGraph
+ }
+ indexDefinitionManager.addDefinition(FOAF.Person,
JoinVirtualProperty(List(FOAF.firstName, FOAF.lastName)))
+ val typeStmtIter = indexManagerGraph.filter(null, RDF.`type`,
CRIS.JoinVirtualProperty)
+ Assert.assertTrue(typeStmtIter.hasNext)
+ //Assert.assertEquals(manuallyCreatedGraph.getGraph,
indexManagerGraph.getGraph)
+ }
+}
\ No newline at end of file