Author: tommaso
Date: Fri Nov 5 15:32:38 2010
New Revision: 1031628
URL: http://svn.apache.org/viewvc?rev=1031628&view=rev
Log:
[CLEREZZA-352] - added a UIMA enabled ResourceTagger to use as extension in
concepts Clerezza module
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMAResourceTagger.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/
(props changed)
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/pom.xml
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/
(props changed)
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/pom.xml
Propchange:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov 5 15:32:38 2010
@@ -0,0 +1 @@
+*.iml
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/pom.xml?rev=1031628&r1=1031627&r2=1031628&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/pom.xml
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/pom.xml
Fri Nov 5 15:32:38 2010
@@ -1,11 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.clerezza</groupId>
<artifactId>org.apache.clerezza.uima.concept-tagging</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
<packaging>bundle</packaging>
- <name>Apache Clerezza UIMA extension for concept (SKOS) tagging</name>
+ <name>Apache Clerezza UIMA extension for concept tagging</name>
<description>Apache Clerezza UIMA extension for concept (SKOS)
tagging</description>
<parent>
<groupId>org.apache.clerezza</groupId>
@@ -17,5 +17,30 @@
<groupId>org.apache.clerezza</groupId>
<artifactId>org.apache.clerezza.platform.concepts.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.uima.utils</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-ep-runtime</artifactId>
+ <scope>system</scope>
+
<systemPath>${project.basedir}/../lib/org.apache.uima.runtime_2.3.1.SNAPSHOT.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>alchemy-annotator-osgi</artifactId>
+ <version>2.3.1-SNAPSHOT</version>
+ <scope>system</scope>
+
<systemPath>${project.basedir}/../org.apache.clerezza.uima.utils/lib/org.apache.uima.alchemyapi_2.3.1.SNAPSHOT.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>OpenCalaisAnnotator-osgi</artifactId>
+ <version>2.3.1-SNAPSHOT</version>
+ <scope>system</scope>
+
<systemPath>${project.basedir}/../org.apache.clerezza.uima.utils/lib/org.apache.uima.opencalais_2.3.1.SNAPSHOT.jar</systemPath>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMAResourceTagger.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMAResourceTagger.java?rev=1031628&view=auto
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMAResourceTagger.java
(added)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMAResourceTagger.java
Fri Nov 5 15:32:38 2010
@@ -0,0 +1,111 @@
+/*
+ * 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.uima.concept;
+
+import org.apache.clerezza.jaxrs.utils.RedirectUtil;
+import org.apache.clerezza.platform.concepts.core.ResourceTagger;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.ontologies.DCTERMS;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.uima.utils.ExternalServicesFacade;
+import org.apache.clerezza.uima.utils.UIMAServicesFacade;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.uima.UIMAException;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.osgi.service.component.ComponentContext;
+
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import java.net.URISyntaxException;
+import java.util.List;
+
+
+/**
+ * UIMA enabled version of {...@link ResourceTagger} providing automatic
concepts tagging
+ *
+ */
+...@component
+...@service(Object.class)
+...@property(name = "javax.ws.rs", boolValue = true)
+...@path("/concepts/tagger/")
+public class UIMAResourceTagger extends ResourceTagger {
+
+ private UIMAServicesFacade uimaServicesFacade;
+
+ @Override
+ protected void activate(ComponentContext context) throws URISyntaxException {
+ super.activate(context);
+ uimaServicesFacade = new ExternalServicesFacade();
+ }
+
+ /**
+ * Update Resource with automatic concept recognition
+ *
+ * @param uri Resource to enrich
+ * @param uriInfo Context for the Resource
+ * @return Resource page eventually containing extracted concepts
+ */
+ @POST
+ @Path("set")
+ public Response updateConcepts(@FormParam("uri") UriRef uri, @Context
UriInfo uriInfo, @FormParam("override") boolean override) {
+ if (uri != null) {
+ GraphNode node = new GraphNode(uri, cgProvider.getContentGraph());
+ List<FeatureStructure> conceptsFS = null;
+ try {
+ /* extract concepts */
+ conceptsFS = uimaServicesFacade.getConcepts(node.toString());
+
+ if (override)
+ node.deleteProperties(DCTERMS.subject);
+
+ /* if concepts have a good relevance, then add them as concept tags */
+ if (conceptsFS != null && !conceptsFS.isEmpty()) {
+ for (FeatureStructure conceptFS : conceptsFS) {
+ Type conceptType = conceptFS.getType();
+ Double relevance =
Double.valueOf(conceptFS.getStringValue(conceptType.getFeatureByBaseName("relevance")));
+ if (relevance > 0.6) {
+ node.addProperty(DCTERMS.subject, new
UriRef(conceptFS.getStringValue(conceptType.getFeatureByBaseName("text"))));
+ }
+ }
+ }
+ } catch (UIMAException e) {
+ throw new WebApplicationException(Response.status(
+ Response.Status.NOT_MODIFIED).entity("Could not automatically
recognize concepts for the specified URI.").build());
+ }
+ catch (Exception e) {
+ throw new WebApplicationException(Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity(
+ "Some error occurred while trying to add automatically
extracted concept tags.").build());
+ }
+ } else {
+ throw new WebApplicationException(Response.status(
+ Response.Status.BAD_REQUEST).entity("No resource uri
defined.").build());
+ }
+ return
RedirectUtil.createSeeOtherResponse("/concepts/generic-resource?uri=" +
+ uri.getUnicodeString(), uriInfo);
+ }
+}
Propchange:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Nov 5 15:32:38 2010
@@ -2,3 +2,5 @@
target
.classpath
.project
+
+*.iml
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/pom.xml?rev=1031628&r1=1031627&r2=1031628&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/pom.xml
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/pom.xml
Fri Nov 5 15:32:38 2010
@@ -17,7 +17,7 @@
<module>org.apache.clerezza.uima.ontologies</module>
<module>org.apache.clerezza.uima.utils</module>
<module>org.apache.clerezza.uima.metadata-generator</module>
- <!--<module>org.apache.clerezza.uima.concept-tagging</module>-->
+ <module>org.apache.clerezza.uima.concept-tagging</module>
</modules>
<dependencies>
<dependency>