Author: reto
Date: Fri Feb 18 20:19:06 2011
New Revision: 1072129
URL: http://svn.apache.org/viewvc?rev=1072129&view=rev
Log:
CLEREZZA-388: associating 1-step paths (properties) to types, failing tests
Modified:
incubator/clerezza/issues/CLEREZZA-388/rdf.cris/core/src/main/scala/org/apache/clerezza/rdf/cris/GraphIndexer.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=1072129&r1=1072128&r2=1072129&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 Feb 18 20:19:06 2011
@@ -39,6 +39,7 @@ import java.util.ArrayList
import java.util.List
import scala.actors.DaemonActor
import scala.actors.TIMEOUT
+import scala.collection.mutable
/**
*
@@ -63,18 +64,27 @@ class GraphIndexer(definitions: TripleCo
private[this] val URI_FIELD_NAME = "resource-uri"
private[this] val logger =
LoggerFactory.getLogger(classOf[GraphIndexer])
- private[this] var indexedTypes: Seq[Resource] = null
- private[this] var indexedProperties: Seq[UriRef] = null
+
+ private[this] var type2IndexedProperties = Map[UriRef, Seq[UriRef]]()
+ private[this] var property2TypeMap = Map[UriRef, mutable.Set[UriRef]]()
+ //private[this] var indexedProperties: Seq[UriRef] = null
def processDefinitions() {
val definitionsPreamble = new Preamble(definitions)
import definitionsPreamble._
- val indexDefinitions = CRIS.IndexDefinition/-RDF.`type`
- val tmp = for (d <- indexDefinitions) yield
(d/CRIS.indexedType!)
- //indexedTypes = for (d <- indexDefinitions) yield
d/CRIS.indexedType!
- indexedTypes = tmp
- indexedProperties = for (p <- (for (d <- indexDefinitions)
- yield (d/CRIS.indexedProperty)).flatten) yield
(p!).asInstanceOf[UriRef]
+ 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
+ })): _*)
}
processDefinitions()
@@ -90,7 +100,7 @@ class GraphIndexer(definitions: TripleCo
for (e <- events) {
val triple = e.getTriple
logger.debug("processing addition of type
"+triple.getObject)
- if (indexedTypes.contains(triple.getObject)) {
+ if
(type2IndexedProperties.contains(triple.getObject)) {
scheduleForReindex(triple.getSubject)
}
}
@@ -104,7 +114,7 @@ class GraphIndexer(definitions: TripleCo
val triple = e.getTriple
val resource = triple.getSubject
val types = for (tn <- resource/RDF.`type`)
yield tn! ;
- if (types.exists(t =>
indexedTypes.contains(t))) {
+ if (types.exists(t =>
type2IndexedProperties.contains(t))) {
scheduleForReindex(resource)
}
}
@@ -112,7 +122,7 @@ class GraphIndexer(definitions: TripleCo
}, new FilterTriple(null, null, null) {
override def `match`(triple: Triple) = {
val predicate = triple.getPredicate
- indexedProperties.contains(predicate)
+ property2TypeMap.contains(predicate)
}
})
@@ -153,9 +163,9 @@ class GraphIndexer(definitions: TripleCo
def indexResource(resource: Resource, writer: IndexWriter) {
- def resourceToDocument(resource: Resource) = {
+ def resourceToDocument(resource: UriRef, resourceType: UriRef)
= {
val doc = new Document
- for (property <- indexedProperties) {
+ for (property <- type2IndexedProperties(resourceType)) {
logger.debug("indexing "+property+" with values
"+(resource/property).length)
for (propertyValue <- resource/property) {
logger.debug("indexing "+property+"
with value "+(propertyValue*))
@@ -172,11 +182,14 @@ class GraphIndexer(definitions: TripleCo
val term = new Term(URI_FIELD_NAME,
uriRef.getUnicodeString)
writer.deleteDocuments(term)
//the reindexing might be caused by the removal of a
type statement
- val types = for (tn <- resource/RDF.`type`) yield tn! ;
- if (types.exists(t => indexedTypes.contains(t))) {
- val doc = resourceToDocument(uriRef)
- doc.add(new Field(URI_FIELD_NAME,
uriRef.getUnicodeString, Field.Store.YES, Field.Index.NOT_ANALYZED))
- writer.addDocument(doc)
+ val types = for (tn <- resource/RDF.`type`) yield
(tn!).asInstanceOf[UriRef] ;
+ types.find(t => type2IndexedProperties.contains(t))
match {
+ case Some(t) => {
+ val doc = resourceToDocument(uriRef, t)
+ doc.add(new Field(URI_FIELD_NAME,
uriRef.getUnicodeString, Field.Store.YES, Field.Index.NOT_ANALYZED))
+ writer.addDocument(doc)
+ }
+ case None => ;
}
}
def indexAnonymousResource(resource: Resource) {
@@ -195,8 +208,8 @@ class GraphIndexer(definitions: TripleCo
processDefinitions()
val basePreamble = new Preamble(baseGraph)
import basePreamble._
- val instances = (for (indexedType <- indexedTypes) yield
(indexedType)/-RDF.`type`).flatten
- logger.debug("instances "+instances.length)
+ val instances = (for ((indexedType,_) <-
type2IndexedProperties) yield (indexedType)/-RDF.`type`).flatten
+ //logger.debug("instances "+instances.length)
val writer = new IndexWriter(index, analyzer, true,
IndexWriter.MaxFieldLength.UNLIMITED);
for (instance <- instances) indexResource(instance!, writer)
writer.close