Author: reto
Date: Fri Mar 4 08:42:40 2011
New Revision: 1077849
URL: http://svn.apache.org/viewvc?rev=1077849&view=rev
Log:
Added JoinProperty api support and test
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=1077849&r1=1077848&r2=1077849&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
Fri Mar 4 08:42:40 2011
@@ -56,8 +56,9 @@ import org.apache.lucene.analysis.Analyz
*/
//while implemented in scala we don't expose any scala-library classes in the
//public interface
-class GraphIndexer(definitions: TripleCollection,
- baseGraph: TripleCollection, index:
Directory, createNewIndex: Boolean) extends ResourceFinder {
+class GraphIndexer(definitionGraph: TripleCollection,
+ baseGraph: TripleCollection,
index: Directory, createNewIndex: Boolean)
+ extends ResourceFinder {
/**
* Creates an in-memory index
@@ -70,25 +71,44 @@ class GraphIndexer(definitions: TripleCo
private[this] val logger =
LoggerFactory.getLogger(classOf[GraphIndexer])
private[this] var type2IndexedProperties = Map[UriRef,
Seq[VirtualProperty]]()
- private[this] var property2TypeMap = Map[UriRef, mutable.Set[UriRef]]()
+ private[this] var property2TypeMap = Map[VirtualProperty,
mutable.Set[UriRef]]()
//private[this] var indexedProperties: Seq[UriRef] = null
protected def processDefinitions() {
- val definitionsPreamble = new Preamble(definitions)
+ val definitionsPreamble = new Preamble(definitionGraph)
import definitionsPreamble._
+ def asVirtualProperty(r: RichGraphNode): VirtualProperty = {
+ lazy val propertyList = {
+ import collection.JavaConversions._
+ (for (childPropertyResource <- new
RdfList(r/CRIS.propertyList)) yield {
+
asVirtualProperty(childPropertyResource)
+ }).toList
+ }
+ if (r.hasProperty(RDF.`type`,
CRIS.JoinVirtualProperty)) {
+ 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)
+ }
+ }
+ }
val indexDefinitionsResources = CRIS.IndexDefinition/-RDF.`type`
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)
+ val vProp = asVirtualProperty(p)
+ if (property2TypeMap.contains(vProp)) {
+ property2TypeMap(vProp) +=
(tUri)
} else {
- property2TypeMap += (pUri ->
mutable.Set(tUri))
+ property2TypeMap += (vProp ->
mutable.Set(tUri))
}
- new PropertyHolder(pUri)
+ vProp
})
type2IndexedProperties = Map(type2IndexedPropertiesTuples: _*)
}
@@ -129,7 +149,8 @@ class GraphIndexer(definitions: TripleCo
}, new FilterTriple(null, null, null) {
override def `match`(triple: Triple) = {
val predicate = triple.getPredicate
- property2TypeMap.contains(predicate)
+ //TODO check indirectly involved properties
+ property2TypeMap.contains(new PropertyHolder(predicate))
}
})
@@ -175,7 +196,7 @@ class GraphIndexer(definitions: TripleCo
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))
+ logger.info("indexing "+vProperty+"
with value "+(propertyValue))
doc.add(new Field(vProperty.stringKey,
propertyValue,
Field.Store.YES,
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=1077849&r1=1077848&r2=1077849&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
Fri Mar 4 08:42:40 2011
@@ -48,12 +48,16 @@ trait IndexDefinitionManager {
vp match {
case PropertyHolder(p) => p
case JoinVirtualProperty(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.JoinVirtualProperty))
val listBNode = new BNode
- definitionGraph.add(new TripleImpl(virtualProperty,
CRIS.JoinVirtualProperty, listBNode))
+ 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
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=1077849&r1=1077848&r2=1077849&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
Fri Mar 4 08:42:40 2011
@@ -32,7 +32,6 @@ import org.apache.lucene.store._
import org.apache.lucene.index.IndexWriter
import org.apache.lucene.util.Version
import org.wymiwyg.commons.util.Util
-import java.util.List
import org.junit._
class GraphIndexerTest {
@@ -168,4 +167,23 @@ class GraphIndexerTest {
val results2 = service.findResources(FOAF.firstName, "*Jane*")
Assert.assertEquals(2, results2.length)
}
+
+ @Test
+ def testJoinProperty {
+ import VirtualProperties._
+ val joinProperty = JoinVirtualProperty(List(FOAF.firstName,
FOAF.lastName))
+ val indexDefinitionManager = new IndexDefinitionManager {
+ val definitionGraph = definitions
+ }
+ indexDefinitionManager.addDefinition(FOAF.Person, joinProperty)
+ service.reCreateIndex();
+ {
+ val results = service.findResources(joinProperty,"John")
+ Assert.assertEquals(2, results.size)
+ }
+ {
+ val results = service.findResources(joinProperty,"John
Doe")
+ Assert.assertEquals(1, results.size)
+ }
+ }
}