You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2008/04/30 13:10:08 UTC

svn commit: r652328 - in /incubator/uima/sandbox/trunk/OpenCalaisAnnotator: ./ desc/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org/apache/uima/annotator/ src/main/java/org/ap...

Author: mbaessler
Date: Wed Apr 30 04:10:07 2008
New Revision: 652328

URL: http://svn.apache.org/viewvc?rev=652328&view=rev
Log:
UIMA-1021

create new project for the implementation of the OpenCalaisAnnotator

https://issues.apache.org/jira/browse/UIMA-1021

Added:
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/OpenCalaisAnnotator.xml
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/pom.xml
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/DescriptionElement.java
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/Offset.java
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java
    incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/RDFSaxHandler.java

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/OpenCalaisAnnotator.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/OpenCalaisAnnotator.xml?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/OpenCalaisAnnotator.xml (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/desc/OpenCalaisAnnotator.xml Wed Apr 30 04:10:07 2008
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+ -->
+<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+  <primitive>true</primitive>
+  <annotatorImplementationName>org.apache.uima.annotator.calais.OpenCalaisAnnotator</annotatorImplementationName>
+  <analysisEngineMetaData>
+    <name>OpenCalaisAnnotator</name>
+    <description></description>
+    <configurationParameters>
+       
+      <configurationParameter>
+          <name>allowDistribution</name>
+          <description></description>
+          <type>Boolean</type>
+          <multiValued>false</multiValued>
+          <mandatory>true</mandatory>
+       </configurationParameter>
+
+      <configurationParameter>
+          <name>allowSearch</name>
+          <description></description>
+          <type>Boolean</type>
+          <multiValued>false</multiValued>
+          <mandatory>true</mandatory>
+       </configurationParameter>
+
+      <configurationParameter>
+          <name>submitter</name>
+          <description></description>
+          <type>String</type>
+          <multiValued>false</multiValued>
+          <mandatory>true</mandatory>
+       </configurationParameter>
+
+      <configurationParameter>
+          <name>licenseID</name>
+          <description></description>
+          <type>String</type>
+          <multiValued>false</multiValued>
+          <mandatory>true</mandatory>
+       </configurationParameter>
+	
+    </configurationParameters>
+    
+    <configurationParameterSettings>
+    
+       <nameValuePair>
+          <name>allowDistribution</name>
+          <value>
+          	   <boolean>false</boolean> 
+          </value>
+       </nameValuePair>      
+
+       <nameValuePair>
+          <name>allowSearch</name>
+          <value>
+          	   <boolean>false</boolean> 
+          </value>
+       </nameValuePair>      
+
+       <nameValuePair>
+          <name>submitter</name>
+          <value>
+          	   <string></string> 
+          </value>
+       </nameValuePair>      
+
+       <nameValuePair>
+          <name>licenseID</name>
+          <value>
+          	   <string></string> 
+          </value>
+       </nameValuePair>      
+     
+    </configurationParameterSettings>
+    <typeSystemDescription>
+      <types>
+        <typeDescription>
+          <name>org.apache.uima.calais.Person</name>
+          <description/>
+          <supertypeName>uima.tcas.Annotation</supertypeName>
+          <features>
+				<featureDescription>
+					<name>calaisType</name>
+					<description>OpenCalais type</description>
+					<rangeTypeName>uima.cas.String</rangeTypeName>
+				</featureDescription>
+		  </features>        
+        </typeDescription>
+       </types>
+    </typeSystemDescription>
+    <capabilities>
+      <capability>
+        <inputs/>
+        <outputs>
+        </outputs>
+        <languagesSupported/>
+      </capability>
+    </capabilities>
+    <operationalProperties>
+      <modifiesCas>true</modifiesCas>
+      <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+      <outputsNewCASes>false</outputsNewCASes>
+    </operationalProperties>
+  </analysisEngineMetaData>
+   
+</analysisEngineDescription>

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/pom.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/pom.xml?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/pom.xml (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/pom.xml Wed Apr 30 04:10:07 2008
@@ -0,0 +1,177 @@
+<!--
+	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.    
+-->
+<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">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.apache.uima</groupId>
+	<artifactId>OpenCalaisAnnotator</artifactId>
+	<packaging>jar</packaging>
+	<version>2.2.2-incubating</version>
+	<name>OpenCalais UIMA Annotator Wrapper</name>
+	<url>http://incubator.apache.org/uima</url>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.uima</groupId>
+			<artifactId>uimaj-core</artifactId>
+			<version>2.2.2-incubating</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.uima</groupId>
+			<artifactId>PearPackagingMavenPlugin</artifactId>
+			<version>2.2.2-incubating</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.uima</groupId>
+			<artifactId>uimaj-test-util</artifactId>
+			<version>2.2.2-incubating</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.uima</groupId>
+			<artifactId>uimaj-component-test-util</artifactId>
+			<version>2.2.2-incubating</version>
+			<scope>compile</scope>
+		</dependency>
+	</dependencies>
+	<build>
+		<finalName>uima-an-calais</finalName>
+		<resources>
+			<resource>
+				<directory>desc</directory>
+				<excludes>
+        	  		<exclude>**</exclude>
+		        </excludes>
+			</resource>
+		</resources>
+		<plugins>
+		   <plugin>
+	          <groupId>org.apache.maven.plugins</groupId>
+	          <artifactId>maven-compiler-plugin</artifactId>
+	          <configuration>
+	            <source>1.5</source>
+	            <target>1.5</target>
+	          </configuration>
+	        </plugin>
+	        
+	        <plugin>
+		        <groupId>org.codehaus.mojo</groupId>
+		        <artifactId>buildnumber-maven-plugin</artifactId>
+		        <executions>
+		          <execution>
+		            <phase>process-classes</phase>
+		            <goals>
+		              <goal>create</goal>
+		            </goals>
+		          </execution>
+		        </executions>
+		        <configuration>
+		          <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
+		          <items>
+		            <item>timestamp</item>
+		          </items>
+		        </configuration>
+	      	</plugin>
+      
+      		<plugin>
+				<artifactId>maven-antrun-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>CopyLicenseNoticeDisclaimer</id>
+						<phase>process-resources</phase>
+						<configuration>
+							<tasks>                    
+                				<copy todir="src/main/resources/META-INF">
+                  					<fileset dir="." includes="LICENSE NOTICE DISCLAIMER"/>
+                				</copy>
+                				<copy todir="target/classes/META-INF">
+                  					<fileset dir="." includes="LICENSE.txt NOTICE.txt DISCLAIMER"/>
+                				</copy>
+							</tasks>
+						</configuration>
+						<goals>
+							<goal>run</goal>
+						</goals>
+					</execution>
+					<!-- after compilation has been done and the files have been copied to the
+						 target directory, delete them from the source directory. -->
+					<execution>
+						<id>DeleteLicenseNoticeDisclaimer</id>
+						<phase>package</phase>
+						<configuration>
+							<tasks>
+								<delete dir="src/main/resources/META-INF" deleteOnExit="true" quiet="true" failOnError="false">
+									<fileset dir="src/main/resources/META-INF"
+										includes="LICENSE NOTICE DISCLAIMER"/>
+								</delete>
+							</tasks>
+						</configuration>
+						<goals>
+							<goal>run</goal>
+						</goals>
+					</execution>	
+					<!-- also delete on clean. -->
+					<execution>
+						<id>CleanLicenseNoticeDisclaimer</id>
+						<phase>clean</phase>
+						<configuration>
+							<tasks>
+								<delete dir="src/main/resources/META-INF" deleteOnExit="true" quiet="true" failOnError="false">
+									<fileset dir="src/main/resources/META-INF"
+										includes="LICENSE NOTICE DISCLAIMER"/>
+								</delete>
+							</tasks>
+						</configuration>
+						<goals>
+							<goal>run</goal>
+						</goals>
+					</execution>	
+				</executions>
+			</plugin>
+              
+	        <plugin>
+		        <groupId>org.apache.maven.plugins</groupId>
+		        <artifactId>maven-jar-plugin</artifactId>
+		        <configuration>
+		          <archive>
+		            <manifestEntries>
+		              <Project-Title>Apache UIMA</Project-Title>
+		              <Implementation-Title>${pom.name}</Implementation-Title>
+		              <Implementation-Version>${pom.version}</Implementation-Version>
+		              <Implementation-Vendor>Apache Software Foundation</Implementation-Vendor>
+		              <Implementation-Url>${pom.url}</Implementation-Url>
+					        <Implementation-License>http://www.apache.org/licenses/LICENSE-2.0.txt</Implementation-License>
+		              <Build-Date>${buildNumber}</Build-Date>
+		            </manifestEntries>
+		          </archive>
+		        </configuration>
+      		</plugin> 
+		</plugins>
+	</build>
+	<repositories>
+		<repository>
+			<id>ApacheIncubatorRepository</id>
+			<url>
+				http://people.apache.org/repo/m2-incubating-repository/
+			</url>
+		</repository>
+	</repositories>
+</project>

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/DescriptionElement.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/DescriptionElement.java?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/DescriptionElement.java (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/DescriptionElement.java Wed Apr 30 04:10:07 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.annotator.calais;
+
+/**
+ * 
+ *
+ */
+public class DescriptionElement {
+
+  private String aboutURL = null;
+  private String typeURL = null;
+  private String subjectURL = null;
+  private int offset = 0;
+  private int length = 0;
+  
+  
+  public DescriptionElement() {
+    this.aboutURL = null;
+    this.typeURL = null;
+    this.subjectURL = null;
+    this.offset = 0;
+    this.length = 0;
+  }
+  
+  public String getAboutURL() {
+    return this.aboutURL;
+  }
+  public void setAboutURL(String aboutURL) {
+    this.aboutURL = aboutURL;
+  }
+  public String getTypeURL() {
+    return this.typeURL;
+  }
+  public void setTypeURL(String typeURL) {
+    this.typeURL = typeURL;
+  }
+  public String getSubjectURL() {
+    return this.subjectURL;
+  }
+  public void setSubjectURL(String subjectURL) {
+    this.subjectURL = subjectURL;
+  }
+  public int getOffset() {
+    return this.offset;
+  }
+  public void setOffset(int offset) {
+    this.offset = offset;
+  }
+  public int getLength() {
+    return this.length;
+  }
+  public void setLength(int length) {
+    this.length = length;
+  }
+  
+}

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/Offset.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/Offset.java?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/Offset.java (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/Offset.java Wed Apr 30 04:10:07 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.annotator.calais;
+
+/**
+ * 
+ *
+ */
+public class Offset {
+
+  private int offset = 0;
+
+  public int getOffset() {
+    return this.offset;
+  }
+
+  public void setOffset(int offset) {
+    this.offset = offset;
+  }
+  
+  
+}

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java Wed Apr 30 04:10:07 2008
@@ -0,0 +1,276 @@
+/*
+ * 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.annotator.calais;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.Level;
+import org.apache.uima.util.Logger;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class OpenCalaisAnnotator extends CasAnnotator_ImplBase {
+
+  private static String CONFIG_PARAM_NAME_SUBMITTER = "submitter";
+
+  private static String CONFIG_PARAM_NAME_LICENSE_ID = "licenseID";
+
+  private static String CONFIG_PARAM_NAME_ALLOW_SEARCH = "allowSearch";
+
+  private static String CONFIG_PARAM_NAME_ALLOW_DISTRIBUTION = "allowDistribution";
+
+  private SAXParser saxParser;
+
+  private Type personType;
+
+  private Feature personCalaisTypeFeat;
+
+  private String serviceParams;
+
+  private Logger logger;
+
+  private URL calaisService;
+
+  public void process(CAS aCas) throws AnalysisEngineProcessException {
+
+    try {
+      // open connection and send data
+      URLConnection connection = this.calaisService.openConnection();
+      connection.setDoOutput(true);
+      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection
+              .getOutputStream()));
+      writer.write(this.serviceParams);
+      writer.write(aCas.getDocumentText());
+      writer.flush();
+      writer.close();
+
+      // result is an XML that contains the RDF XML result
+      // first get the RDF XML result out of the returned XML
+      DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+      BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
+      Document feedDoc = docBuilder.parse(in);
+      String RdfXmlContent = feedDoc.getDocumentElement().getTextContent();
+
+      // create new InputStream for the RDF XML content
+      BufferedInputStream bufByteIn = new BufferedInputStream(new ByteArrayInputStream(
+              RdfXmlContent.getBytes()));
+
+      // create SAX handler
+      ArrayList<DescriptionElement> elements = new ArrayList<DescriptionElement>();
+      HashMap<String, DescriptionElement> subjectMap = new HashMap<String, DescriptionElement>();
+      Offset offset = new Offset();
+      RDFSaxHandler saxHandler = new RDFSaxHandler(elements, subjectMap, offset);
+
+      // parse RDF XML content returned by the calais service
+      this.saxParser.parse(bufByteIn, saxHandler);
+
+      // analyze entities
+      Iterator<DescriptionElement> elementIt = elements.iterator();
+      while (elementIt.hasNext()) {
+        DescriptionElement element = elementIt.next();
+        if (element.getTypeURL().equals("http://s.opencalais.com/1/type/em/e/Person")) {
+          DescriptionElement refElement = subjectMap.get(element.getAboutURL());
+          int begin = refElement.getOffset() - offset.getOffset();
+          int end = begin + refElement.getLength();
+          AnnotationFS annotFs = aCas.createAnnotation(this.personType, begin, end);
+          annotFs.setStringValue(this.personCalaisTypeFeat, element.getTypeURL().intern());
+          aCas.addFsToIndexes(annotFs);
+
+          // System.out.println("Found person: " + aCas.getDocumentText().substring(begin,end) + "
+          // (" + begin + "," + end + ")");
+        }
+      }
+    } catch (IOException ex) {
+      throw new AnalysisEngineProcessException(ex);
+    } catch (SAXException ex) {
+      throw new AnalysisEngineProcessException(ex);
+    } catch (ParserConfigurationException ex) {
+      throw new AnalysisEngineProcessException(ex);
+    }
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.uima.analysis_component.AnalysisComponent_ImplBase#initialize(org.apache.uima.UimaContext)
+   */
+  public void initialize(UimaContext context) throws ResourceInitializationException {
+    super.initialize(context);
+
+    // initialize annotator logger
+    this.logger = this.getContext().getLogger();
+
+    // create SAX parser
+    try {
+      SAXParserFactory factory = SAXParserFactory.newInstance();
+      this.saxParser = factory.newSAXParser();
+    } catch (ParserConfigurationException ex) {
+      throw new ResourceInitializationException(ex);
+    } catch (SAXException ex) {
+      throw new ResourceInitializationException(ex);
+    }
+
+    // get configuration parameters
+    // get submitter
+    String submitter = (String) this.getContext().getConfigParameterValue(
+            CONFIG_PARAM_NAME_SUBMITTER);
+    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
+        CONFIG_PARAM_NAME_SUBMITTER, submitter });
+    // get licenseID
+    String licenseID = (String) this.getContext().getConfigParameterValue(
+            CONFIG_PARAM_NAME_LICENSE_ID);
+    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
+        CONFIG_PARAM_NAME_LICENSE_ID, licenseID });
+    // get allowSearch
+    Boolean allowSearch = (Boolean) this.getContext().getConfigParameterValue(
+            CONFIG_PARAM_NAME_ALLOW_SEARCH);
+    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
+        CONFIG_PARAM_NAME_ALLOW_SEARCH, allowSearch.toString() });
+    // get allowDistribution
+    Boolean allowDistribution = (Boolean) this.getContext().getConfigParameterValue(
+            CONFIG_PARAM_NAME_ALLOW_DISTRIBUTION);
+    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
+        CONFIG_PARAM_NAME_ALLOW_DISTRIBUTION, allowDistribution.toString() });
+
+    // generate externalID for the calais service
+    String externalID = "UIMACalaisAnnotWrapper-" + System.currentTimeMillis();
+    this.logger.log(Level.CONFIG, "Generated external ID: \"{0}\"", externalID);
+
+    // create configXML for calais service
+    String configXML = getConfigXML(allowDistribution.toString(), allowSearch.toString(),
+            externalID, submitter);
+
+    // create service parameter string
+    StringBuffer serviceParamsBuf = new StringBuffer();
+    // param licenseID
+    serviceParamsBuf.append("&licenseID=");
+    serviceParamsBuf.append(licenseID);
+    // param configXML
+    serviceParamsBuf.append("&paramsXML=");
+    serviceParamsBuf.append(configXML);
+    // param content
+    serviceParamsBuf.append("&content=");
+    this.serviceParams = serviceParamsBuf.toString();
+
+    // create calais service URL
+    try {
+      this.calaisService = new URL("http://api.opencalais.com/enlighten/calais.asmx/Enlighten");
+    } catch (MalformedURLException ex) {
+      throw new ResourceInitializationException(ex);
+    }
+
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.uima.analysis_component.CasAnnotator_ImplBase#typeSystemInit(org.apache.uima.cas.TypeSystem)
+   */
+  public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException {
+    super.typeSystemInit(typeSystem);
+
+    this.personType = typeSystem.getType("org.apache.uima.calais.Person");
+    this.personCalaisTypeFeat = this.personType.getFeatureByBaseName("calaisType");
+
+  }
+
+  /**
+   * create configuration XML needed by the calais service
+   * 
+   * @param allowDistribution
+   * @param allowSearch
+   * @param externalID
+   * @param submitter
+   * @return
+   */
+  private String getConfigXML(String allowDistribution, String allowSearch, String externalID,
+          String submitter) {
+    StringBuffer buffer = new StringBuffer();
+    // create root element
+    buffer.append("<c:params");
+    buffer.append(" xmlns:c=\"http://s.opencalais.com/1/pred/\"");
+    buffer.append(" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
+
+    // set processing directives
+    buffer.append("<c:processingDirectives");
+    // set parameter contentType = text/text
+    buffer.append(" c:contentType=\"text/txt\"");
+    // set parameter outputFormat = xml/rdf
+    buffer.append(" c:outputFormat=\"xml/rdf\">");
+    // close processing directives
+    buffer.append("</c:processingDirectives>");
+
+    // set user directives
+    buffer.append("<c:userDirectives");
+    // set parameter allowDistribution
+    buffer.append(" c:allowDistribution=\"");
+    buffer.append(allowDistribution);
+    buffer.append("\"");
+    // set parameter allowSearch
+    buffer.append(" c:allowSearch=\"");
+    buffer.append(allowSearch);
+    buffer.append("\"");
+    // set parameter externalID
+    buffer.append(" c:externalID=\"");
+    buffer.append(externalID);
+    buffer.append("\"");
+    // set parameter externalID
+    buffer.append(" c:submitter=\"");
+    buffer.append(submitter);
+    buffer.append("\"");
+    // close user directives
+    buffer.append("></c:userDirectives>");
+
+    // set external meta data
+    buffer.append("<c:externalMetadata>");
+    buffer.append("</c:externalMetadata>");
+
+    // close root element
+    buffer.append("</c:params>");
+
+    return buffer.toString();
+  }
+
+}

