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/01/20 00:20:17 UTC

svn commit: r1061059 - in /incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris: ./ src/ src/main/ src/main/resources/ src/main/resources/OSGI-INF/ src/main/scala/ src/main/scala/org/ src/main/scala/org/apache/ src/main/scala/org/ap...

Author: reto
Date: Wed Jan 19 23:20:17 2011
New Revision: 1061059

URL: http://svn.apache.org/viewvc?rev=1061059&view=rev
Log:
CLEREZZA-388: indexing service for content garph

Added:
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/pom.xml
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/serviceComponents.xml
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/
    incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/IndexService.scala

Added: incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/pom.xml?rev=1061059&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/pom.xml (added)
+++ incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/pom.xml Wed Jan 19 23:20:17 2011
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>org.apache.clerezza.parent</artifactId>
+		<version>0.2-incubating-SNAPSHOT</version>
+	</parent>
+	<groupId>org.apache.clerezza</groupId>
+	<artifactId>org.apache.clerezza.platform.cris</artifactId>
+	<packaging>bundle</packaging>
+	<version>0.1-incubating-SNAPSHOT</version>
+	<name>Clerezza - Platform CRIS service for the content graph</name>
+	<description>
+		A composite resource index service for resources described in the content graph
+	</description>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.cris.ontologies</artifactId>
+			<version>0.1-incubating-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.cris.core</artifactId>
+			<version>0.1-incubating-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.utils</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.rdf.scala.utils</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.scala-lang</groupId>
+			<artifactId>scala-library</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.platform.graphprovider.content</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-memory</artifactId>
+			<version>3.0.3</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<sourceDirectory>src/main/scala</sourceDirectory>
+		<testSourceDirectory>src/test/scala</testSourceDirectory>
+		<plugins>
+			<plugin>
+				<groupId>org.scala-tools</groupId>
+				<artifactId>maven-scala-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>compile</goal>
+							<goal>testCompile</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<configuration>
+					<instructions>
+						<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
+						<!-- <Export-Package>org.apache.clerezza.platform.cris.*</Export-Package> -->
+						<Private-Package>org.apache.clerezza.platform.cris.*</Private-Package>
+						<Bundle-SymbolicName>org.apache.clerezza.platform.cris</Bundle-SymbolicName>
+					</instructions>
+				</configuration>
+			</plugin>
+
+		</plugins>
+	</build>
+</project>

Added: incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/serviceComponents.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1061059&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/serviceComponents.xml (added)
+++ incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/resources/OSGI-INF/serviceComponents.xml Wed Jan 19 23:20:17 2011
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+	<scr:component enabled="true" immediate="true" name="org.apache.clerezza.platform.cris.IndexService">
+		<implementation class="org.apache.clerezza.platform.cris.IndexService"/>
+		<service servicefactory="false">
+			<provide interface="org.apache.clerezza.rdf.cris.ResourceFinder"/>
+			<provide interface="org.apache.clerezza.rdf.cris.IndexDefinitionManager"/>
+		</service>
+		<reference name="cgProvider" interface="org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider"
+		cardinality="1..1" policy="static" bind="bindCgProvider" unbind="unbindCgProvider"/>
+		<reference name="tcManager" interface="org.apache.clerezza.rdf.core.access.TcManager"
+		cardinality="1..1" policy="static" bind="bindTcManager" unbind="unbindTcManager"/>
+	</scr:component>
+</components>

Added: incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/IndexService.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/IndexService.scala?rev=1061059&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/IndexService.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-388/org.apache.clerezza.platform.cris/src/main/scala/org/apache/clerezza/platform/cris/IndexService.scala Wed Jan 19 23:20:17 2011
@@ -0,0 +1,104 @@
+/*
+ * 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.platform.cris;
+
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider
+import org.apache.clerezza.rdf.cris.GraphIndexer
+import org.apache.clerezza.rdf.cris.Condition
+import org.apache.clerezza.rdf.cris.IndexDefinitionManager
+import org.apache.clerezza.rdf.cris.ResourceFinder
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException
+import org.apache.clerezza.rdf.core.access.TcManager
+import org.apache.clerezza.rdf.core.MGraph
+import org.apache.clerezza.rdf.core.Resource
+import org.apache.clerezza.rdf.core.UriRef
+import org.apache.clerezza.rdf.utils._
+import org.apache.clerezza.rdf.scala.utils._
+import org.apache.clerezza.rdf.ontologies._
+import org.apache.lucene.document._
+import org.apache.lucene.store._
+import org.apache.lucene.index._
+import org.apache.lucene.search._
+import org.osgi.service.component.ComponentContext
+import org.slf4j._
+import java.io.File
+import java.util.List
+
+/**
+ * Provides access to indexed resources in the content graph. The definitions
+ * are taken from a graph with Uri <http://zz.localhost/cris.definitions.graph>.
+ * For convenience the definitions can be changed using the methods inherited
+ * from IndexDefinitionManager, after adding new Definitions reCreateIndex
+ * should be invoked.
+ *
+ * @author reto
+ */
+class IndexService() extends ResourceFinder with IndexDefinitionManager {
+
+	var graphIndexer: GraphIndexer = null
+	var cgProvider: ContentGraphProvider = null
+	var tcManager: TcManager = null
+
+	val definitionGraphUri = new UriRef("http://zz.localhost/cris.definitions.graph")
+
+	var definitionGraph: MGraph = null
+
+	protected def activate(context: ComponentContext) {
+		definitionGraph = try {
+			tcManager.getMGraph(definitionGraphUri)
+		} catch {
+			case e: NoSuchEntityException => tcManager.createMGraph(definitionGraphUri)
+		}
+		val luceneIndexDir: File = context.getBundleContext().
+					getDataFile("lucene-index")
+		val createNewIndex = luceneIndexDir.exists
+		println("!!!!! "+createNewIndex)
+		graphIndexer = new GraphIndexer(definitionGraph,
+										cgProvider.getContentGraph,
+										FSDirectory.open(luceneIndexDir),
+										createNewIndex
+		)
+	}
+	
+	def bindCgProvider(p: ContentGraphProvider) {
+		cgProvider = p
+	}
+
+	def unbindCgProvider(p: ContentGraphProvider) {
+		cgProvider = null
+	}
+
+	def bindTcManager(m: TcManager) {
+		tcManager = m
+	}
+
+	def unbindTcManager(m: TcManager) {
+		tcManager = null
+	}
+
+	def findResources(conditions: Condition*): List[Resource] = {
+		graphIndexer.findResources(conditions: _*)
+	}
+
+	def reCreateIndex() {
+		graphIndexer.reCreateIndex()
+	}
+
+}