Skip to content

Commit

Permalink
Merge pull request #11 from averbis/10-Update-archetype-for-UIMA-3-OS…
Browse files Browse the repository at this point in the history
…Gi-combination

Issue #10: Update archetype for UIMA 3 OSGi combination
  • Loading branch information
pkluegl authored Sep 28, 2021
2 parents 356dbd7 + f7743b6 commit 4d0d5be
Show file tree
Hide file tree
Showing 25 changed files with 12,659 additions and 445 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project template to bootstrap UIMA Ruta annotators and package them as a PEAR pa
There is no need to clone this repo to generate a new Ruta annotator project. Just execute the following command:

```
mvn archetype:generate -DarchetypeGroupId=de.averbis.textanalysis -DarchetypeArtifactId=ruta-pear-archetype -DarchetypeVersion=2.0.0-SNAPSHOT
mvn archetype:generate -DarchetypeGroupId=de.averbis.textanalysis -DarchetypeArtifactId=ruta-pear-archetype -DarchetypeVersion=2.0.0
```
You need to define a [groupId, artifactId and version](https://maven.apache.org/guides/mini/guide-naming-conventions.html) for your UIMA Ruta annotator project.

Expand Down Expand Up @@ -60,7 +60,14 @@ my-ruta-annotator/
├── pom.xml
└── src
├── main
│   ├── java
│   │ └── com
│   │ └── example
│   │ └── nlp
│   │ └── GenerateConfiguredDescriptorTemplate.java
│   ├── resources
│   │   ├── descriptor
│   │   │ └── GeneratedBasicEngine.xml
│   │   └── META-INF
│   │   └── org.apache.uima.fit
│   │   └── types.txt
Expand Down
9 changes: 9 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,12 @@
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory>src/test/resources</directory>
<includes>
<include>log4j2.xml</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory></directory>
<includes>
Expand Down
113 changes: 93 additions & 20 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,28 @@
<artifactId>numeric-value-typesystem</artifactId>
<version>${core-typesystems-version}</version>
</dependency>
<dependency>
<groupId>de.averbis.textanalysis</groupId>
<artifactId>named-entity-typesystem</artifactId>
<version>${core-typesystems-version}</version>
</dependency>
<dependency>
<groupId>de.averbis.textanalysis</groupId>
<artifactId>text-typesystem</artifactId>
<version>${core-typesystems-version}</version>
</dependency>
<dependency>
<groupId>de.averbis.textanalysis</groupId>
<artifactId>neural-typesystem</artifactId>
<version>${core-typesystems-version}</version>
</dependency>
<dependency>
<groupId>de.averbis.textanalysis</groupId>
<artifactId>evaluation-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 +168,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>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<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 +200,16 @@
</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.apache.uima</groupId>
Expand All @@ -183,6 +229,7 @@
<include>**/*.ruta</include>
</includes>
</scriptFiles>
<analysisEngineTemplate>${basedir}/src/main/resources/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,39 @@
<buildPaths>
</buildPaths>
</configuration>
</execution>
</execution>
</executions>
</plugin>
<!-- Generate Java classes for defined types -->
<plugin>
<groupId>org.apache.uima</groupId>
<artifactId>jcasgen-maven-plugin</artifactId>
<version>${uima-version}</version>
<executions>
<execution>
<id>generate-jcas-classes</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<typeSystemIncludes>
<typeSystemInclude>target/generated-sources/ruta/descriptor/${packageInPathFormat}/${rutaScriptName}RutaTypeSystem.xml</typeSystemInclude>
</typeSystemIncludes>
<typeSystemExcludes>
<typeSystemExclude>/**/BasicTypeSystem.xml</typeSystemExclude>
<typeSystemExclude>/**/InternalTypeSystem.xml</typeSystemExclude>
</typeSystemExcludes>
<limitToProject>true</limitToProject>
</configuration>
</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 @@ -248,6 +320,7 @@
</execution>
</executions>
</plugin>
<!-- Include dependencies in runtime scope as libraries -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -266,13 +339,13 @@
</execution>
</executions>
</plugin>
<!-- Assembles the PEAR package -->
<plugin>
<groupId>org.apache.uima</groupId>
<artifactId>PearPackagingMavenPlugin</artifactId>
<version>${uima-version}</version>
<extensions>true</extensions>
<executions>
<!-- Assembles the PEAR package -->
<execution>
<phase>package</phase>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.ReindexUpdateMode;
import org.apache.uima.ruta.engine.RutaEngine;
import org.xml.sax.SAXException;

/**
* Helper class for manually generating a preconfigured descriptor template for the generated Ruta
* analysis engine descriptors
*
*/
public class GenerateConfiguredDescriptorTemplate {

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

File outputFile = new File("src/main/resources/descriptor/GeneratedBasicEngine.xml");
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);
}
}

}
Loading

0 comments on commit 4d0d5be

Please sign in to comment.