Author: tommaso Date: Thu Apr 28 09:01:10 2011 New Revision: 1097371 URL: http://svn.apache.org/viewvc?rev=1097371&view=rev Log: [CLEREZZA-497] - add uima.casconsumer module
Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/ (with props) incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumer.java incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ClerezzaCASConsumerDescriptor.xml incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerTest.java Propchange: incubator/clerezza/trunk/parent/uima/uima.casconsumer/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Thu Apr 28 09:01:10 2011 @@ -0,0 +1 @@ +*.iml Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml?rev=1097371&view=auto ============================================================================== --- incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml (added) +++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml Thu Apr 28 09:01:10 2011 @@ -0,0 +1,51 @@ +<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.clerezza</groupId> + <artifactId>uima.casconsumer</artifactId> + <version>0.1-incubating-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>Clerezza - Apache UIMA CAS Consumer for Graph objects</name> + <description>Clerezza - Apache UIMA CAS Consumer for Graph objects</description> + <parent> + <groupId>org.apache.clerezza</groupId> + <artifactId>uima</artifactId> + <version>0.1-incubating-SNAPSHOT</version> + </parent> + <dependencies> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>uima.utils</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>uima.ontologies</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.uima</groupId> + <artifactId>uimaj-ep-runtime</artifactId> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>rdf.core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>rdf.utils</artifactId> + </dependency> + <dependency> + <groupId>org.apache.uima</groupId> + <artifactId>uimaj-component-test-util</artifactId> + <version>2.3.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>rdf.simple.storage</artifactId> + <scope>runtime</scope> + </dependency> + </dependencies> +</project> Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumer.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumer.java?rev=1097371&view=auto ============================================================================== --- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumer.java (added) +++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumer.java Thu Apr 28 09:01:10 2011 @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.clerezza.uima.casconsumer; + +import org.apache.clerezza.rdf.core.BNode; +import org.apache.clerezza.rdf.core.MGraph; +import org.apache.clerezza.rdf.core.TripleCollection; +import org.apache.clerezza.rdf.core.UriRef; +import org.apache.clerezza.rdf.core.access.TcManager; +import org.apache.clerezza.rdf.utils.GraphNode; +import org.apache.clerezza.uima.utils.UIMAUtils; +import org.apache.clerezza.uima.utils.exception.FeatureStructureNotFoundException; +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.CASException; +import org.apache.uima.jcas.cas.TOP; +import org.apache.uima.resource.ResourceInitializationException; + +/** + * A UIMA CASConsumer which consumes a {@link CAS} to a Clerezza {@link TripleCollection} + */ +public class ClerezzaCASConsumer extends CasAnnotator_ImplBase { + + private String graphName; + private String casModelFilePath; + + @Override + public void initialize(UimaContext context) throws ResourceInitializationException { + super.initialize(context); + + // get the RDF model + casModelFilePath = String.valueOf(context.getConfigParameterValue("casModelFile")); + + // get the output graph name + graphName = String.valueOf(context.getConfigParameterValue("graphName")); + } + + @Override + public void process(CAS cas) throws AnalysisEngineProcessException { + // create the output graph + MGraph outputGraph = createGraph(); + + // create the root node + GraphNode sample = new GraphNode(new BNode(), outputGraph); + + if (casModelFilePath!=null && casModelFilePath.length()>0) { + try { + UIMAUtils.enhanceNode(sample, UIMAUtils.getAllFSofType(TOP.type, cas.getJCas())); + } catch (FeatureStructureNotFoundException e) { + throw new AnalysisEngineProcessException(e); + } catch (CASException e) { + throw new AnalysisEngineProcessException(e); + } + } + + } + + private MGraph createGraph() { + final TcManager tcManager = TcManager.getInstance(); + final UriRef mGraphName = new UriRef(graphName); + return tcManager.createMGraph(mGraphName); + } +} Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ClerezzaCASConsumerDescriptor.xml URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ClerezzaCASConsumerDescriptor.xml?rev=1097371&view=auto ============================================================================== --- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ClerezzaCASConsumerDescriptor.xml (added) +++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/resources/ClerezzaCASConsumerDescriptor.xml Thu Apr 28 09:01:10 2011 @@ -0,0 +1,79 @@ +<?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.clerezza.uima.casconsumer.ClerezzaCASConsumer</annotatorImplementationName> + <analysisEngineMetaData> + <name>ClerezzaCASConsumerDescriptor</name> + <description>CAS Consumer to produce Clerezza graphs</description> + <version>1.0</version> + <vendor/> + <configurationParameters> + <configurationParameter> + <name>graphName</name> + <type>String</type> + <multiValued>false</multiValued> + <mandatory>true</mandatory> + </configurationParameter> + <configurationParameter> + <name>casModelFile</name> + <type>String</type> + <multiValued>false</multiValued> + <mandatory>true</mandatory> + </configurationParameter> + </configurationParameters> + <configurationParameterSettings> + <nameValuePair> + <name>graphName</name> + <value> + <string>uimagraph</string> + </value> + </nameValuePair> + <nameValuePair> + <name>casModelFile</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: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerTest.java URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerTest.java?rev=1097371&view=auto ============================================================================== --- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerTest.java (added) +++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerTest.java Thu Apr 28 09:01:10 2011 @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.clerezza.uima.casconsumer; + +import org.apache.uima.test.junit_extension.AnnotatorTester; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * TestCase for {@link ClerezzaCASConsumer} + */ +public class ClerezzaCASConsumerTest { + + @Test + public void configurationTest() { + try { + AnnotatorTester.doConfigurationTest("src/main/resources/ClerezzaCASConsumerDescriptor.xml"); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } +}