Skip to content

Commit

Permalink
Issue #10: Update archetype for UIMA 3 OSGi combination
Browse files Browse the repository at this point in the history
- extend script and test to check created annotations of declared type
- use generated preconfigured temaplte for engine descriptor
- refactor logging dependencies
  • Loading branch information
pkluegl committed Sep 13, 2021
1 parent 356dbd7 commit 78d2004
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/maven/archetype-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
name="${artifactId}">

<fileSets>
<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/main/ruta</directory>
</fileSet>
Expand All @@ -27,6 +30,9 @@
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/test/resources</directory>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory></directory>
<includes>
Expand Down
114 changes: 95 additions & 19 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@
<core-typesystems-version>4.1.0</core-typesystems-version>
<!-- See https://github.com/averbis/health-typesystems for the latest version of Averbis health type systems -->
<health-typesystems-version>3.1.0</health-typesystems-version>

<uima-version>3.2.0</uima-version>
<ruta-version>3.1.0</ruta-version>
<log4j-version>2.8.2</log4j-version>
<slf4j-version>1.7.30</slf4j-version>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-core</artifactId>
<version>${uima-version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>ruta-core</artifactId>
Expand Down Expand Up @@ -60,6 +71,7 @@
<artifactId>numeric-value-typesystem</artifactId>
<version>${core-typesystems-version}</version>
</dependency>

<dependency>
<groupId>de.averbis.textanalysis</groupId>
<artifactId>clinical-section-typesystem</artifactId>
Expand Down Expand Up @@ -135,14 +147,27 @@
<artifactId>tnm-typesystem</artifactId>
<version>${health-typesystems-version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
Expand All @@ -154,16 +179,37 @@
</resources>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>generate-ruta-template</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>${package}.GenerateConfiguredDescriptorTemplate</mainClass>
<classpathScope>compile</classpathScope>
<arguments>
<argument>${project.build.directory}/generated-sources/ruta/descriptor/GeneratedBasicEngine.xml</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.uima</groupId>
Expand All @@ -172,7 +218,7 @@
<executions>
<execution>
<id>descriptors</id>
<phase>generate-sources</phase>
<phase>process-classes</phase>
<goals>
<goal>generate</goal>
</goals>
Expand All @@ -183,6 +229,7 @@
<include>**/*.ruta</include>
</includes>
</scriptFiles>
<analysisEngineTemplate>${project.build.directory}/generated-sources/ruta/descriptor/GeneratedBasicEngine.xml</analysisEngineTemplate>
<typeSystemOutputDirectory>${project.build.directory}/generated-sources/ruta/descriptor</typeSystemOutputDirectory>
<analysisEngineOutputDirectory>${project.build.directory}/generated-sources/ruta/descriptor</analysisEngineOutputDirectory>
<analysisEngineSuffix>RutaAnnotator</analysisEngineSuffix>
Expand All @@ -198,9 +245,9 @@
<buildPaths>
</buildPaths>
</configuration>
</execution>
</execution>
</executions>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
Expand Down Expand Up @@ -287,6 +334,35 @@
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.6.0,)</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2021 Averbis GmbH
*
* Licensed 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 ${package};

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.metadata.ConfigurationParameter;
import org.apache.uima.resource.metadata.ConfigurationParameterDeclarations;
import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
import org.apache.uima.ruta.engine.RutaEngine;
import org.xml.sax.SAXException;

public class GenerateConfiguredDescriptorTemplate {

public static void main(String[] args) throws ResourceInitializationException,
FileNotFoundException, SAXException, IOException {

File outputFile = new File(args[0]);
outputFile.getParentFile().mkdirs();

AnalysisEngineDescription description = AnalysisEngineFactory
.createEngineDescription(RutaEngine.class);

// activate complete reindexing mode for compatibility in OSGi environments
description.getAnalysisEngineMetaData().getConfigurationParameterSettings()
.setParameterValue("reindexUpdateMode", "COMPLETE");

// optionally activate rule debug information by passing 'true'
configureIfAvailable(description, RutaEngine.PARAM_DEBUG, false);
configureIfAvailable(description, RutaEngine.PARAM_DEBUG_WITH_MATCHES, false);

try (OutputStream os = new FileOutputStream(outputFile)) {
description.toXML(os);
}
}


private static void configureIfAvailable(AnalysisEngineDescription description, String param,
Object value) {

ConfigurationParameterDeclarations configurationParameterDeclarations = description
.getAnalysisEngineMetaData().getConfigurationParameterDeclarations();
ConfigurationParameterSettings configurationParameterSettings = description
.getAnalysisEngineMetaData().getConfigurationParameterSettings();

ConfigurationParameter configurationParameter = configurationParameterDeclarations
.getConfigurationParameter(null, param);

if (configurationParameter != null) {
configurationParameterSettings.setParameterValue(param, value);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE ${package};

// add Ruta code here
TYPESYSTEM de.averbis.textanalysis.typesystems.AverbisTypeSystem;

DECLARE SomeType;
Token{->SomeType};
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Averbis GmbH
*
* Licensed 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 ${package};

import java.io.File;
Expand All @@ -8,12 +23,14 @@
import org.apache.uima.UIMAException;
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.cas.CAS;
import org.apache.uima.fit.factory.JCasFactory;
import org.apache.uima.fit.util.SimpleNamedResourceManager;
import org.apache.uima.jcas.JCas;
import org.apache.uima.pear.tools.PackageBrowser;
import org.apache.uima.pear.tools.PackageInstaller;
import org.apache.uima.resource.PearSpecifier;
import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.util.XMLInputSource;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -25,22 +42,25 @@
*/
public class PearPackageIT {

/*
* Make sure that the annotator is able to
* process text without exceptions
*/
@Test
public void testProcessText() throws IOException, UIMAException {
public void testProcessText() throws Exception {

PackageBrowser packageBrowser = this.installPackage();
XMLInputSource xmlInputSource = new XMLInputSource(packageBrowser.getComponentPearDescPath());
PearSpecifier pearSpecifier = UIMAFramework.getXMLParser().parsePearSpecifier(xmlInputSource);
AnalysisEngine analysisEngine = UIMAFramework.produceAnalysisEngine(pearSpecifier, new SimpleNamedResourceManager(), null);

JCas jCas = JCasFactory.createJCas();
jCas.setDocumentText("Test document text");

analysisEngine.process(jCas);
JCas jcas = JCasFactory.createJCas();
CAS cas = jcas.getCas();
jcas.setDocumentText("Test document text");

// mock some annotations
Ruta.apply(cas, "W{->Token};");

analysisEngine.process(jcas);

Assert.assertEquals("SomeType annotations", 3,
cas.select("${package}.${rutaScriptName}.SomeType").count());
}

private PackageBrowser installPackage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" strict="true" monitorInterval="30">
<Appenders>
<Console name="STDOUT">
<PatternLayout pattern="%d %-5p %M %logger{1} >> %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>

0 comments on commit 78d2004

Please sign in to comment.