You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by ha...@apache.org on 2010/01/05 19:21:00 UTC
svn commit: r896160 [1/2] - in /incubator/clerezza: issues/CLEREZZA-60/
issues/CLEREZZA-60/org.apache.clerezza.platform.concept/
issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/
issues/CLEREZZA-60/org.a...
Author: hasan
Date: Tue Jan 5 18:20:58 2010
New Revision: 896160
URL: http://svn.apache.org/viewvc?rev=896160&view=rev
Log:
CLEREZZA-60: initial version of clerezza.platform.concept
Added:
incubator/clerezza/issues/CLEREZZA-60/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/ (with props)
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/pom.xml
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptCache.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProvider.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProviderManager.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptsFinder.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/LocalConceptProvider.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/RemoteConceptProvider.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/manage-concept-providers-page.ssp
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/concept-provider-manipulation.js
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/form.css
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptProviderManagerTest.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptsFinderTest.java
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/ (with props)
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/pom.xml
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/clerezza/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/clerezza/platform/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/clerezza/platform/concept/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/clerezza/platform/concept/ontologies/
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/src/main/resources/org/apache/clerezza/platform/concept/ontologies/concept.rdf
incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/pom.xml
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/pom.xml
Propchange: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 5 18:20:58 2010
@@ -0,0 +1 @@
+target
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/pom.xml?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/pom.xml (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/pom.xml Tue Jan 5 18:20:58 2010
@@ -0,0 +1,67 @@
+<?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.platform.concept</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.platform.concept.core</artifactId>
+ <packaging>bundle</packaging>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <name>Clerezza - Platform Concept Core</name>
+ <description>The core part of Platform Concept</description>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ </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.ontologies</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.platform.concept.ontologies</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.web.fileserver</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.platform.graphprovider.content</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.platform.typerendering.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.platform.typerendering.scalaserverpages</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.jaxrs.utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.triaxrs</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptCache.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptCache.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptCache.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptCache.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,285 @@
+/*
+ * 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.concept.core;
+
+import java.util.Date;
+import java.util.Iterator;
+import org.apache.clerezza.platform.concept.ontologies.CONCEPT;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.DC;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.apache.clerezza.rdf.ontologies.SKOS;
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+/**
+ * This class manages caches of SPARQL query results against a specific EndPoint
+ * and Graph.
+ *
+ * @author hasan
+ */
+class ConceptCache {
+ private UriRef sparqlEndPoint;
+ private UriRef defaultGraph;
+ private UriRef CONCEPT_CACHE_MGRAPH = new UriRef("http://tpf.localhost/concept.cache");
+
+ /**
+ * Constructs a {@link ConceptCache} for the specified SPARQL EndPoint and
+ * Graph.
+ *
+ * @param sparqlEndPoint
+ * the SPARQL EndPoint used in the query.
+ * @param defaultGraph
+ * the Graph against which the query was executed.
+ *
+ */
+ public ConceptCache(UriRef sparqlEndPoint, UriRef defaultGraph) {
+ this.sparqlEndPoint = sparqlEndPoint;
+ this.defaultGraph = defaultGraph;
+ }
+
+ /**
+ * Caches the query results available in the specified Graph under a
+ * particular search term.
+ *
+ * @param searchTerm
+ * the term used for querying concepts.
+ * @param parsedGraph
+ * the Graph which contains query results.
+ */
+ void cache(String searchTerm, Graph parsedGraph) {
+ MGraph conceptCacheMGraph = getConceptCacheMGraph();
+ NonLiteral conceptCacheNode = getConceptCacheNode(conceptCacheMGraph);
+ if (conceptCacheNode != null) {
+ removeCachedConcepts(searchTerm, conceptCacheNode, conceptCacheMGraph);
+ }
+ addCacheEntry(searchTerm, conceptCacheNode, conceptCacheMGraph,
+ parsedGraph);
+ }
+
+ private MGraph getConceptCacheMGraph() {
+ MGraph conceptCacheMGraph = null;
+ TcManager tcManager = TcManager.getInstance();
+ try {
+ conceptCacheMGraph = tcManager.getMGraph(CONCEPT_CACHE_MGRAPH);
+ } catch (NoSuchEntityException nsee) {
+ conceptCacheMGraph = tcManager.createMGraph(CONCEPT_CACHE_MGRAPH);
+ }
+ return conceptCacheMGraph;
+ }
+
+ private NonLiteral getConceptCacheNode(MGraph conceptCacheMGraph) {
+ Iterator<Triple> conceptCaches = conceptCacheMGraph.filter(
+ null, RDF.type, CONCEPT.ConceptCache);
+ while (conceptCaches.hasNext()) {
+ NonLiteral conceptCacheNode = conceptCaches.next().getSubject();
+ if (!conceptCacheMGraph.filter(conceptCacheNode,
+ CONCEPT.sparqlEndPoint, sparqlEndPoint).hasNext()) {
+ continue;
+ }
+ if (defaultGraph != null) {
+ if (!conceptCacheMGraph.filter(conceptCacheNode,
+ CONCEPT.defaultGraph, defaultGraph).hasNext()) {
+ continue;
+ }
+ }
+ return conceptCacheNode;
+ }
+ return null;
+ }
+
+ private void removeCachedConcepts(String searchTerm,
+ NonLiteral conceptCacheNode, MGraph conceptCacheMGraph) {
+ NonLiteral conceptCacheEntryNode = getConceptCacheEntryNode(
+ searchTerm, conceptCacheNode, conceptCacheMGraph);
+ if (conceptCacheEntryNode == null) {
+ return;
+ }
+ GraphNode conceptCacheEntryGraphNode = new GraphNode(
+ conceptCacheEntryNode, conceptCacheMGraph);
+ removeCachedConcepts(conceptCacheEntryGraphNode);
+ conceptCacheMGraph.remove(new TripleImpl(conceptCacheNode,
+ CONCEPT.cacheEntry, conceptCacheEntryNode));
+ }
+
+ private NonLiteral getConceptCacheEntryNode(String searchTerm,
+ NonLiteral conceptCacheNode, MGraph conceptCacheMGraph) {
+ TypedLiteral searchLiteral = LiteralFactory.getInstance()
+ .createTypedLiteral(searchTerm);
+ Iterator<Triple> cacheEntries = conceptCacheMGraph.filter(
+ conceptCacheNode, CONCEPT.cacheEntry, null);
+ while (cacheEntries.hasNext()) {
+ NonLiteral conceptCacheEntryNode = (NonLiteral) cacheEntries.next()
+ .getObject();
+ if (!conceptCacheMGraph.filter(conceptCacheEntryNode,
+ CONCEPT.searchTerm, searchLiteral).hasNext()) {
+ continue;
+ }
+ return conceptCacheEntryNode;
+ }
+ return null;
+ }
+
+ private void removeCachedConcepts(GraphNode conceptCacheEntryGraphNode) {
+ Iterator<Resource> searchResults =
+ conceptCacheEntryGraphNode.getObjects(CONCEPT.searchResult);
+ while (searchResults.hasNext()) {
+ Resource concept = searchResults.next();
+ GraphNode conceptGraphNode = new GraphNode(concept,
+ conceptCacheEntryGraphNode.getGraph());
+ conceptGraphNode.deleteProperties(OWL.sameAs);
+ conceptGraphNode.deleteProperties(RDFS.comment);
+ conceptGraphNode.deleteProperties(SKOS.prefLabel);
+ conceptGraphNode.deleteProperties(RDF.type);
+ }
+ conceptCacheEntryGraphNode.deleteProperties(CONCEPT.searchResult);
+ conceptCacheEntryGraphNode.deleteProperties(DC.date);
+ conceptCacheEntryGraphNode.deleteProperties(CONCEPT.searchTerm);
+ conceptCacheEntryGraphNode.deleteProperties(RDF.type);
+ }
+
+ private void addCacheEntry(String searchTerm, NonLiteral conceptCacheNode,
+ MGraph conceptCacheMGraph, Graph parsedGraph) {
+ GraphNode conceptCacheGraphNode = null;
+ if (conceptCacheNode == null) {
+ conceptCacheGraphNode = addConceptCacheNode(conceptCacheMGraph);
+ } else {
+ conceptCacheGraphNode = new GraphNode(conceptCacheNode,
+ conceptCacheMGraph);
+ }
+ GraphNode conceptCacheEntryGraphNode = new GraphNode(new BNode(),
+ conceptCacheMGraph);
+ conceptCacheGraphNode.addProperty(CONCEPT.cacheEntry,
+ conceptCacheEntryGraphNode.getNode());
+ conceptCacheEntryGraphNode.addProperty(RDF.type, CONCEPT.SearchTerm);
+ conceptCacheEntryGraphNode.addProperty(CONCEPT.searchTerm,
+ LiteralFactory.getInstance().createTypedLiteral(searchTerm));
+ conceptCacheEntryGraphNode.addProperty(DC.date,
+ LiteralFactory.getInstance().createTypedLiteral(new Date()));
+
+ Iterator<Triple> concepts = parsedGraph.filter(null, RDF.type, SKOS.Concept);
+ while (concepts.hasNext()) {
+ conceptCacheEntryGraphNode.addProperty(CONCEPT.searchResult,
+ concepts.next().getSubject());
+ }
+ conceptCacheMGraph.addAll(parsedGraph);
+ }
+
+ private GraphNode addConceptCacheNode(MGraph conceptCacheMGraph) {
+ GraphNode conceptCacheGraphNode = new GraphNode(new BNode(),
+ conceptCacheMGraph);
+ conceptCacheGraphNode.addProperty(RDF.type, CONCEPT.ConceptCache);
+ conceptCacheGraphNode.addProperty(CONCEPT.sparqlEndPoint,
+ sparqlEndPoint);
+ if (defaultGraph != null) {
+ conceptCacheGraphNode.addProperty(CONCEPT.defaultGraph,
+ defaultGraph);
+ }
+ return conceptCacheGraphNode;
+ }
+
+ /**
+ * Retrieves concepts from the cache stored under the specified search term.
+ * Cache entries are invalid if they are older than the specified date.
+ *
+ * @param searchTerm
+ * the search term under which the concepts are cached.
+ * @param acceptableOldestCachingDate
+ * the Date before which a cache entry is considered invalid.
+ * @return
+ * an {@link MGraph} containing the valid cached concepts.
+ */
+ MGraph retrieve(String searchTerm, Date acceptableOldestCachingDate) {
+ MGraph conceptCacheMGraph = getConceptCacheMGraph();
+
+ NonLiteral conceptCacheNode = getConceptCacheNode(conceptCacheMGraph);
+ if (conceptCacheNode == null) {
+ return null;
+ }
+ NonLiteral conceptCacheEntryNode = getConceptCacheEntryNode(searchTerm,
+ conceptCacheNode, conceptCacheMGraph);
+ if (conceptCacheEntryNode == null) {
+ return null;
+ }
+ GraphNode conceptCacheEntryGraphNode = new GraphNode(
+ conceptCacheEntryNode, conceptCacheMGraph);
+ Date cachingDate = getCachingDate(conceptCacheEntryGraphNode);
+ if (cachingDate == null || cachingDate.before(acceptableOldestCachingDate)) {
+ removeCachedConcepts(conceptCacheEntryGraphNode);
+ conceptCacheMGraph.remove(new TripleImpl(conceptCacheNode,
+ CONCEPT.cacheEntry, conceptCacheEntryNode));
+ return null;
+ }
+ return getCachedConcepts(conceptCacheEntryGraphNode);
+ }
+
+ private Date getCachingDate(GraphNode conceptCacheEntryGraphNode) {
+ Iterator<Literal> cachingDates = conceptCacheEntryGraphNode.getLiterals(
+ DC.date);
+ if (cachingDates.hasNext()) {
+ return LiteralFactory.getInstance().createObject(Date.class,
+ (TypedLiteral) cachingDates.next());
+ }
+ return null;
+ }
+
+ private MGraph getCachedConcepts(GraphNode conceptCacheEntryGraphNode) {
+ MGraph resultMGraph = new SimpleMGraph();
+ MGraph conceptCacheMGraph = (MGraph) conceptCacheEntryGraphNode.getGraph();
+ NonLiteral conceptCacheNode = (NonLiteral) conceptCacheEntryGraphNode.getNode();
+ Iterator<Triple> triples = conceptCacheMGraph.filter(
+ conceptCacheNode, CONCEPT.searchResult, null);
+ while (triples.hasNext()) {
+ UriRef concept = (UriRef) triples.next().getObject();
+ GraphNode graphNode = new GraphNode(concept, conceptCacheMGraph);
+ resultMGraph.add(new TripleImpl(concept, RDF.type, SKOS.Concept));
+
+ Iterator<Literal> prefLabelStatements = graphNode.getLiterals(SKOS.prefLabel);
+ while (prefLabelStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, SKOS.prefLabel,
+ prefLabelStatements.next()));
+ }
+ Iterator<Literal> commentStatements = graphNode.getLiterals(RDFS.comment);
+ while (commentStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, RDFS.comment,
+ commentStatements.next()));
+ }
+ Iterator<UriRef> sameAsStatements = graphNode.getUriRefObjects(OWL.sameAs);
+ while (sameAsStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, OWL.sameAs,
+ sameAsStatements.next()));
+ }
+ }
+ return resultMGraph;
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProvider.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProvider.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProvider.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProvider.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.concept.core;
+
+import org.apache.clerezza.rdf.core.Graph;
+
+/**
+ * An implementation of this interface provides a function to retrieve
+ * concepts based on a search term.
+ *
+ * @author hasan
+ */
+public interface ConceptProvider {
+ /**
+ * Returns a graph containing all concepts whose SKOS:prefLabels
+ * or SKOS:altLabels contain the search term.
+ *
+ * @param searchTerm a filter condition that specifies the term that must
+ * be contained within SKOS:prefLabels or SKOS:altLabels of a concept.
+ * @return a Graph containing all concepts that meet the filter condition.
+ *
+ */
+ public Graph retrieveConcepts(String searchTerm);
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProviderManager.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProviderManager.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProviderManager.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptProviderManager.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,309 @@
+/*
+ * 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.concept.core;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.jaxrs.utils.TrailingSlash;
+import org.apache.clerezza.platform.concept.ontologies.CONCEPT;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
+import org.apache.clerezza.platform.typerendering.RenderletManager;
+import org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.PLATFORM;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.rdf.utils.RdfList;
+import org.apache.clerezza.rdf.utils.UnionMGraph;
+import org.apache.clerezza.web.fileserver.BundlePathNode;
+import org.apache.clerezza.web.fileserver.FileServer;
+import org.apache.felix.scr.annotations.Services;
+import org.osgi.framework.Bundle;
+import org.osgi.service.component.ComponentContext;
+import org.wymiwyg.commons.util.dirbrowser.PathNode;
+
+/**
+ * This service manages concept providers. Concept providers are prioritized.
+ *
+ * The URI path of this service is /concepts/provider-manager.
+ *
+ * @author hasan, tio
+ */
+@Component
+@Services({
+ @Service(Object.class),
+ @Service(ConceptProviderManager.class)
+})
+@Property(name = "javax.ws.rs", boolValue = true)
+@Path("/concepts/provider-manager")
+public class ConceptProviderManager {
+
+ private FileServer fileServer;
+
+ @Reference
+ protected ContentGraphProvider cgProvider;
+
+ @Reference
+ private RenderletManager renderletManager;
+
+ private List<ConceptProvider> conceptProviderList =
+ new ArrayList<ConceptProvider>();
+
+ /**
+ * The activate method is called when SCR activates the component
+ * configuration.
+ *
+ * @param context
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ protected void activate(ComponentContext context)
+ throws IOException,
+ URISyntaxException {
+
+ Bundle bundle = context.getBundleContext().getBundle();
+ URL resourceDir = getClass().getResource("staticweb");
+ PathNode pathNode = new BundlePathNode(bundle, resourceDir.getPath());
+
+ fileServer = new FileServer(pathNode);
+
+ URL template = getClass().getResource("manage-concept-providers-page.ssp");
+ renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
+ new UriRef(template.toURI().toString()),
+ CONCEPT.ManageConceptProvidersPage, "naked",
+ MediaType.APPLICATION_XHTML_XML_TYPE, true);
+
+ instantiateConceptProviders();
+ }
+
+ private void instantiateConceptProviders() {
+ conceptProviderList.clear();
+ MGraph contentGraph = cgProvider.getContentGraph();
+
+ NonLiteral cplNode = getConceptProviderListNode(contentGraph);
+ RdfList cpl = new RdfList(cplNode, contentGraph);
+ for (int i = 0; i < cpl.size(); i++) {
+ NonLiteral conceptProvider = (NonLiteral) cpl.get(i);
+ Iterator<Triple> conceptProviderTypes = contentGraph.filter(
+ conceptProvider, RDF.type, null);
+ if (conceptProviderTypes.hasNext()) {
+ UriRef conceptProviderType = (UriRef) conceptProviderTypes.next().getObject();
+ if (conceptProviderType.equals(CONCEPT.LocalConceptProvider)) {
+ instantiateLocalConceptProvider(contentGraph, conceptProvider);
+ } else {
+ instantiateRemoteConceptProvider(contentGraph, conceptProvider);
+ }
+ }
+ }
+ }
+
+ private NonLiteral getConceptProviderListNode(MGraph contentGraph) {
+ Iterator<Triple> triples = contentGraph.filter(null, RDF.type,
+ CONCEPT.ConceptProviderList);
+ if (triples.hasNext()) {
+ return triples.next().getSubject();
+ }
+ NonLiteral cplNode = new BNode();
+ new RdfList(cplNode, contentGraph);
+ contentGraph.add(new TripleImpl(cplNode, RDF.type,
+ CONCEPT.ConceptProviderList));
+ return cplNode;
+ }
+
+ private void instantiateLocalConceptProvider(MGraph contentGraph,
+ NonLiteral conceptProvider) {
+ Iterator<Triple> selectedSchemes = contentGraph.filter(
+ conceptProvider, CONCEPT.selectedScheme, null);
+ if (selectedSchemes.hasNext()) {
+ UriRef selectedScheme = (UriRef) selectedSchemes.next().getObject();
+ conceptProviderList.add(new LocalConceptProvider(this,
+ selectedScheme));
+ }
+ }
+
+ private void instantiateRemoteConceptProvider(MGraph contentGraph,
+ NonLiteral conceptProvider) {
+ Iterator<Triple> endPoints = contentGraph.filter(
+ conceptProvider, CONCEPT.sparqlEndPoint, null);
+ if (endPoints.hasNext()) {
+ UriRef sparqlEndPoint = (UriRef) endPoints.next().getObject();
+ Iterator<Triple> defaultGraphs = contentGraph.filter(
+ conceptProvider, CONCEPT.defaultGraph, null);
+ UriRef defaultGraph = null;
+ if (defaultGraphs.hasNext()) {
+ defaultGraph = (UriRef) defaultGraphs.next().getObject();
+ }
+ Iterator<Triple> queryTemplates = contentGraph.filter(
+ conceptProvider, CONCEPT.queryTemplate, null);
+ if (queryTemplates.hasNext()) {
+ TypedLiteral queryTemplate =
+ (TypedLiteral) queryTemplates.next().getObject();
+ conceptProviderList.add(
+ new RemoteConceptProvider(sparqlEndPoint,
+ defaultGraph, queryTemplate.getLexicalForm()));
+ }
+ }
+ }
+
+ /**
+ * Returns a GraphNode containing a list of {@link ConceptProvider}s stored
+ * in the content graph to be managed. The order in the list represents
+ * the priority of the providers.
+ * This resource is accessible through a GET request on the URI sub-path
+ * "edit-concept-provider-list".
+ *
+ */
+ @GET
+ @Path("edit-concept-provider-list")
+ public GraphNode getProviderList(@Context UriInfo uriInfo) {
+ TrailingSlash.enforceNotPresent(uriInfo);
+ MGraph contentGraph = cgProvider.getContentGraph();
+ MGraph resultGraph = new SimpleMGraph();
+
+ NonLiteral cplNode = getConceptProviderListNode(contentGraph);
+ GraphNode resultNode = new GraphNode(cplNode, resultGraph);
+
+ resultNode.addProperty(RDF.type, CONCEPT.ManageConceptProvidersPage);
+ resultNode.addProperty(RDF.type, PLATFORM.HeadedPage);
+ return new GraphNode(resultNode.getNode(),
+ new UnionMGraph(resultGraph, contentGraph));
+ }
+
+ /**
+ * Allows the list of {@link ConceptProvider}s stored in the content graph
+ * to be updated with the list POSTed via the URI sub-path
+ * "update-concept-provider-list".
+ * The order in the list represents the priority of the providers.
+ *
+ * @param types
+ * specify the type of each ConceptProvider: either a
+ * LocalConceptProvider or a RemoteConceptProvider.
+ * @param sparqlEndPoints
+ * the SPARQL EndPoint to connect to in case of a RemoteConceptProvider.
+ * @param defaultGraphs
+ * the Graph to be queried in case of a RemoteConceptProvider.
+ * @param queryTemplates
+ * the template for the query to be used in case of a RemoteConceptProvider.
+ * @param conceptSchemes
+ * the concept scheme within which concepts are to be searched,
+ * in case of a LocalConceptProvider.
+ * @return
+ * - a 200 (OK) response if everything is fine.
+ * - a 400 (BAD REQUEST) response if types parameter is undefined.
+ */
+ @POST
+ @Path("update-concept-provider-list")
+ public Response updateConceptProviders(
+ @FormParam("types") List<String> types,
+ @FormParam("sparqlEndPoints") List<String> sparqlEndPoints,
+ @FormParam("defaultGraphs") List<String> defaultGraphs,
+ @FormParam("queryTemplates") List<String> queryTemplates,
+ @FormParam("conceptSchemes") List<String> conceptSchemes) {
+
+ if (types == null) {
+ return Response.status(Status.BAD_REQUEST)
+ .entity("Form parameter \"types\" should be defined").build();
+ }
+ MGraph contentGraph = cgProvider.getContentGraph();
+ NonLiteral cplNode = getConceptProviderListNode(contentGraph);
+ GraphNode cplGraphNode = new GraphNode(cplNode, contentGraph);
+ cplGraphNode.deleteNodeContext();
+
+ cplNode = getConceptProviderListNode(contentGraph);
+ RdfList cpl = new RdfList(cplNode, contentGraph);
+
+ int length = types.size();
+ for (int i=0; i<length; i++) {
+ UriRef conceptProviderType = new UriRef(types.get(i));
+ BNode conceptProvider = new BNode();
+ contentGraph.add(new TripleImpl(conceptProvider, RDF.type,
+ conceptProviderType));
+ if (conceptProviderType.equals(CONCEPT.LocalConceptProvider)) {
+ contentGraph.add(new TripleImpl(conceptProvider,
+ CONCEPT.selectedScheme,
+ new UriRef(conceptSchemes.get(i))));
+ } else {
+ contentGraph.add(new TripleImpl(conceptProvider,
+ CONCEPT.sparqlEndPoint,
+ new UriRef(sparqlEndPoints.get(i))));
+ String defaultGraph = defaultGraphs.get(i);
+ if (!defaultGraph.trim().isEmpty()) {
+ contentGraph.add(new TripleImpl(conceptProvider,
+ CONCEPT.defaultGraph,
+ new UriRef(defaultGraph)));
+ }
+ contentGraph.add(new TripleImpl(conceptProvider,
+ CONCEPT.queryTemplate,
+ LiteralFactory.getInstance().createTypedLiteral(
+ queryTemplates.get(i))));
+ }
+ cpl.add(i, conceptProvider);
+ }
+ instantiateConceptProviders();
+ return Response.status(Status.OK).build();
+ }
+
+ /**
+ * Returns a PathNode of a static file from the staticweb folder.
+ *
+ * @param path specifies the path param of a URI
+ *
+ * @return {@link PathNode}
+ */
+ @GET
+ @Path("{path:.+}")
+ public PathNode getStaticFile(@PathParam("path") String path) {
+ final PathNode node = fileServer.getNode(path);
+ return node;
+ }
+
+ List<ConceptProvider> getConceptProviders() {
+ return conceptProviderList;
+ }
+
+ MGraph getContentGraph() {
+ return cgProvider.getContentGraph();
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptsFinder.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptsFinder.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptsFinder.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/ConceptsFinder.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,159 @@
+/*
+ * 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.concept.core;
+
+import java.util.Iterator;
+import java.util.List;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.RDFS;
+import org.apache.clerezza.rdf.ontologies.SKOS;
+import org.apache.clerezza.rdf.utils.GraphNode;
+
+/**
+ * This JAX-RS resource can be used to search concepts accessible through
+ * registered {@link ConceptProvider}s. Concept providers are prioritized.
+ * The URI, SKOS:prefLabel and RDFS:comment of a concept from a provider of a
+ * higher priority will be used instead of those concepts having an OWL:sameAs
+ * relation with this concept, but from a provider of lower priority.
+ *
+ * The URI path of this service is /concepts/find.
+ *
+ * @author hasan
+ */
+@Component
+@Service(Object.class)
+@Property(name = "javax.ws.rs", boolValue = true)
+@Path("/concepts/find")
+public class ConceptsFinder {
+
+ @Reference
+ protected ConceptProviderManager conceptProviderManager;
+
+ /**
+ * Searches concepts for a specified search term. The actual search task
+ * is delegated to each {@link ConceptProvider} instance. The results from
+ * each {@link ConceptProvider} are merged into a single result graph.
+ * However, concepts from providers of lower priority are only considered if
+ * they are not staying in an OWL:sameAs relation with concepts from
+ * providers of higher priority.
+ *
+ * @param searchTerm
+ * The search term in form of a String.
+ * @return
+ * A GraphNode containing the search results.
+ */
+ @GET
+ public GraphNode findConcepts(@QueryParam(value="searchTerm")
+ String searchTerm) {
+
+ List<ConceptProvider> conceptProviderList = conceptProviderManager
+ .getConceptProviders();
+
+ MGraph resultMGraph = new SimpleMGraph();
+ GraphNode resultNode = new GraphNode(new BNode(), resultMGraph);
+ boolean first = true;
+ for (ConceptProvider cp : conceptProviderList) {
+ Graph graph = cp.retrieveConcepts(searchTerm);
+ Iterator<Triple> concepts = graph.filter(null, RDF.type, SKOS.Concept);
+ if (first) {
+ while (concepts.hasNext()) {
+ resultNode.addProperty(SKOS.member, concepts.next().getSubject());
+ }
+ resultMGraph.addAll(graph);
+ first = false;
+ } else {
+ while (concepts.hasNext()) {
+ NonLiteral concept = concepts.next().getSubject();
+ GraphNode conceptGraphNode = new GraphNode(concept, graph);
+ Iterator<Resource> sameAsConcepts =
+ conceptGraphNode.getObjects(OWL.sameAs);
+ if (!(hasSameAs(resultMGraph, concept)
+ || hasAnyConcept(resultMGraph, sameAsConcepts))) {
+ resultNode.addProperty(SKOS.member, concept);
+ addConceptToResultMGraph(resultMGraph, conceptGraphNode);
+ }
+
+ }
+ }
+ }
+ resultNode.addProperty(RDF.type, SKOS.Collection);
+ return resultNode;
+ }
+
+ private boolean hasSameAs(MGraph graph, NonLiteral sameAsConcept) {
+ Iterator<Triple> concepts = graph.filter(null, RDF.type, SKOS.Concept);
+ while (concepts.hasNext()) {
+ NonLiteral concept = concepts.next().getSubject();
+ if (graph.filter(concept, OWL.sameAs, sameAsConcept).hasNext()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean hasAnyConcept(MGraph graph, Iterator<Resource> concepts) {
+ while (concepts.hasNext()) {
+ NonLiteral concept = (NonLiteral) concepts.next();
+ if (graph.filter(concept, RDF.type, SKOS.Concept).hasNext()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void addConceptToResultMGraph(MGraph resultMGraph,
+ GraphNode graphNode) {
+ NonLiteral concept = (NonLiteral) graphNode.getNode();
+ resultMGraph.add(new TripleImpl(concept, RDF.type, SKOS.Concept));
+
+ Iterator<Literal> prefLabelStatements = graphNode.getLiterals(SKOS.prefLabel);
+ while (prefLabelStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, SKOS.prefLabel,
+ prefLabelStatements.next()));
+ }
+ Iterator<Literal> commentStatements = graphNode.getLiterals(RDFS.comment);
+ while (commentStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, RDFS.comment,
+ commentStatements.next()));
+ }
+ Iterator<UriRef> sameAsStatements = graphNode.getUriRefObjects(OWL.sameAs);
+ while (sameAsStatements.hasNext()) {
+ resultMGraph.add(new TripleImpl(concept, OWL.sameAs,
+ sameAsStatements.next()));
+ }
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/LocalConceptProvider.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/LocalConceptProvider.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/LocalConceptProvider.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/LocalConceptProvider.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.concept.core;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.sparql.ParseException;
+import org.apache.clerezza.rdf.core.sparql.QueryParser;
+import org.apache.clerezza.rdf.core.sparql.query.ConstructQuery;
+
+/**
+ * This {@link ConceptProvider} operates on concepts available in the localhost.
+ *
+ * @author tio, hasan
+ */
+public class LocalConceptProvider implements ConceptProvider {
+
+ private ConceptProviderManager conceptProviderManager = null;
+ private UriRef selectedScheme = null;
+
+ /**
+ * Constructs a {@link LocalConceptProvider} with the specified parameters.
+ *
+ * @param conceptProviderManager
+ * A reference to the manager of this provider.
+ * @param selectedScheme
+ * The scheme in which concepts are to be searched.
+ */
+ public LocalConceptProvider(ConceptProviderManager conceptProviderManager,
+ UriRef selectedScheme) {
+ this.conceptProviderManager = conceptProviderManager;
+ this.selectedScheme = selectedScheme;
+ }
+
+ @Override
+ public Graph retrieveConcepts(String searchTerm) {
+ QueryParser queryParser = QueryParser.getInstance();
+
+ String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
+ "PREFIX skos: <http://www.w3.org/2008/05/skos#> " +
+ "CONSTRUCT {?concept a skos:Concept; skos:prefLabel ?prefLabel; " +
+ "rdfs:comment ?comment; owl:sameAs ?sameConcept .} " +
+ "WHERE {?concept skos:inScheme " + selectedScheme.toString() +
+ "; skos:prefLabel ?prefLabel . " +
+ "OPTIONAL { ?concept skos:altLabel ?altLabel .} " +
+ "OPTIONAL { ?concept rdfs:comment ?comment .} " +
+ "OPTIONAL { ?concept owl:sameAs ?sameConcept .} " +
+ "FILTER (REGEX(STR(?prefLabel), '" +
+ searchTerm + "', 'i') || REGEX(STR(?altLabel), '" +
+ searchTerm + "', 'i'))}";
+
+ ConstructQuery constructQuery;
+ try {
+ constructQuery = (ConstructQuery) queryParser.parse(query);
+ } catch (ParseException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ MGraph defaultGraph = conceptProviderManager.getContentGraph();
+ TcManager tcManager = TcManager.getInstance();
+ return tcManager.executeSparqlQuery(constructQuery, defaultGraph);
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/RemoteConceptProvider.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/RemoteConceptProvider.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/RemoteConceptProvider.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/java/org/apache/clerezza/platform/concept/core/RemoteConceptProvider.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,124 @@
+/*
+ * 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.concept.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Calendar;
+import java.util.Date;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This implementation of {@link ConceptProvider} provides a functionality
+ * to query a SPARQL End Point for a given search term. The query is to be
+ * generated from a template by replacing the place holder for the search term
+ * with the specified search term.
+ *
+ * @author tio, hasan
+ */
+public class RemoteConceptProvider implements ConceptProvider {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private UriRef sparqlEndPoint = null;
+ private UriRef defaultGraph = null;
+ private String queryTemplate = null;
+ private ConceptCache conceptCache = null;
+
+ /**
+ * Constructs a {@link RemoteConceptProvider} with the specified parameters.
+ *
+ * @param sparqlEndPoint
+ * the SPARQL End Point to connect to
+ * @param defaultGraph
+ * the Graph to query for concepts
+ * @param queryTemplate
+ * the template for query containing place holders for the search term.
+ */
+ public RemoteConceptProvider(
+ UriRef sparqlEndPoint, UriRef defaultGraph, String queryTemplate) {
+ this.sparqlEndPoint = sparqlEndPoint;
+ this.defaultGraph = defaultGraph;
+ this.queryTemplate = queryTemplate;
+ this.conceptCache = new ConceptCache(sparqlEndPoint, defaultGraph);
+ }
+
+ @Override
+ public Graph retrieveConcepts(String searchTerm) {
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_MONTH, -30);
+ Date acceptableOldestCachingDate = calendar.getTime();
+ MGraph cachedConcepts = conceptCache.retrieve(searchTerm.toLowerCase(),
+ acceptableOldestCachingDate);
+ if (cachedConcepts != null) {
+ return cachedConcepts.getGraph();
+ } else {
+ final int connectionTimeout = 4000;
+ String query = queryTemplate.replace("${searchTerm}", searchTerm);
+ try {
+ String param = "query=" + URLEncoder.encode(query, "UTF-8");
+ if (defaultGraph != null) {
+ param += "&default-graph-uri=" + defaultGraph.getUnicodeString();
+ }
+ final URL url = new URL(sparqlEndPoint.getUnicodeString());
+ final HttpURLConnection con =
+ (HttpURLConnection) url.openConnection();
+ con.setRequestProperty("Accept", "application/rdf+xml");
+ con.setRequestMethod("POST");
+ con.setDoOutput(true);
+ con.setDoInput(true);
+ con.setUseCaches(false);
+ con.setConnectTimeout(connectionTimeout);
+
+ final OutputStream os = con.getOutputStream();
+ os.write(param.getBytes());
+ os.close();
+
+ final InputStream is = con.getInputStream();
+ Graph parsedGraph = Parser.getInstance().parse(is,
+ SupportedFormat.RDF_XML);
+ is.close();
+ conceptCache.cache(searchTerm.toLowerCase(), parsedGraph);
+ return parsedGraph;
+ } catch (ProtocolException ex) {
+ throw new RuntimeException(ex);
+ } catch (MalformedURLException ex) {
+ throw new RuntimeException(ex);
+ } catch (UnsupportedEncodingException ex) {
+ throw new RuntimeException(ex);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/manage-concept-providers-page.ssp
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/manage-concept-providers-page.ssp?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/manage-concept-providers-page.ssp (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/manage-concept-providers-page.ssp Tue Jan 5 18:20:58 2010
@@ -0,0 +1,104 @@
+def skos(s: Any) = new UriRef("http://www.w3.org/2008/05/skos#"+s)
+def cm(s: Any) = new UriRef("http://clerezza.org/2009/04/conceptmanager#"+s)
+def lingvoj(s: Any) = new UriRef("http://www.lingvoj.org/ontology#"+s)
+def rdfs(s: Any) = new UriRef("http://www.w3.org/2000/01/rdf-schema#"+s)
+def rdf(s: Any) = new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#"+s)
+
+def createProvider(rdfType: String, selectedScheme: String, sparqlEndPoint: String, defaultGraph: String, query: String) =
+ <tr>
+ <td>
+ <input type="checkbox" value={rdfType}/>
+ </td>
+ <td>
+ <div>Provider:
+ </div>
+ {createSelection(!selectedScheme.equals(""))}
+ <br/>
+ <div>Concept Scheme:</div>
+ <input type="text" value={selectedScheme} name="conceptSchemes"/>
+ <div>SPARQL Endpoint:</div>
+ <input type="text" value={sparqlEndPoint} name="sparqlEndPoints"/>
+ <div>Default Graph:</div>
+ <input type="text" value={defaultGraph} name="defaultGraphs"/>
+ <div>Query Template:</div>
+ <textarea rows="8" name="queryTemplates">{query}</textarea>
+ <br/>
+ <br/>
+ </td>
+ </tr>
+
+
+def createSelection(isLocal: Boolean) = <select name="types">
+ {if(isLocal) {
+ <option value={cm("LocalConceptProvider").getUnicodeString()} selected="selected">LocalConceptProvider</option>
+ <option value={cm("RemoteConceptProvider").getUnicodeString()} >RemoteConceptProvider</option>
+ } else {
+ <option value={cm("LocalConceptProvider").getUnicodeString()}>LocalConceptProvider</option>
+ <option value={cm("RemoteConceptProvider").getUnicodeString()} selected="selected">RemoteConceptProvider</option>
+ }}
+ </select>
+
+resultDocModifier.addStyleSheet("style/form.css");
+resultDocModifier.addScriptReference("/jquery/jquery.tooltip.pack.js");
+resultDocModifier.addScriptReference("/jquery/jquery.ajaxQueue.js");
+resultDocModifier.addScriptReference("/jquery/jquery.autocomplete.min.js");
+resultDocModifier.addScriptReference("/admin/concept-manager/scripts/ajax-options.js");
+resultDocModifier.addScriptReference("scripts/concept-provider-manipulation.js");
+resultDocModifier.setTitle("Resource Tagging");
+resultDocModifier.addNodes2Elem("tx-module", <h1>Resource Tagging</h1>);
+
+resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li class="tx-active"><a href="">Concept Providers Manager</a></li>);
+
+resultDocModifier.addNodes2Elem("tx-contextual-buttons-ol", <li><a id="deleteButton" class="tx-button tx-button-remove" href="#">Remove</a></li>);
+resultDocModifier.addNodes2Elem("tx-contextual-buttons-ol", <li><a id="addButton" class="tx-button tx-button-create" href="#">Save</a></li>);
+
+<div id="tx-content">
+ <div class="tx-tree">
+ <form action="" id="providers" method="post">
+ <fieldset>
+ <table>
+ <thead>
+ <tr>
+ <th><a href="#"></a></th>
+ <th style="width: 95%"><a href="#"></a>Concept Providers</th>
+ </tr>
+ </thead>
+ <tbody>
+ { for (provider <- (res!!)) yield {
+ if((provider/rdf("type")*).indexOf("LocalConceptProvider") != -1) {
+ createProvider((provider/rdf("type")*), provider/cm("selectedScheme")*, "", "", "")
+ } else {
+ createProvider((provider/rdf("type")*), "", provider/cm("sparqlEndPoint")*, provider/cm("defaultGraph")*, provider/cm("queryTemplate")*)
+ }
+ }
+ }
+ <tr id="last">
+ <td></td>
+ <td>
+ <div>Add Concept Provider:</div>
+ <select id="type">
+ <option value={cm("LocalConceptProvider").getUnicodeString()}>LocalConceptProvider</option>
+ <option value={cm("RemoteConceptProvider").getUnicodeString()}>RemoteConceptProvider</option>
+ </select>
+ <div>Concept Scheme:</div>
+ <input type="text" name="conceptScheme" id="conceptScheme"/>
+ <div>SPARQL Endpoint</div>
+ <input type="text" name="sparqlEndPoint" id="sparqlEndPoint" />
+ <div>Default Graph:</div>
+ <input type="text" name="defaultGraph" id="defaultGraph"/>
+ <div>Query Template:</div>
+ <textarea rows="8" id="query"/>
+ <br/>
+ <br/>
+ <div>
+ <a href="#" class="tx-icon tx-icon-ok" id="addProvider">Add</a>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </fieldset>
+ </form>
+ </div>
+
+</div>
\ No newline at end of file
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/concept-provider-manipulation.js
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/concept-provider-manipulation.js?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/concept-provider-manipulation.js (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/scripts/concept-provider-manipulation.js Tue Jan 5 18:20:58 2010
@@ -0,0 +1,214 @@
+/*
+ * 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.
+ */
+function ConceptProviderGui(){};
+
+ConceptProviderGui.isModified = false;
+
+ConceptProviderGui.query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" +
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
+ "PREFIX skos08: <http://www.w3.org/2008/05/skos#> \n" +
+ "PREFIX skos04: <http://www.w3.org/2004/02/skos/core#> \n" +
+ "CONSTRUCT { ?concept a skos08:Concept; skos08:prefLabel ?prefLabel; " +
+ "rdfs:comment ?comment; owl:sameAs ?sameConcept . } \n" +
+ "WHERE { ?concept a skos04:Concept; skos04:prefLabel ?prefLabel . \n" +
+ "OPTIONAL { ?concept skos04:altLabel ?altLabel . } \n" +
+ "OPTIONAL { ?concept rdfs:comment ?comment . } \n" +
+ "OPTIONAL { ?concept owl:sameAs ?sameConcept . } \n" +
+ "FILTER (REGEX(STR(?prefLabel), '${searchTerm}') || REGEX(STR(?altLabel), '${searchTerm}'))}";
+
+ConceptProviderGui.initButtons = function() {
+
+ ConceptProviderGui.updateButtonState();
+
+ $("#deleteButton").click(function(event) {
+ $("input:checked").each(function() {
+ $(this).parent().parent().remove();
+ });
+ $(this).addClass("tx-inactive");
+ ConceptProviderGui.isModified = true;
+ });
+
+ $("#addProvider").click(function(event) {
+ ConceptProviderGui.addProvider($("#type").val(),
+ $("#conceptScheme").val(),
+ $("#sparqlEndPoint").val(),
+ $("#defaultGraph").val(),
+ $("#query").val());
+ $("#conceptScheme").val("");
+ $("#sparqlEndPoint").val("");
+ $("#defaultGraph").val("");
+ $("#query").val("");
+ });
+
+ $("#addButton").click(function(event) {
+ if($(this).text() == "Save") {
+ var options = new AjaxOptions("update-providers", "updating providers", function(obj) {
+ });
+ $("textarea[id!=query]").each(function() {
+ $(this).removeAttr("disabled");
+ });
+ options.type = "POST";
+ options.url = "update-concept-provider-list";
+ options.data = $("#providers").serialize();
+ $.ajax(options);
+ }
+ });
+}
+
+ConceptProviderGui.addProvider = function(rdfType, conceptScheme, sparqlEndPoint, defaultGraph, query) {
+ var tr = $("<tr/>").attr("id", "");
+ var td1 = $("<td/>");
+ var div = $("<div/>").text("Provider:");
+ var td2 = $("<td/>");
+
+ var selection = $("<select/>").attr("name","types");
+
+ $("#type > option:not(:selected)").each(function() {
+ selection.append($(this).clone());
+ });
+ $("#type > option:selected").each(function() {
+ var option = $(this).clone();
+ option.attr("selected", "selected");
+ selection.append(option);
+ });
+
+ td2.append(div);
+ td2.append(selection);
+
+ var inputText = $("<input/>").attr({
+ "type":"text",
+ "name":"conceptSchemes",
+ "value": conceptScheme
+ });
+
+ div = $("<div/>").text("Concept Scheme:");
+ td2.append(div);
+ td2.append(inputText);
+
+ inputText = $("<input/>").attr({
+ "type":"text",
+ "name":"sparqlEndPoints",
+ "value": sparqlEndPoint
+ });
+
+ div = $("<div/>").text("SPARQL End Point");
+ td2.append(div);
+ td2.append(inputText);
+
+ inputText = $("<input/>").attr({
+ "type":"text",
+ "name":"defaultGraphs",
+ "value": defaultGraph
+ });
+
+ div = $("<div/>").text("Default Graph:");
+ td2.append(div);
+ td2.append(inputText)
+ var inputCheckbox = $("<input/>").attr({
+ "type":"checkbox",
+ "value": rdfType
+ });
+
+ inputCheckbox.appendTo(td1);
+
+ td1.appendTo(tr);
+
+ var textArea = $("<textarea/>").attr({
+ "rows":"8",
+ "name":"queryTemplates"
+ }).val(query);
+ div = $("<div/>").text("Query Template:");
+ td2.append(div);
+ td2.append(textArea);
+ td2.append($("<br/>"));
+ td2.append($("<br/>"));
+ td2.appendTo(tr);
+ tr.insertBefore("#last");
+ ConceptProviderGui.isModified = true;
+
+ $("select[name=types] > option:selected").each(function() {
+ ConceptProviderGui.updateDropDown($(this), "conceptSchemes");
+ });
+}
+
+ConceptProviderGui.updateDropDown = function (obj, name) {
+ if(obj.val().indexOf("Local") != -1) {
+ obj.parent().parent().find("input[name!=" + name + "]").each(function() {
+ $(this).prev().hide();
+ $(this).hide();
+ });
+ obj.parent().parent().find("input[name=" + name + "]").each(function() {
+ $(this).prev().show();
+ $(this).show();
+ });
+ obj.parent().parent().find("textarea").each(function() {
+ $(this).prev().hide();
+ $(this).hide();
+ });
+ } else {
+ obj.parent().parent().find("input[name!=" + name + "]").each(function() {
+ $(this).prev().show();
+ $(this).show();
+ });
+ obj.parent().parent().find("input[name=" + name + "]").each(function() {
+ $(this).prev().hide();
+ $(this).hide();
+ });
+ obj.parent().parent().find("textarea").each(function() {
+ $(this).prev().show();
+ $(this).show();
+ });
+ }
+}
+
+ConceptProviderGui.updateButtonState = function() {
+ var counter = $("input:checked").length;
+ if(counter == 0) {
+ $("#deleteButton").addClass("tx-inactive");
+ } else {
+ $("#deleteButton").removeClass("tx-inactive");
+ }
+}
+
+$(document).ready(function () {
+
+ $("select[name=types]").live("change", function() {
+ $("select[name=types] > option:selected").each(function(){
+ ConceptProviderGui.updateDropDown($(this), "conceptSchemes");
+ });
+ });
+ $("select[name=types] > option:selected").each(function() {
+ ConceptProviderGui.updateDropDown($(this), "conceptSchemes");
+ });
+ $("#type").live("change", function() {
+ $("#type > option:selected").each(function(){
+ ConceptProviderGui.updateDropDown($(this), "conceptScheme");
+ $("#query").val(ConceptProviderGui.query);
+ });
+ });
+ $("#type > option:selected").each(function() {
+ ConceptProviderGui.updateDropDown($(this), "conceptScheme");
+ $("#query").val(ConceptProviderGui.query);
+ });
+ $("input:checkbox").live("change",function() {
+ ConceptProviderGui.updateButtonState();
+ });
+
+ ConceptProviderGui.initButtons();
+});
\ No newline at end of file
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/form.css
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/form.css?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/form.css (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/main/resources/org/apache/clerezza/platform/concept/core/staticweb/style/form.css Tue Jan 5 18:20:58 2010
@@ -0,0 +1,3 @@
+input, select, textarea {
+ width: 32em;
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptProviderManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptProviderManagerTest.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptProviderManagerTest.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptProviderManagerTest.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,99 @@
+/*
+ * 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.concept.core;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.apache.clerezza.platform.concept.ontologies.CONCEPT;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This class tests the functionality of a ConceptProviderManager.
+ *
+ * @author hasan
+ */
+public class ConceptProviderManagerTest {
+
+ private class TestConceptProvider implements ConceptProvider {
+ @Override
+ public Graph retrieveConcepts(String searchTerm) {
+ return null;
+ }
+ }
+
+ private class TestedConceptProviderManager extends ConceptProviderManager {
+ public void fillConceptProviderList() {
+ ConceptProvider CP1 = new TestConceptProvider();
+ ConceptProvider CP2 = new TestConceptProvider();
+ getConceptProviders().add(CP1);
+ getConceptProviders().add(CP2);
+ }
+ }
+
+ private static MGraph mGraph = new SimpleMGraph();
+
+ private TestedConceptProviderManager testedConceptProviderManager;
+
+ @Before
+ public void setUp() {
+ testedConceptProviderManager = new TestedConceptProviderManager();
+ testedConceptProviderManager.cgProvider = new ContentGraphProvider() {
+
+ @Override
+ public MGraph getContentGraph() {
+ return mGraph;
+ }
+ };
+ }
+
+ @Test
+ public void testUpdateConceptProviders() {
+ testedConceptProviderManager.fillConceptProviderList();
+ List<ConceptProvider> cpl = testedConceptProviderManager
+ .getConceptProviders();
+ Assert.assertTrue(cpl.get(0) instanceof TestConceptProvider);
+ Assert.assertTrue(cpl.get(1) instanceof TestConceptProvider);
+ Assert.assertTrue(cpl.size()==2);
+ List<String> types = Arrays.asList(
+ CONCEPT.LocalConceptProvider.getUnicodeString(),
+ CONCEPT.RemoteConceptProvider.getUnicodeString());
+ List<String> sparqlEndPoint = Arrays.asList(
+ "", "http://example.org/sparql");
+ List<String> defaultGraphs = Arrays.asList(
+ "", "http://example.org/graph");
+ List<String> queryTemplates = Arrays.asList(
+ "", "CONSTRUCT {?a ?b ?c .} WHERE {?a ?b ?c .}");
+ List<String> conceptSchemes = Arrays.asList(
+ "http://localhost:8080/default", "");
+ Response response = testedConceptProviderManager.updateConceptProviders(
+ types, sparqlEndPoint, defaultGraphs, queryTemplates,
+ conceptSchemes);
+ cpl = testedConceptProviderManager.getConceptProviders();
+ Assert.assertTrue(cpl.get(0) instanceof LocalConceptProvider);
+ Assert.assertTrue(cpl.get(1) instanceof RemoteConceptProvider);
+ Assert.assertTrue(cpl.size()==2);
+ }
+}
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptsFinderTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptsFinderTest.java?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptsFinderTest.java (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.core/src/test/java/org/apache/clerezza/platform/concept/core/ConceptsFinderTest.java Tue Jan 5 18:20:58 2010
@@ -0,0 +1,127 @@
+/*
+ * 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.concept.core;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.ontologies.OWL;
+import org.apache.clerezza.rdf.ontologies.RDF;
+import org.apache.clerezza.rdf.ontologies.SKOS;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This class tests the functionality of a ConceptsFinder.
+ *
+ * @author hasan
+ */
+public class ConceptsFinderTest {
+
+ private final UriRef concept1a = new UriRef("http://example.org/concept1a");
+ private final UriRef concept1b = new UriRef("http://example.org/concept1b");
+ private final UriRef concept1c = new UriRef("http://example.org/concept1c");
+ private final UriRef concept1d = new UriRef("http://example.org/concept1d");
+
+ private final UriRef concept2a = new UriRef("http://example.org/concept2a");
+ private final UriRef concept2b = new UriRef("http://example.org/concept2b");
+ private final UriRef concept2c = new UriRef("http://example.org/concept2c");
+ private final UriRef concept2d = new UriRef("http://example.org/concept2d");
+
+ private final List<UriRef> concepts1 = Arrays.asList(
+ concept1a, concept1b, concept1c, concept1d);
+ private final List<UriRef> concepts2 = Arrays.asList(
+ concept2a, concept2b, concept2c, concept2d);
+
+ private class TestConceptProvider implements ConceptProvider {
+ MGraph conceptGraph = new SimpleMGraph();
+
+ public TestConceptProvider(List<UriRef> myConcepts,
+ List<UriRef> yourConcepts, List<Integer> sameAs) {
+ Assert.assertTrue(myConcepts.size()==4);
+ Assert.assertTrue(yourConcepts.size()==4);
+ for (UriRef concept : myConcepts) {
+ conceptGraph.add(new TripleImpl(concept, RDF.type, SKOS.Concept));
+ }
+ for (Integer index : sameAs) {
+ conceptGraph.add(new TripleImpl(myConcepts.get(index), OWL.sameAs,
+ yourConcepts.get(index)));
+ }
+ }
+
+ @Override
+ public Graph retrieveConcepts(String searchTerm) {
+ return conceptGraph.getGraph();
+ }
+ }
+
+ private class TestedConceptProviderManager extends ConceptProviderManager {
+ public void fillConceptProviderList() {
+ ConceptProvider CP1 = new TestConceptProvider(concepts1, concepts2,
+ Arrays.asList(1,3));
+ ConceptProvider CP2 = new TestConceptProvider(concepts2, concepts1,
+ Arrays.asList(2,3));
+ getConceptProviders().add(CP1);
+ getConceptProviders().add(CP2);
+ }
+ }
+
+ private class TestedConceptsFinder extends ConceptsFinder {
+ }
+
+ private static MGraph mGraph = new SimpleMGraph();
+ private TestedConceptProviderManager testedConceptProviderManager;
+ private TestedConceptsFinder testedConceptsFinder;
+
+ @Before
+ public void setUp() {
+ testedConceptProviderManager = new TestedConceptProviderManager();
+ testedConceptProviderManager.cgProvider = new ContentGraphProvider() {
+ @Override
+ public MGraph getContentGraph() {
+ return mGraph;
+ }
+ };
+ testedConceptsFinder = new TestedConceptsFinder();
+ testedConceptsFinder.conceptProviderManager =
+ testedConceptProviderManager;
+ }
+
+ @Test
+ public void testFindConcepts() {
+ testedConceptProviderManager.fillConceptProviderList();
+ GraphNode proposals = testedConceptsFinder.findConcepts("any");
+ Assert.assertTrue(proposals.countObjects(SKOS.member)==5);
+ Assert.assertTrue(proposals.hasProperty(SKOS.member, concept1a));
+ Assert.assertTrue(proposals.hasProperty(SKOS.member, concept1b));
+ Assert.assertTrue(proposals.hasProperty(SKOS.member, concept1c));
+ Assert.assertTrue(proposals.hasProperty(SKOS.member, concept1d));
+ Assert.assertTrue(proposals.hasProperty(SKOS.member, concept2a));
+ Assert.assertFalse(proposals.hasProperty(SKOS.member, concept2b));
+ Assert.assertFalse(proposals.hasProperty(SKOS.member, concept2c));
+ Assert.assertFalse(proposals.hasProperty(SKOS.member, concept2d));
+ }
+}
Propchange: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 5 18:20:58 2010
@@ -0,0 +1 @@
+target
Added: incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/pom.xml?rev=896160&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/pom.xml (added)
+++ incubator/clerezza/issues/CLEREZZA-60/org.apache.clerezza.platform.concept/org.apache.clerezza.platform.concept.ontologies/pom.xml Tue Jan 5 18:20:58 2010
@@ -0,0 +1,45 @@
+<?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.platform.concept</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.platform.concept.ontologies</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Clerezza - Platform Concept Ontologies</name>
+ <description>
+ Ontologies for Platform Concept Core
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.core</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.maven-ontologies-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <configuration>
+ <resourcePath>${basedir}/src/main/resources</resourcePath>
+ <sources>
+ <source>${basedir}/target/generated-sources/main/java</source>
+ </sources>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>