You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by to...@apache.org on 2011/02/28 10:46:04 UTC
svn commit: r1075256 - in /uima/sandbox/trunk/AlchemyAPIAnnotator: ./ desc/
src/main/java/org/apache/uima/alchemy/annotator/
src/main/java/org/apache/uima/alchemy/digester/domain/
src/main/java/org/apache/uima/alchemy/digester/sentiment/ src/main/java/...
Author: tommaso
Date: Mon Feb 28 09:46:03 2011
New Revision: 1075256
URL: http://svn.apache.org/viewvc?rev=1075256&view=rev
Log:
[UIMA-2073] - add sentiment analysis service annotator
Added:
uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java (with props)
uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java (with props)
Removed:
uima/sandbox/trunk/AlchemyAPIAnnotator/marker-file-identifying-standard-pear
Modified:
uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml Mon Feb 28 09:46:03 2011
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
+ <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+ <primitive>true</primitive>
+ <annotatorImplementationName>org.apache.uima.alchemy.annotator.TextSentimentAnalysisAnnotator</annotatorImplementationName>
+ <analysisEngineMetaData>
+ <name>TextSentimentAnalysisAEDescriptor</name>
+ <description/>
+ <version>1.0</version>
+ <vendor/>
+ <configurationParameters>
+ <configurationParameter>
+ <name>apikey</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>outputMode</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>url</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>false</mandatory>
+ </configurationParameter>
+ </configurationParameters>
+ <configurationParameterSettings>
+ <nameValuePair>
+ <name>outputMode</name>
+ <value>
+ <string>xml</string>
+ </value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>apikey</name>
+ <value>
+ <string/>
+ </value>
+ </nameValuePair>
+ </configurationParameterSettings>
+ <typeSystemDescription>
+ <types>
+ <typeDescription>
+ <name>org.apache.uima.alchemy.ts.sentiment.SentimentFS</name>
+ <description/>
+ <supertypeName>uima.tcas.Annotation</supertypeName>
+ <features>
+ <featureDescription>
+ <name>sentimentType</name>
+ <description/>
+ <rangeTypeName>uima.cas.String</rangeTypeName>
+ </featureDescription>
+ <featureDescription>
+ <name>score</name>
+ <description/>
+ <rangeTypeName>uima.cas.String</rangeTypeName>
+ </featureDescription>
+ </features>
+ </typeDescription>
+ </types>
+ </typeSystemDescription>
+ <typePriorities/>
+ <fsIndexCollection/>
+ <capabilities>
+ <capability>
+ <inputs/>
+ <outputs>
+ <type allAnnotatorFeatures="true">org.apache.uima.alchemy.ts.sentiment.SentimentFS</type>
+ </outputs>
+ <languagesSupported/>
+ </capability>
+ </capabilities>
+ <operationalProperties>
+ <modifiesCas>true</modifiesCas>
+ <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+ <outputsNewCASes>false</outputsNewCASes>
+ </operationalProperties>
+ </analysisEngineMetaData>
+ <resourceManagerConfiguration/>
+</analysisEngineDescription>
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.uima.alchemy.annotator;
+
+import org.apache.uima.alchemy.digester.DigesterProvider;
+import org.apache.uima.alchemy.digester.sentiment.SentimentAnalysisDigesterProvider;
+import org.apache.uima.jcas.JCas;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+public class TextSentimentAnalysisAnnotator extends AbstractAlchemyAnnotator {
+
+ protected URL createServiceURI() throws MalformedURLException {
+ return URI.create("http://access.alchemyapi.com/calls/text/TextGetTextSentiment").toURL();
+ }
+
+ protected String[] getServiceParameters() {
+ return new String[] { "outputMode", "url" };
+ }
+
+ protected DigesterProvider createDigester() {
+ return new SentimentAnalysisDigesterProvider();
+ }
+
+ protected void initializeRuntimeParameters(JCas aJCas) {
+ // create parameters string
+ StringBuffer serviceParamsBuf = new StringBuffer();
+ serviceParamsBuf.append("&text=");
+ String modifiedText = cleanText(aJCas);
+ serviceParamsBuf.append(modifiedText);
+ this.serviceParams += (serviceParamsBuf.toString());
+ }
+
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,44 @@
+/**
+ * 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.uima.alchemy.digester.domain;
+
+/**
+ * The document sentiment information
+ */
+public class DocumentSentiment {
+ private String type;
+ private String score;
+
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getScore() {
+ return score;
+ }
+
+ public void setScore(String score) {
+ this.score = score;
+ }
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/DocumentSentiment.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,35 @@
+/**
+ * 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.uima.alchemy.digester.domain;
+
+/**
+ * The result of a sentiment analysis service call
+ */
+public class SentimentAnalysisResults extends Results {
+
+ private DocumentSentiment docSentiment;
+
+ public DocumentSentiment getDocSentiment() {
+ return docSentiment;
+ }
+
+ public void setDocSentiment(DocumentSentiment docSentiment) {
+ this.docSentiment = docSentiment;
+ }
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/domain/SentimentAnalysisResults.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.uima.alchemy.digester.sentiment;
+
+import org.apache.commons.lang.Validate;
+import org.apache.uima.alchemy.digester.DigesterProvider;
+import org.apache.uima.alchemy.digester.OutputDigester;
+import org.apache.uima.alchemy.digester.exception.UnsupportedResultFormatException;
+
+/**
+ * Provider for sentiment analysis output parser
+ */
+public class SentimentAnalysisDigesterProvider implements DigesterProvider {
+ public OutputDigester getDigester(String type) throws UnsupportedResultFormatException {
+ Validate.notEmpty(type);
+ OutputDigester digester = null;
+ if (type.equals("xml")) {
+ digester = new XMLSentimentAnalysisDigester();
+ } else
+ throw new UnsupportedResultFormatException(type);
+ return digester;
+ }
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/SentimentAnalysisDigesterProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,50 @@
+/**
+ * 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.uima.alchemy.digester.sentiment;
+
+import org.apache.commons.digester.Digester;
+import org.apache.uima.alchemy.digester.OutputDigester;
+import org.apache.uima.alchemy.digester.domain.*;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+
+/**
+ * Digester for XML output of sentiment analysis service
+ */
+public class XMLSentimentAnalysisDigester implements OutputDigester {
+ public Results parseAlchemyXML(InputStream responseStream) throws IOException, SAXException,
+ URISyntaxException {
+ Digester digester = new Digester();
+ digester.setValidating(false);
+
+ digester.addObjectCreate("results", SentimentAnalysisResults.class);
+ digester.addBeanPropertySetter("results/status", "status");
+ digester.addBeanPropertySetter("results/url", "url");
+ digester.addBeanPropertySetter("results/language", "language");
+ digester.addObjectCreate("results/docSentiment", DocumentSentiment.class);
+ digester.addBeanPropertySetter("results/docSentiment/type", "type");
+ digester.addBeanPropertySetter("results/docSentiment/score", "score");
+ digester.addSetNext("results/docSentiment", "setDocSentiment");
+
+ return (Results) digester.parse(responseStream);
+ }
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/digester/sentiment/XMLSentimentAnalysisDigester.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java?rev=1075256&r1=1075255&r2=1075256&view=diff
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java (original)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/Alchemy2TypeSystemMapper.java Mon Feb 28 09:46:03 2011
@@ -29,6 +29,7 @@ import org.apache.uima.alchemy.digester.
import org.apache.uima.alchemy.digester.domain.LanguageDetectionResults;
import org.apache.uima.alchemy.digester.domain.MicroformatsResults;
import org.apache.uima.alchemy.digester.domain.Results;
+import org.apache.uima.alchemy.digester.domain.SentimentAnalysisResults;
import org.apache.uima.alchemy.mapper.exception.MappingException;
import org.apache.uima.alchemy.mapper.processor.AlchemyOutputProcessor;
import org.apache.uima.alchemy.mapper.processor.AnnotatedEntitiesProcessor;
@@ -38,6 +39,7 @@ import org.apache.uima.alchemy.mapper.pr
import org.apache.uima.alchemy.mapper.processor.LanguageProcessor;
import org.apache.uima.alchemy.mapper.processor.MicroformatsProcessor;
import org.apache.uima.alchemy.mapper.processor.RankedEntitiesProcessor;
+import org.apache.uima.alchemy.mapper.processor.SentimentAnalysisProcessor;
import org.apache.uima.jcas.JCas;
public class Alchemy2TypeSystemMapper {
@@ -63,6 +65,7 @@ public class Alchemy2TypeSystemMapper {
processors.put(KeywordResults.class, new KeywordProcessor());
processors.put(LanguageDetectionResults.class, new LanguageProcessor());
processors.put(MicroformatsResults.class, new MicroformatsProcessor());
+ processors.put(SentimentAnalysisResults.class, new SentimentAnalysisProcessor());
}
private static void setLanaguage(Results results, JCas aJCas) {
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.uima.alchemy.mapper.processor;
+
+import org.apache.uima.alchemy.digester.domain.DocumentSentiment;
+import org.apache.uima.alchemy.digester.domain.Results;
+import org.apache.uima.alchemy.digester.domain.SentimentAnalysisResults;
+import org.apache.uima.alchemy.ts.sentiment.SentimentFS;
+import org.apache.uima.jcas.JCas;
+
+public class SentimentAnalysisProcessor implements AlchemyOutputProcessor {
+
+ public void process(JCas cas, Results results) throws Exception {
+ DocumentSentiment docSentiment = ((SentimentAnalysisResults) results).getDocSentiment();
+ if (docSentiment != null) {
+ SentimentFS sentimentFS = new SentimentFS(cas);
+ sentimentFS.setScore(docSentiment.getScore());
+ sentimentFS.setSentimentType(docSentiment.getType());
+ sentimentFS.addToIndexes();
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/mapper/processor/SentimentAnalysisProcessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,98 @@
+
+
+/* First created by JCasGen Mon Feb 28 10:31:26 CET 2011 */
+package org.apache.uima.alchemy.ts.sentiment;
+
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.jcas.cas.TOP_Type;
+
+import org.apache.uima.jcas.tcas.Annotation;
+
+
+/**
+ * Updated by JCasGen Mon Feb 28 10:31:26 CET 2011
+ * XML source: /Users/tommasoteofili/Documents/workspaces/uima_workspace/uima/sandbox/AlchemyAPIAnnotator/desc/TextSentimentAnalysisAEDescriptor.xml
+ * @generated */
+public class SentimentFS extends Annotation {
+ /** @generated
+ * @ordered
+ */
+ public final static int typeIndexID = JCasRegistry.register(SentimentFS.class);
+ /** @generated
+ * @ordered
+ */
+ public final static int type = typeIndexID;
+ /** @generated */
+ public int getTypeIndexID() {return typeIndexID;}
+
+ /** Never called. Disable default constructor
+ * @generated */
+ protected SentimentFS() {}
+
+ /** Internal - constructor used by generator
+ * @generated */
+ public SentimentFS(int addr, TOP_Type type) {
+ super(addr, type);
+ readObject();
+ }
+
+ /** @generated */
+ public SentimentFS(JCas jcas) {
+ super(jcas);
+ readObject();
+ }
+
+ /** @generated */
+ public SentimentFS(JCas jcas, int begin, int end) {
+ super(jcas);
+ setBegin(begin);
+ setEnd(end);
+ readObject();
+ }
+
+ /** <!-- begin-user-doc -->
+ * Write your own initialization here
+ * <!-- end-user-doc -->
+ @generated modifiable */
+ private void readObject() {}
+
+
+
+ //*--------------*
+ //* Feature: sentimentType
+
+ /** getter for sentimentType - gets
+ * @generated */
+ public String getSentimentType() {
+ if (SentimentFS_Type.featOkTst && ((SentimentFS_Type)jcasType).casFeat_sentimentType == null)
+ jcasType.jcas.throwFeatMissing("sentimentType", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ return jcasType.ll_cas.ll_getStringValue(addr, ((SentimentFS_Type)jcasType).casFeatCode_sentimentType);}
+
+ /** setter for sentimentType - sets
+ * @generated */
+ public void setSentimentType(String v) {
+ if (SentimentFS_Type.featOkTst && ((SentimentFS_Type)jcasType).casFeat_sentimentType == null)
+ jcasType.jcas.throwFeatMissing("sentimentType", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ jcasType.ll_cas.ll_setStringValue(addr, ((SentimentFS_Type)jcasType).casFeatCode_sentimentType, v);}
+
+
+ //*--------------*
+ //* Feature: score
+
+ /** getter for score - gets
+ * @generated */
+ public String getScore() {
+ if (SentimentFS_Type.featOkTst && ((SentimentFS_Type)jcasType).casFeat_score == null)
+ jcasType.jcas.throwFeatMissing("score", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ return jcasType.ll_cas.ll_getStringValue(addr, ((SentimentFS_Type)jcasType).casFeatCode_score);}
+
+ /** setter for score - sets
+ * @generated */
+ public void setScore(String v) {
+ if (SentimentFS_Type.featOkTst && ((SentimentFS_Type)jcasType).casFeat_score == null)
+ jcasType.jcas.throwFeatMissing("score", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ jcasType.ll_cas.ll_setStringValue(addr, ((SentimentFS_Type)jcasType).casFeatCode_score, v);}
+ }
+
+
\ No newline at end of file
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,101 @@
+
+/* First created by JCasGen Mon Feb 28 10:31:26 CET 2011 */
+package org.apache.uima.alchemy.ts.sentiment;
+
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.FSGenerator;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.FeatureImpl;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.jcas.tcas.Annotation_Type;
+
+/**
+ * Updated by JCasGen Mon Feb 28 10:31:26 CET 2011
+ * @generated */
+public class SentimentFS_Type extends Annotation_Type {
+ /** @generated */
+ protected FSGenerator getFSGenerator() {return fsGenerator;}
+ /** @generated */
+ private final FSGenerator fsGenerator =
+ new FSGenerator() {
+ public FeatureStructure createFS(int addr, CASImpl cas) {
+ if (SentimentFS_Type.this.useExistingInstance) {
+ // Return eq fs instance if already created
+ FeatureStructure fs = SentimentFS_Type.this.jcas.getJfsFromCaddr(addr);
+ if (null == fs) {
+ fs = new SentimentFS(addr, SentimentFS_Type.this);
+ SentimentFS_Type.this.jcas.putJfsFromCaddr(addr, fs);
+ return fs;
+ }
+ return fs;
+ } else return new SentimentFS(addr, SentimentFS_Type.this);
+ }
+ };
+ /** @generated */
+ public final static int typeIndexID = SentimentFS.typeIndexID;
+ /** @generated
+ @modifiable */
+ public final static boolean featOkTst = JCasRegistry.getFeatOkTst("org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+
+ /** @generated */
+ final Feature casFeat_sentimentType;
+ /** @generated */
+ final int casFeatCode_sentimentType;
+ /** @generated */
+ public String getSentimentType(int addr) {
+ if (featOkTst && casFeat_sentimentType == null)
+ jcas.throwFeatMissing("sentimentType", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ return ll_cas.ll_getStringValue(addr, casFeatCode_sentimentType);
+ }
+ /** @generated */
+ public void setSentimentType(int addr, String v) {
+ if (featOkTst && casFeat_sentimentType == null)
+ jcas.throwFeatMissing("sentimentType", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ ll_cas.ll_setStringValue(addr, casFeatCode_sentimentType, v);}
+
+
+
+ /** @generated */
+ final Feature casFeat_score;
+ /** @generated */
+ final int casFeatCode_score;
+ /** @generated */
+ public String getScore(int addr) {
+ if (featOkTst && casFeat_score == null)
+ jcas.throwFeatMissing("score", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ return ll_cas.ll_getStringValue(addr, casFeatCode_score);
+ }
+ /** @generated */
+ public void setScore(int addr, String v) {
+ if (featOkTst && casFeat_score == null)
+ jcas.throwFeatMissing("score", "org.apache.uima.alchemy.ts.sentiment.SentimentFS");
+ ll_cas.ll_setStringValue(addr, casFeatCode_score, v);}
+
+
+
+
+
+ /** initialize variables to correspond with Cas Type and Features
+ * @generated */
+ public SentimentFS_Type(JCas jcas, Type casType) {
+ super(jcas, casType);
+ casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl)this.casType, getFSGenerator());
+
+
+ casFeat_sentimentType = jcas.getRequiredFeatureDE(casType, "sentimentType", "uima.cas.String", featOkTst);
+ casFeatCode_sentimentType = (null == casFeat_sentimentType) ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl)casFeat_sentimentType).getCode();
+
+
+ casFeat_score = jcas.getRequiredFeatureDE(casType, "score", "uima.cas.String", featOkTst);
+ casFeatCode_score = (null == casFeat_score) ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl)casFeat_score).getCode();
+
+ }
+}
+
+
+
+
\ No newline at end of file
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/main/java/org/apache/uima/alchemy/ts/sentiment/SentimentFS_Type.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java?rev=1075256&view=auto
==============================================================================
--- uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java (added)
+++ uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java Mon Feb 28 09:46:03 2011
@@ -0,0 +1,62 @@
+/**
+ * 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.uima.alchemy.annotator;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.alchemy.ts.sentiment.SentimentFS;
+import org.apache.uima.alchemy.utils.TestUtils;
+import org.apache.uima.jcas.JCas;
+import org.junit.Test;
+
+/**
+ * SentimentAnalysis service test
+ */
+
+public class TextSentimentAnalysisAnnotatorTest {
+ @SuppressWarnings("unchecked")
+ @Test
+ public void annotatorIntegrationTest() {
+ String doc = "The BBC's Jim Muir says the Tunisians have been struggling to cope with the deluge of refugees";
+ String xmlPath = "desc/TextSentimentAnalysisAEDescriptor.xml";
+ try {
+ Map<String, Object> parameterSettings = new HashMap<String, Object>();
+ parameterSettings.put("apikey", "04490000a72fe7ec5cb3497f14e77f338c86f2fe");
+ JCas sentimentJCas = TestUtils.executeAE(TestUtils.getAE(xmlPath, parameterSettings), doc);
+ List<SentimentFS> sentimentList = (List<SentimentFS>) TestUtils.getAllFSofType(
+ SentimentFS.type, sentimentJCas);
+ assertTrue(sentimentList != null);
+ assertTrue(sentimentList.size() == 1);
+ SentimentFS sentimentFS = sentimentList.get(0);
+ assertTrue(sentimentFS != null);
+ assertTrue(sentimentFS.getSentimentType() != null
+ && "negative".equals(sentimentFS.getSentimentType()));
+ assertTrue(sentimentFS.getScore() != null && Double.valueOf(sentimentFS.getScore()) < 0);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.toString());
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: uima/sandbox/trunk/AlchemyAPIAnnotator/src/test/java/org/apache/uima/alchemy/annotator/TextSentimentAnalysisAnnotatorTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain