Author: hasan
Date: Thu Jan 14 19:20:36 2010
New Revision: 899362
URL: http://svn.apache.org/viewvc?rev=899362&view=rev
Log:
CLEREZZA-59: improved free concepts usage and management, added mgraph for
storing remote concepts description
Added:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptsDescriptionManager.java
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptManipulator.java
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptsFinder.java
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/GenericResourcePage.java
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/LocalConceptProvider.java
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptProvider.java
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptManipulator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptManipulator.java?rev=899362&r1=899361&r2=899362&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptManipulator.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptManipulator.java
Thu Jan 14 19:20:36 2010
@@ -52,6 +52,8 @@
@Path("/concepts/manipulator")
public class ConceptManipulator {
+ public static String FREE_CONCEPT_SCHEME =
"concept-scheme/free-concepts";
+
@Reference
protected ContentGraphProvider cgProvider;
@@ -95,9 +97,12 @@
.build();
}
String baseUri =
platformConfig.getDefaultBaseUri().getUnicodeString();
- UriRef concept = new UriRef(baseUri +
UriRefUtil.stripNonUriRefChars(prefLabel));
+ UriRef concept = new UriRef(baseUri + "concept/" +
+ UriRefUtil.stripNonUriRefChars(prefLabel));
contentGraph.add(new TripleImpl(concept, RDF.type,
SKOS.Concept));
+ contentGraph.add(new TripleImpl(concept, SKOS.inScheme,
+ new UriRef(baseUri + FREE_CONCEPT_SCHEME)));
contentGraph.add(new TripleImpl(concept, SKOS.prefLabel,
preferredLabel));
if (!comment.isEmpty()) {
contentGraph.add(new TripleImpl(concept, RDFS.comment,
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptsFinder.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptsFinder.java?rev=899362&r1=899361&r2=899362&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptsFinder.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/ConceptsFinder.java
Thu Jan 14 19:20:36 2010
@@ -26,6 +26,8 @@
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import org.apache.clerezza.platform.config.PlatformConfig;
+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.felix.scr.annotations.Component;
@@ -40,6 +42,7 @@
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.access.TcManager;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.core.impl.TripleImpl;
import org.apache.clerezza.rdf.ontologies.OWL;
@@ -51,10 +54,15 @@
/**
* This JAX-RS resource can be used to search concepts accessible through
- * registered {...@link ConceptProvider}s. Concept providers are prioritized.
+ * registered {...@link ConceptProvider}s. If no {...@link
LocalConceptProvider} is
+ * registered for {...@link ConceptManipulator.FREE_CONCEPT_SCHEME}, then one
is
+ * created to find free concepts in the content graph.
+ * 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.
+ * Implicitly created {...@link LocalConceptProvider} for free concepts has the
+ * lowest priority.
*
* The URI path of this service is /concepts/find.
*
@@ -72,12 +80,31 @@
@Reference
protected ConceptProviderManager conceptProviderManager;
+ @Reference
+ private TcManager tcManager;
+
+ @Reference
+ protected ContentGraphProvider cgProvider;
+
+ @Reference
+ private PlatformConfig platformConfig;
+
+ private LocalConceptProvider freeConceptProvider = null;
+
+ private UriRef freeConceptScheme = null;
+
protected void activate(ComponentContext context) throws
URISyntaxException {
URL template =
getClass().getResource("skos-collection-json.ssp");
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
new UriRef(template.toURI().toString()),
SKOS.Collection, null,
MediaType.APPLICATION_JSON_TYPE, true);
+
+ freeConceptScheme =
+ new
UriRef(platformConfig.getDefaultBaseUri().getUnicodeString()
+ + ConceptManipulator.FREE_CONCEPT_SCHEME);
+ freeConceptProvider = new LocalConceptProvider(tcManager,
cgProvider,
+ freeConceptScheme);
}
/**
@@ -97,6 +124,8 @@
public GraphNode findConcepts(@QueryParam(value="searchTerm")
String searchTerm) {
+ boolean freeConceptProviderFound = false;
+
List<ConceptProvider> conceptProviderList =
conceptProviderManager
.getConceptProviders();
@@ -104,33 +133,51 @@
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);
+ if (!freeConceptProviderFound) {
+ if (cp instanceof LocalConceptProvider) {
+ if (((LocalConceptProvider)
cp).getSelectedScheme().equals(
+ freeConceptScheme)) {
+ freeConceptProviderFound = true;
}
-
}
}
+ retrieveConcepts(cp, first, resultNode, searchTerm);
+ if (first) {
+ first = false;
+ }
+ }
+ if (!freeConceptProviderFound && freeConceptProvider != null) {
+ retrieveConcepts(freeConceptProvider, first,
resultNode, searchTerm);
}
resultNode.addProperty(RDF.type, SKOS.Collection);
return resultNode;
}
+ private void retrieveConcepts(ConceptProvider conceptProvider, boolean
first,
+ GraphNode resultNode, String searchTerm) {
+ MGraph resultMGraph = (MGraph) resultNode.getGraph();
+ Graph graph = conceptProvider.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);
+ } 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);
+ }
+
+ }
+ }
+ }
+
private boolean hasSameAs(MGraph graph, NonLiteral sameAsConcept) {
Iterator<Triple> concepts = graph.filter(null, RDF.type,
SKOS.Concept);
while (concepts.hasNext()) {
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/GenericResourcePage.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/GenericResourcePage.java?rev=899362&r1=899361&r2=899362&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/GenericResourcePage.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/GenericResourcePage.java
Thu Jan 14 19:20:36 2010
@@ -63,6 +63,8 @@
@Reference
private RenderletManager renderletManager;
+ private RemoteConceptsDescriptionManager
remoteConceptsDescriptionManager = null;
+
protected void activate(ComponentContext context)
throws URISyntaxException {
@@ -71,6 +73,8 @@
new UriRef(template.toURI().toString()),
CONCEPTS.GenericResourcePage, "naked",
MediaType.APPLICATION_XHTML_XML_TYPE, true);
+
+ remoteConceptsDescriptionManager = new
RemoteConceptsDescriptionManager();
}
/**
@@ -86,7 +90,8 @@
@Context UriInfo uriInfo) {
GraphNode node = new GraphNode(new BNode(), new UnionMGraph(new
SimpleMGraph(),
- cgProvider.getContentGraph()));
+ cgProvider.getContentGraph(),
+
remoteConceptsDescriptionManager.getRemoteConceptsDescriptionMGraph()));
node.addProperty(RDF.type, PLATFORM.HeadedPage);
node.addProperty(RDF.type, CONCEPTS.GenericResourcePage);
if (uri != null) {
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/LocalConceptProvider.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/LocalConceptProvider.java?rev=899362&r1=899361&r2=899362&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/LocalConceptProvider.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/LocalConceptProvider.java
Thu Jan 14 19:20:36 2010
@@ -55,6 +55,10 @@
this.selectedScheme = selectedScheme;
}
+ public UriRef getSelectedScheme() {
+ return this.selectedScheme;
+ }
+
@Override
public Graph retrieveConcepts(String searchTerm) {
QueryParser queryParser = QueryParser.getInstance();
Modified:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptProvider.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptProvider.java?rev=899362&r1=899361&r2=899362&view=diff
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptProvider.java
(original)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptProvider.java
Thu Jan 14 19:20:36 2010
@@ -50,6 +50,7 @@
private UriRef defaultGraph = null;
private String queryTemplate = null;
private ConceptCache conceptCache = null;
+ private RemoteConceptsDescriptionManager
remoteConceptsDescriptionManager = null;
/**
* Constructs a {...@link RemoteConceptProvider} with the specified
parameters.
@@ -67,6 +68,7 @@
this.defaultGraph = defaultGraph;
this.queryTemplate = queryTemplate;
this.conceptCache = new ConceptCache(sparqlEndPoint,
defaultGraph);
+ this.remoteConceptsDescriptionManager = new
RemoteConceptsDescriptionManager();
}
@Override
@@ -107,6 +109,7 @@
SupportedFormat.RDF_XML);
is.close();
conceptCache.cache(searchTerm.toLowerCase(), parsedGraph);
+
remoteConceptsDescriptionManager.storeConceptsDescription(parsedGraph);
return parsedGraph;
} else {
final InputStream es =
con.getErrorStream();
Added:
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptsDescriptionManager.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptsDescriptionManager.java?rev=899362&view=auto
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptsDescriptionManager.java
(added)
+++
incubator/clerezza/issues/CLEREZZA-59/org.apache.clerezza.platform.concepts/org.apache.clerezza.platform.concepts.core/src/main/java/org/apache/clerezza/platform/concepts/core/RemoteConceptsDescriptionManager.java
Thu Jan 14 19:20:36 2010
@@ -0,0 +1,102 @@
+/*
+ * 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.concepts.core;
+
+import java.util.Iterator;
+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.Triple;
+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.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 stores description of concepts resulted from searches
+ * performed by {...@link RemoteConceptProvider}s.
+ *
+ * @author hasan
+ */
+public class RemoteConceptsDescriptionManager {
+
+ private UriRef REMOTE_CONCEPTS_DESCRIPTION_MGRAPH =
+ new
UriRef("http://tpf.localhost/remote.concepts.description");
+
+ /**
+ * Stores SKOS:prefLabel and RDFS.comment of concepts available in the
+ * specified Graph.
+ *
+ * @param graph
+ * the Graph which contains concepts and their
descriptions.
+ */
+ void storeConceptsDescription(Graph graph) {
+ MGraph remoteConceptsDescriptionMGraph =
+ getRemoteConceptsDescriptionMGraph();
+
+ Iterator<Triple> concepts = graph.filter(null, RDF.type,
SKOS.Concept);
+ while (concepts.hasNext()) {
+ UriRef concept = (UriRef) concepts.next().getSubject();
+ copyConceptDescription(new GraphNode(concept, graph),
+ new GraphNode(concept,
remoteConceptsDescriptionMGraph));
+ }
+ }
+
+ /**
+ * This method creates an {...@link MGraph} to store concepts'
descriptions
+ * if this graph does not already exist.
+ *
+ * @return
+ * an {...@link MGraph}
+ */
+ public MGraph getRemoteConceptsDescriptionMGraph() {
+ MGraph remoteConceptsDescriptionMGraph = null;
+ TcManager tcManager = TcManager.getInstance();
+ try {
+ remoteConceptsDescriptionMGraph =
+
tcManager.getMGraph(REMOTE_CONCEPTS_DESCRIPTION_MGRAPH);
+ } catch (NoSuchEntityException nsee) {
+ remoteConceptsDescriptionMGraph =
+
tcManager.createMGraph(REMOTE_CONCEPTS_DESCRIPTION_MGRAPH);
+ }
+ return remoteConceptsDescriptionMGraph;
+ }
+
+ private void copyConceptDescription(GraphNode sourceGraphNode,
+ GraphNode destinationGraphNode) {
+
+ destinationGraphNode.deleteNodeContext();
+
+ Iterator<Literal> prefLabelStatements =
+ sourceGraphNode.getLiterals(SKOS.prefLabel);
+ if (prefLabelStatements.hasNext()) {
+ destinationGraphNode.addProperty(SKOS.prefLabel,
+ prefLabelStatements.next());
+ }
+ Iterator<Literal> commentStatements =
+ sourceGraphNode.getLiterals(RDFS.comment);
+ while (commentStatements.hasNext()) {
+ destinationGraphNode.addProperty(RDFS.comment,
+ commentStatements.next());
+ }
+ }
+}