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
- fixed tests
  • Loading branch information
pkluegl committed Sep 14, 2021
1 parent 78d2004 commit 9a904b4
Show file tree
Hide file tree
Showing 18 changed files with 462 additions and 87 deletions.
5 changes: 4 additions & 1 deletion src/main/resources/META-INF/maven/archetype-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<fileSet filtered="true" packaged="false">
<directory>src/test/resources</directory>
<includes>
<include>log4j2.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory></directory>
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<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>
Expand Down Expand Up @@ -203,7 +203,7 @@
</goals>
<configuration>
<mainClass>${package}.GenerateConfiguredDescriptorTemplate</mainClass>
<classpathScope>compile</classpathScope>
<classpathScope>test</classpathScope>
<arguments>
<argument>${project.build.directory}/generated-sources/ruta/descriptor/GeneratedBasicEngine.xml</argument>
</arguments>
Expand Down Expand Up @@ -252,7 +252,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<executions>
<!-- Copies the type system to the pearPackaging folder -->
<execution>
<id>copy-type-system</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.ReindexUpdateMode;
import org.apache.uima.ruta.engine.RutaEngine;
import org.xml.sax.SAXException;

Expand All @@ -37,13 +38,14 @@ public static void main(String[] args) throws ResourceInitializationException,

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");
.setParameterValue(RutaEngine.PARAM_REINDEX_UPDATE_MODE,
ReindexUpdateMode.COMPLETE.name());

// optionally activate rule debug information by passing 'true'
configureIfAvailable(description, RutaEngine.PARAM_DEBUG, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
package ${package};

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.uima.UIMAException;
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.cas.CAS;
Expand All @@ -45,7 +43,7 @@ public class PearPackageIT {
@Test
public void testProcessText() throws Exception {

PackageBrowser packageBrowser = this.installPackage();
PackageBrowser packageBrowser = this.installPackage();
XMLInputSource xmlInputSource = new XMLInputSource(packageBrowser.getComponentPearDescPath());
PearSpecifier pearSpecifier = UIMAFramework.getXMLParser().parsePearSpecifier(xmlInputSource);
AnalysisEngine analysisEngine = UIMAFramework.produceAnalysisEngine(pearSpecifier, new SimpleNamedResourceManager(), null);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/projects/it1/archetype.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ groupId=com.example
artifactId=contract-annotator
version=0.1.0-SNAPSHOT
package=com.example.nlp
rutaScriptName=Contractannotator
rutaScriptName=Contract
118 changes: 97 additions & 21 deletions src/test/resources/projects/it1/reference/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>com.example.nlp.GenerateConfiguredDescriptorTemplate</mainClass>
<classpathScope>test</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,14 +245,14 @@
<buildPaths>
</buildPaths>
</configuration>
</execution>
</execution>
</executions>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<executions>
<!-- Copies the type system to the pearPackaging folder -->
<execution>
<id>copy-type-system</id>
Expand Down Expand Up @@ -276,7 +323,7 @@
<execution>
<phase>package</phase>
<configuration>
<mainComponentDesc>desc/com/example/nlp/ContractannotatorRutaAnnotator.xml</mainComponentDesc>
<mainComponentDesc>desc/com/example/nlp/ContractRutaAnnotator.xml</mainComponentDesc>
<componentId>${project.artifactId}-${project.version}</componentId>
<datapath>$main_root/resources</datapath>
</configuration>
Expand All @@ -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,76 @@
/*
* 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 com.example.nlp;

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.ReindexUpdateMode;
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(RutaEngine.PARAM_REINDEX_UPDATE_MODE,
ReindexUpdateMode.COMPLETE.name());

// 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
@@ -0,0 +1,6 @@
PACKAGE com.example.nlp;

TYPESYSTEM de.averbis.textanalysis.typesystems.AverbisTypeSystem;

DECLARE SomeType;
Token{->SomeType};

This file was deleted.

Loading

0 comments on commit 9a904b4

Please sign in to comment.