Skip to content

Commit

Permalink
Merge pull request #11 from nlpsandbox/ymnliu-develop
Browse files Browse the repository at this point in the history
Update API to version 0.2.2
  • Loading branch information
tschaffter authored Nov 27, 2020
2 parents eb69758 + 772254c commit 8380b86
Show file tree
Hide file tree
Showing 39 changed files with 912 additions and 1,509 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ updates:
interval: "monthly"
target-branch: "develop"

- package-ecosystem: "pip"
directory: "/server"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "monthly"
target-branch: "develop"
target-branch: "develop"
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- '*.*.*'
pull_request:


env:
docker_repository: nlpsandbox/person-name-annotator-example

jobs:
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -38,7 +42,7 @@ jobs:
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=nlpsandbox/date-annotator-example-java
DOCKER_IMAGE=${{ env.docker_repository }}
VERSION=noop
PUSH=false
if [ "${{ github.event_name }}" = "schedule" ]; then
Expand Down Expand Up @@ -99,4 +103,4 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: nlpsandbox/date-annotator-example-java
repository: ${{ env.docker_repository }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.idea
venv
venv
dist.yaml
openapi.yaml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ An example implementation of the [NLP Sandbox Date Annotator] using Java Spring

## Specification

- Annotates date strings in clinical notes using simple regular expressions
- Implements the [NLP Sandbox Date Annotator OpenAPI specification]
- Annotates date strings in clinical notes using simple regular expressions

## Usage

Expand All @@ -26,7 +26,7 @@ Build and start the Date Annotator.

cd server/
mvn package
java -jar target/openapi-spring-0.1.6.jar
java -jar target/openapi-spring-0.2.2.jar

## Interactive documentation

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.8"

services:
date-annotator:
image: nlpsandbox/date-annotator-example-java:edge
image: nlpsandbox/date-annotator-example-java:latest
build:
context: server
dockerfile: Dockerfile
Expand Down
7 changes: 0 additions & 7 deletions openapitools.json

This file was deleted.

14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "date-annotator-example-java",
"version": "0.2.2",
"license": "Apache-2.0",
"devDependencies": {
"@openapitools/openapi-generator-cli": "^1.0.18-4.3.1"
},
"scripts": {
"generate:server": "openapi-generator generate -g spring -o server -i $npm_config_spec"
}
}
2 changes: 2 additions & 0 deletions server/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

Dockerfile
20 changes: 20 additions & 0 deletions server/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
README.md
pom.xml
src/main/java/org/openapitools/OpenAPI2SpringBoot.java
src/main/java/org/openapitools/RFC3339DateFormat.java
src/main/java/org/openapitools/api/ApiUtil.java
src/main/java/org/openapitools/api/ServiceApi.java
src/main/java/org/openapitools/api/ServiceApiController.java
src/main/java/org/openapitools/api/TextDateAnnotationsApi.java
src/main/java/org/openapitools/api/TextDateAnnotationsApiController.java
src/main/java/org/openapitools/configuration/HomeController.java
src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java
src/main/java/org/openapitools/model/Error.java
src/main/java/org/openapitools/model/Note.java
src/main/java/org/openapitools/model/Service.java
src/main/java/org/openapitools/model/TextAnnotation.java
src/main/java/org/openapitools/model/TextDateAnnotation.java
src/main/java/org/openapitools/model/TextDateAnnotationAllOf.java
src/main/java/org/openapitools/model/TextDateAnnotationRequest.java
src/main/java/org/openapitools/model/TextDateAnnotations.java
src/main/resources/application.properties
2 changes: 1 addition & 1 deletion server/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.1
5.0.0-beta2
17 changes: 4 additions & 13 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM python:3.8.5-slim-buster

ENV PIP_NO_CACHE_DIR=off
ENV APP_DIR=/opt/app
ENV APP_VERSION="0.1.6"
ENV APP_VERSION="0.2.2"

# Safer bash scripts with 'set -euxo pipefail'
SHELL ["/bin/bash", "-euxo", "pipefail", "-c"]
Expand All @@ -14,11 +13,8 @@ RUN mkdir -p /usr/share/man/man1
# hadolint ignore=DL3008
RUN apt-get update -qq -y \
&& apt-get install --no-install-recommends -qq -y \
build-essential \
# build-essential \
gosu \
libpcre3 \
libpcre3-dev \
# Java
default-jre \
maven \
&& apt-get -y autoclean \
Expand All @@ -27,13 +23,10 @@ RUN apt-get update -qq -y \

# Copy server files
COPY src ${APP_DIR}/src
COPY requirements.txt pom.xml app.ini ${APP_DIR}/
COPY pom.xml ${APP_DIR}/
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

