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/01/03 09:25:51 UTC
svn commit: r1054549 - in /uima/sandbox/trunk/RDFCASConsumer: ./ 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/rdf/
src/main/resources/ src/test/ src/test/j...
Author: tommaso
Date: Mon Jan 3 08:25:50 2011
New Revision: 1054549
URL: http://svn.apache.org/viewvc?rev=1054549&view=rev
Log:
[UIMA-1984] - initial import of RDF CAS Consumer
Added:
uima/sandbox/trunk/RDFCASConsumer/ (with props)
uima/sandbox/trunk/RDFCASConsumer/desc/
uima/sandbox/trunk/RDFCASConsumer/desc/RDFCASConsumerDescriptor.xml
uima/sandbox/trunk/RDFCASConsumer/pom.xml
uima/sandbox/trunk/RDFCASConsumer/src/
uima/sandbox/trunk/RDFCASConsumer/src/main/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/
uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/RDFCASConsumer.java
uima/sandbox/trunk/RDFCASConsumer/src/main/resources/
uima/sandbox/trunk/RDFCASConsumer/src/test/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/
uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/RDFCASConsumerTest.java
uima/sandbox/trunk/RDFCASConsumer/src/test/resources/
uima/sandbox/trunk/RDFCASConsumer/src/test/resources/TestRDFCASConsumerDescriptor.xml
Propchange: uima/sandbox/trunk/RDFCASConsumer/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jan 3 08:25:50 2011
@@ -0,0 +1 @@
+*.iml
Added: uima/sandbox/trunk/RDFCASConsumer/desc/RDFCASConsumerDescriptor.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/RDFCASConsumer/desc/RDFCASConsumerDescriptor.xml?rev=1054549&view=auto
==============================================================================
--- uima/sandbox/trunk/RDFCASConsumer/desc/RDFCASConsumerDescriptor.xml (added)
+++ uima/sandbox/trunk/RDFCASConsumer/desc/RDFCASConsumerDescriptor.xml Mon Jan 3 08:25:50 2011
@@ -0,0 +1,91 @@
+<?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.rdf.RDFCASConsumer</annotatorImplementationName>
+ <analysisEngineMetaData>
+ <name>RDFCASConsumerDescriptor</name>
+ <description>Creates an RDF version of a CAS</description>
+ <version>1.0</version>
+ <vendor/>
+ <configurationParameters>
+ <configurationParameter>
+ <name>format</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>file</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>view</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>false</mandatory>
+ </configurationParameter>
+ </configurationParameters>
+ <configurationParameterSettings>
+ <nameValuePair>
+ <name>format</name>
+ <value>
+ <string>application/rdf+xml</string>
+ </value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>file</name>
+ <value>
+ <string></string>
+ </value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>view</name>
+ <value>
+ <string></string>
+ </value>
+ </nameValuePair>
+ </configurationParameterSettings>
+ <typeSystemDescription>
+ <types>
+ </types>
+ </typeSystemDescription>
+ <typePriorities/>
+ <fsIndexCollection/>
+ <capabilities>
+ <capability>
+ <inputs/>
+ <outputs/>
+ <languagesSupported/>
+ </capability>
+ </capabilities>
+ <operationalProperties>
+ <modifiesCas>true</modifiesCas>
+ <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+ <outputsNewCASes>false</outputsNewCASes>
+ </operationalProperties>
+ </analysisEngineMetaData>
+ <resourceManagerConfiguration/>
+</analysisEngineDescription>
Added: uima/sandbox/trunk/RDFCASConsumer/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/RDFCASConsumer/pom.xml?rev=1054549&view=auto
==============================================================================
--- uima/sandbox/trunk/RDFCASConsumer/pom.xml (added)
+++ uima/sandbox/trunk/RDFCASConsumer/pom.xml Mon Jan 3 08:25:50 2011
@@ -0,0 +1,119 @@
+<?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.
+-->
+<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>
+
+ <parent>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>parent-pom</artifactId>
+ <version>1</version>
+ </parent>
+
+ <artifactId>RDFCASConsumer</artifactId>
+ <version>2.3.1-SNAPSHOT</version>
+ <name>UIMA Annotator: ${project.artifactId}</name>
+ <description>Writes information contained in CAS objects into a RDF-like file</description>
+ <url>${uimaWebsiteUrl}</url>
+
+ <!-- Special inheritance note
+ even though the <scm> element that follows is exactly the
+ same as those in super poms, it cannot be inherited because
+ there is some special code that computes the connection elements
+ from the chain of parent poms, if this is omitted.
+
+ Keeping this a bit factored allows cutting/pasting the <scm>
+ element, and just changing the following two properties -->
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/uima/${uimaScmRoot}/trunk/${uimaScmProject}
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/uima/${uimaScmRoot}/trunk/${uimaScmProject}
+ </developerConnection>
+ <url>
+ http://svn.apache.org/viewvc/uima/${uimaScmRoot}/trunk/${uimaScmProject}
+ </url>
+ </scm>
+
+ <properties>
+ <uimaScmRoot>sandbox</uimaScmRoot>
+ <uimaScmProject>${project.artifactId}</uimaScmProject>
+ <uimaDependencyVersion>2.3.1-SNAPSHOT</uimaDependencyVersion>
+ <pearMainDescriptor>desc/RDFCASConsumer.xml</pearMainDescriptor>
+ <bookNameRoot>RDFCASConsumerUserGuide</bookNameRoot>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-core</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-component-test-util</artifactId>
+ <version>2.3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </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.clerezza</groupId>
+ <artifactId>org.apache.clerezza.uima.ontologies</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.core</artifactId>
+ <version>0.12-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.utils</artifactId>
+ <version>0.13-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.8</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>org.apache.clerezza.rdf.jena.serializer</artifactId>
+ <version>0.9-incubating-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>uima-rdfcasconsumer</finalName>
+ </build>
+
+</project>
\ No newline at end of file
Added: uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/RDFCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/RDFCASConsumer.java?rev=1054549&view=auto
==============================================================================
--- uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/RDFCASConsumer.java (added)
+++ uima/sandbox/trunk/RDFCASConsumer/src/main/java/org/apache/uima/rdf/RDFCASConsumer.java Mon Jan 3 08:25:50 2011
@@ -0,0 +1,133 @@
+/**
+ * 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.rdf;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.clerezza.uima.utils.UIMAUtils;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.JCasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * CASConsumer that writes CAS contents to an RDF-like format
+ */
+public class RDFCASConsumer extends JCasAnnotator_ImplBase {
+
+ private String view;
+ private String file;
+ private String format;
+
+ @Override
+ public void initialize(UimaContext context) {
+ view = String.valueOf(context.getConfigParameterValue("view"));
+ file = String.valueOf(context.getConfigParameterValue("file"));
+ format = String.valueOf(context.getConfigParameterValue("format"));
+ }
+
+
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ try {
+
+ JCas selectedView = getCASToSerialize(jCas);
+
+ GraphNode node = createNode(selectedView);
+
+ Type type = selectedView.getCasType(Annotation.type);
+
+ List<FeatureStructure> annotations = getAnnotations(selectedView, type);
+
+ UIMAUtils.enhanceNode(node, annotations);
+
+ writeFile(node);
+
+ } catch (Exception e) {
+ throw new AnalysisEngineProcessException(e);
+ }
+
+ }
+
+ private JCas getCASToSerialize(JCas jCas) throws CASException {
+ JCas selectedView;
+ if (view != null && view.length() > 0 && !view.equals("current")) {
+ selectedView = jCas.getView(view);
+ } else
+ selectedView = jCas;
+ return selectedView;
+ }
+
+ private GraphNode createNode(JCas selectedView) {
+ MGraph mGraph = new SimpleMGraph();
+ return new GraphNode(new UriRef(selectedView.toString()), mGraph);
+ }
+
+ private List<FeatureStructure> getAnnotations(JCas selectedView, Type type) {
+ AnnotationIndex<Annotation> annotationIndex = selectedView.getAnnotationIndex(type);
+ List<FeatureStructure> annotations = new ArrayList<FeatureStructure>(annotationIndex.size());
+ for (Annotation a : annotationIndex) {
+ annotations.add(a);
+ }
+ return annotations;
+ }
+
+ private void writeFile(GraphNode node) throws IOException {
+
+ OutputStream outputStream = null;
+ try {
+ URI uri = URI.create(file);
+
+ File f = new File(uri);
+ if (!f.exists())
+ f.createNewFile();
+
+ outputStream = new FileOutputStream(f);
+ Serializer serializer = Serializer.getInstance();
+ serializer.serialize(outputStream, node.getGraph(), format);
+ outputStream.flush();
+ outputStream.close();
+ } finally {
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException e1) {
+ // do nothing
+ }
+ }
+ }
+ }
+}
Added: uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/RDFCASConsumerTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/RDFCASConsumerTest.java?rev=1054549&view=auto
==============================================================================
--- uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/RDFCASConsumerTest.java (added)
+++ uima/sandbox/trunk/RDFCASConsumer/src/test/java/org/apache/uima/rdf/RDFCASConsumerTest.java Mon Jan 3 08:25:50 2011
@@ -0,0 +1,69 @@
+/**
+ * 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.rdf;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.admin.CASFactory;
+import org.apache.uima.cas.admin.CASMgr;
+import org.apache.uima.cas.impl.TypeSystemImpl;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.test.junit_extension.AnnotatorTester;
+import org.junit.Test;
+
+
+/**
+ */
+public class RDFCASConsumerTest {
+ private static final String text = "President Obama vows to \"make BP pay\" for the Gulf oil spill, and says the US must end its fossil fuel \"addiction\"";
+
+ @Test
+ public void testSerializing() {
+ try {
+
+ TypeSystem ts = new TypeSystemImpl();
+
+ CASMgr casMgr = CASFactory.createCAS(ts);
+ casMgr.initCASIndexes();
+
+ AnnotatorTester tester = new AnnotatorTester("src/test/resources/TestRDFCASConsumerDescriptor.xml");
+ casMgr.getIndexRepositoryMgr().commit();
+
+ CAS cas = casMgr.getCAS();
+
+ JCas jCas = cas.getCurrentView().getJCas();
+ jCas.setDocumentText(text);
+ Annotation annotation = new Annotation(jCas);
+ annotation.setBegin(9);
+ annotation.setEnd(15);
+ annotation.addToIndexes();
+
+ Annotation annotation2 = new Annotation(jCas);
+ annotation2.setBegin(16);
+ annotation2.setEnd(20);
+ annotation2.addToIndexes();
+
+ tester.performTest(cas);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: uima/sandbox/trunk/RDFCASConsumer/src/test/resources/TestRDFCASConsumerDescriptor.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/RDFCASConsumer/src/test/resources/TestRDFCASConsumerDescriptor.xml?rev=1054549&view=auto
==============================================================================
--- uima/sandbox/trunk/RDFCASConsumer/src/test/resources/TestRDFCASConsumerDescriptor.xml (added)
+++ uima/sandbox/trunk/RDFCASConsumer/src/test/resources/TestRDFCASConsumerDescriptor.xml Mon Jan 3 08:25:50 2011
@@ -0,0 +1,91 @@
+<?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.rdf.RDFCASConsumer</annotatorImplementationName>
+ <analysisEngineMetaData>
+ <name>RDFCASConsumerDescriptor</name>
+ <description>Creates an RDF version of a CAS</description>
+ <version>1.0</version>
+ <vendor/>
+ <configurationParameters>
+ <configurationParameter>
+ <name>format</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>file</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>true</mandatory>
+ </configurationParameter>
+ <configurationParameter>
+ <name>view</name>
+ <type>String</type>
+ <multiValued>false</multiValued>
+ <mandatory>false</mandatory>
+ </configurationParameter>
+ </configurationParameters>
+ <configurationParameterSettings>
+ <nameValuePair>
+ <name>format</name>
+ <value>
+ <string>application/rdf+xml</string>
+ </value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>file</name>
+ <value>
+ <string>file:///tmp/test.rdf</string>
+ </value>
+ </nameValuePair>
+ <nameValuePair>
+ <name>view</name>
+ <value>
+ <string></string>
+ </value>
+ </nameValuePair>
+ </configurationParameterSettings>
+ <typeSystemDescription>
+ <types>
+ </types>
+ </typeSystemDescription>
+ <typePriorities/>
+ <fsIndexCollection/>
+ <capabilities>
+ <capability>
+ <inputs/>
+ <outputs/>
+ <languagesSupported/>
+ </capability>
+ </capabilities>
+ <operationalProperties>
+ <modifiesCas>true</modifiesCas>
+ <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+ <outputsNewCASes>false</outputsNewCASes>
+ </operationalProperties>
+ </analysisEngineMetaData>
+ <resourceManagerConfiguration/>
+</analysisEngineDescription>