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/05 18:17:55 UTC
svn commit: r1078313 - 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: Sat Mar 5 17:17:55 2011
New Revision: 1078313
URL: http://svn.apache.org/viewvc?rev=1078313&view=rev
Log:
CLEREZZA-388: supporting joined-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/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=1078313&r1=1078312&r2=1078313&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 Sat Mar 5 17:17:55 2011
@@ -70,7 +70,7 @@ class GraphIndexer(definitionGraph: Trip
private[this] val URI_FIELD_NAME = "resource-uri"
private[this] val logger = LoggerFactory.getLogger(classOf[GraphIndexer])
- private[this] var type2IndexedProperties = Map[UriRef, Seq[VirtualProperty]]()
+ private[this] var type2IndexedProperties: Map[UriRef, Seq[VirtualProperty]] = null
private[this] var property2TypeMap = Map[VirtualProperty, mutable.Set[UriRef]]()
//private[this] var indexedProperties: Seq[UriRef] = null
@@ -193,10 +193,12 @@ class GraphIndexer(definitionGraph: Trip
def resourceToDocument(resource: UriRef, resourceType: UriRef) = {
val doc = new Document
- for (vProperty <- type2IndexedProperties(resourceType)) {
+ val indexedProperties = type2IndexedProperties(resourceType)
+ logger.info("indexing "+resource+" considering "+indexedProperties.size+" properties ("+indexedProperties+")")
+ for (vProperty <- indexedProperties) {
logger.debug("indexing "+vProperty+" with values "+(vProperty.value(resource)).length)
for (propertyValue <- vProperty.value(resource)) {
- logger.info("indexing "+vProperty+" with value "+(propertyValue))
+ logger.debug("indexing "+vProperty+"("+vProperty.stringKey+") with value "+(propertyValue))
doc.add(new Field(vProperty.stringKey,
propertyValue,
Field.Store.YES,
@@ -239,7 +241,10 @@ class GraphIndexer(definitionGraph: Trip
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)
+ for (instance <- instances) {
+ //println("indexing "+instance)
+ indexResource(instance!, writer)
+ }
writer.close
}
@@ -251,6 +256,7 @@ class GraphIndexer(definitionGraph: Trip
def findResources(conditions: Condition*) = {
val booleanQuery = new BooleanQuery()
for (c <- conditions) {
+ println("adding query "+c.query+" from "+c)
booleanQuery.add(c.query, BooleanClause.Occur.MUST)
}
val searcher = new IndexSearcher(index, true);
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=1078313&r1=1078312&r2=1078313&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 Sat Mar 5 17:17:55 2011
@@ -40,7 +40,10 @@ case class PropertyHolder(property: UriR
case class JoinVirtualProperty(properties: List[VirtualProperty]) extends VirtualProperty {
val stringKey = "J"+VirtualProperty.listDigest(properties)
- def value(node: RichGraphNode): Seq[String] = Seq("")
+ private def singleValue(node: RichGraphNode): String = (for (property <- properties) yield {
+ property.value(node).mkString(" ")
+ }).mkString(" ")
+ def value(node: RichGraphNode): Seq[String] = Seq(singleValue(node))
}
case class PathVirtualProperty(properties: List[VirtualProperty]) extends 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=1078313&r1=1078312&r2=1078313&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 Sat Mar 5 17:17:55 2011
@@ -73,6 +73,7 @@ class GraphIndexerTest {
node.addPropertyValue(FOAF.firstName, "John")
node.addPropertyValue(FOAF.firstName, "William")
node.addPropertyValue(FOAF.lastName, "Smith")
+ node.addPropertyValue(RDFS.comment, "A person with two names")
service = new GraphIndexer(definitions, dataGraph)
}
@@ -168,6 +169,39 @@ class GraphIndexerTest {
Assert.assertEquals(2, results2.length)
}
+ @Test
+ def reIndexWithoutActualChange {
+ service.reCreateIndex();
+ {
+ //the old data still available
+ val results = service.findResources(FOAF.firstName, "*Joe*")
+ Assert.assertEquals(2, results.size)
+ }
+ }
+
+ @Test
+ def reIndexTest {
+ //import VirtualProperties._
+ //val joinProperty = JoinVirtualProperty(List(FOAF.firstName, FOAF.lastName))
+ val indexDefinitionManager = new IndexDefinitionManager {
+ val definitionGraph = definitions
+ }
+ println("size before: "+definitions.size)
+ indexDefinitionManager.addDefinition(FOAF.Person, FOAF.firstName, FOAF.lastName, RDFS.comment)
+ println("size after: "+definitions.size)
+ service.reCreateIndex();
+ {
+ //the old data still available
+ val results = service.findResources(FOAF.firstName, "*Joe*")
+ Assert.assertEquals(2, results.size)
+ }
+ {
+ //the newly indexed property
+ val results = service.findResources(RDFS.comment,"*two*")
+ Assert.assertEquals(1, results.size)
+ }
+ }
+
@Test
def testJoinProperty {
import VirtualProperties._
@@ -178,7 +212,7 @@ class GraphIndexerTest {
indexDefinitionManager.addDefinition(FOAF.Person, joinProperty)
service.reCreateIndex();
{
- val results = service.findResources(joinProperty,"John")
+ val results = service.findResources(joinProperty,"*John*")
Assert.assertEquals(2, results.size)
}
{