# Install dependencies
RUN pip install -r ${APP_DIR}/requirements.txt

# Build app
WORKDIR ${APP_DIR}
RUN mvn package \
Expand All @@ -43,6 +36,4 @@ RUN mvn package \
EXPOSE 8080

# Set the entrypoint script and the default command run by the container
ENTRYPOINT ["java", "-jar", "target/app.jar"]
# ENTRYPOINT ["/docker-entrypoint.sh"]
# CMD ["uwsgi", "--ini", "app.ini", "--http-socket", ":8080"]
ENTRYPOINT ["java", "-jar", "target/app.jar"]
15 changes: 0 additions & 15 deletions server/app.ini

This file was deleted.

2 changes: 1 addition & 1 deletion server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

if [ "$1" = 'uwsgi' ]; then
if [ "$1" = 'java' ]; then
cd ${APP_DIR}
exec gosu www-data "$@"
fi
Expand Down
6 changes: 3 additions & 3 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<artifactId>openapi-spring</artifactId>
<packaging>jar</packaging>
<name>openapi-spring</name>
<version>0.1.6</version>
<version>0.2.2</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.8.0</springfox-version>
<springfox-version>2.9.2</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<version>2.3.3.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down
1 change: 0 additions & 1 deletion server/requirements.txt

This file was deleted.

82 changes: 82 additions & 0 deletions server/src/main/java/org/nlpsandbox/DateExtractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.nlpsandbox;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openapitools.model.TextDateAnnotation;

public class DateExtractor {

class NamedPattern{
public String name;
public Pattern pattern;

public NamedPattern(String name, Pattern pattern){
this.name = name;
this.pattern = pattern;
}
}

class Span{
int begin;
int end;
int length;

public Span(int begin, int end){
this.begin = begin;
this.end = end;
this.length = end - begin;
}
}

static List<NamedPattern> datePatterns;

public DateExtractor(){
datePatterns = new ArrayList<>();
datePatterns.add(new NamedPattern("DD/MM/YYYY",
Pattern.compile(
"\\b([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(/)([1-9]|0[1-9]|1[0-2])(/)(19[0-9][0-9]|20[0-9][0-9])")));

datePatterns.add(new NamedPattern("MM/DD/YYYY",
Pattern.compile(
"\\b([1-9]|0[1-9]|1[0-2])(/)([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(/)(19[0-9][0-9]|20[0-9][0-9])")));

datePatterns.add(new NamedPattern("MM-DD-YYYY",
Pattern.compile(
"\\b([1-9]|0[1-9]|1[0-2])(-)([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])(-)(19[0-9][0-9]|20[0-9][0-9])")));

datePatterns.add(new NamedPattern("MMMM",
Pattern.compile("\\b(January|February|March|April|May|June|" +
"July|August|September|October|November|" +
"December)")));
}

public List<TextDateAnnotation> findDatesFromString(String sentence){

List<TextDateAnnotation> annotations = new ArrayList<>();
for (NamedPattern np: datePatterns) {
// Now create matcher object.
Matcher m = np.pattern.matcher(sentence);
while (m.find()) {
annotations.add(new TextDateAnnotation()
.start(m.start(0))
.length(m.group(0).length())
.text(m.group(0))
.dateFormat(np.name)
.confidence(92.5f));
}
}
return annotations;
}

public static void main(String[] args) {
DateExtractor de = new DateExtractor();
String str1 = "Today is 10/26/2020, and yesterday is 10/25/2020. ";
de.findDatesFromString(str1);

String str2 = "Today is 26/11/2020. ";
de.findDatesFromString(str2);
}
}
32 changes: 24 additions & 8 deletions server/src/main/java/org/openapitools/RFC3339DateFormat.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
package org.openapitools;

import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
import com.fasterxml.jackson.databind.util.StdDateFormat;

import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class RFC3339DateFormat extends DateFormat {
private static final long serialVersionUID = 1L;
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");

public class RFC3339DateFormat extends ISO8601DateFormat {
private final StdDateFormat fmt = new StdDateFormat()
.withTimeZone(TIMEZONE_Z)
.withColonInTimeZone(true);

private static final long serialVersionUID = 1L;
public RFC3339DateFormat() {
this.calendar = new GregorianCalendar();
}

@Override
public Date parse(String source, ParsePosition pos) {
return fmt.parse(source, pos);
}

// Same as ISO8601DateFormat but serializing milliseconds.
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
String value = ISO8601Utils.format(date, true);
toAppendTo.append(value);
return toAppendTo;
return fmt.format(date, toAppendTo, fieldPosition);
}

@Override
public Object clone() {
return this;
}
}
Loading

0 comments on commit 8380b86

Please sign in to comment.