Added: incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/RDFSaxHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/RDFSaxHandler.java?rev=652328&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/RDFSaxHandler.java (added)
+++ incubator/uima/sandbox/trunk/OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/RDFSaxHandler.java Wed Apr 30 04:10:07 2008
@@ -0,0 +1,109 @@
+/*
+ * 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.annotator.calais;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class RDFSaxHandler extends DefaultHandler {
+
+    DescriptionElement currentDesc = null;
+    private boolean enableOffset = false;
+    private boolean enableLength = false;
+    private boolean enableDocument = false;
+    private Offset offset;
+    
+    private ArrayList<DescriptionElement> elements;
+    private HashMap<String, DescriptionElement> subjectMap;
+  
+   public RDFSaxHandler(ArrayList<DescriptionElement> elements, HashMap<String, DescriptionElement> subjectMap, Offset offset) {
+     this.elements = elements;
+     this.subjectMap = subjectMap;
+     this.offset = offset;
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String,
+    *      java.lang.String, java.lang.String)
+    */
+   public void endElement(String uri, String localName, String qName)
+         throws SAXException {
+     
+     if(qName.equals("rdf:Description")) {
+       this.elements.add(this.currentDesc);
+       if(this.currentDesc.getSubjectURL() != null) {
+         this.subjectMap.put(this.currentDesc.getSubjectURL(), this.currentDesc);
+       }
+     }
+
+   }
+
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
+    *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
+    */
+   public void startElement(String uri, String localName, String qName,
+         Attributes attributes) throws SAXException {
+
+     if(qName.equals("rdf:Description")) {
+       this.currentDesc = new DescriptionElement(); 
+       // get "about" attribute value
+       this.currentDesc.setAboutURL(attributes.getValue("rdf:about"));
+     } else if(qName.equals("rdf:type")) {
+       // get "resource" attribute value
+       this.currentDesc.setTypeURL(attributes.getValue("rdf:resource"));
+     } else if(qName.equals("c:subject")) {
+       // get "resource" attribute value
+       this.currentDesc.setSubjectURL(attributes.getValue("rdf:resource"));
+     } else if(qName.equals("c:offset")) {
+         this.enableOffset = true;
+     } else if(qName.equals("c:length")) {
+         this.enableLength = true;
+     } else if(qName.equals("c:document")) {
+         this.enableDocument = true;
+     }
+   }
+
+  @Override
+  public void characters(char[] ch, int start, int length) throws SAXException {
+    if(this.enableOffset) {
+        this.currentDesc.setOffset(Integer.parseInt(new String(ch, start, length)));
+        this.enableOffset = false;
+    } else if(this.enableLength) {
+      this.currentDesc.setLength(Integer.parseInt(new String(ch, start, length)));
+      this.enableLength = false;
+    } else if(this.enableDocument) {
+      String documentText = new String(ch, start, length);
+      this.offset.setOffset(documentText.toLowerCase().indexOf("<body>") + 6);
+      this.enableDocument = false;
+    }
+
+    
+  }
+   
+   
+}