Skip to content

Commit

Permalink
Rename project to location annotator (#56)
Browse files Browse the repository at this point in the history
* Update package.json

* Update package-lock.json

* Run npm generate:server:edge

* Minor update

* Fix typo in README

* Bump schema and annotator version to 1.2.0
  • Loading branch information
tschaffter authored Jun 21, 2021
1 parent e362626 commit 01ee359
Show file tree
Hide file tree
Showing 23 changed files with 395 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
pull_request:

env:
docker_repository: docker.synapse.org/syn22277123/physical-address-annotator-example
docker_repository: docker.synapse.org/syn22277123/location-annotator-example

jobs:
configure:
Expand Down
2 changes: 1 addition & 1 deletion .nlpsandbox-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.2.0
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![nlpsandbox.io](https://nlpsandbox.github.io/nlpsandbox-themes/banner/[email protected])](https://nlpsandbox.io)

# NLP Sandbox Physical Address Annotator Example
# NLP Sandbox Location Annotator Example

[![GitHub Release](https://img.shields.io/github/release/nlpsandbox/physical-address-annotator-example.svg?include_prereleases&color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/physical-address-annotator-example/releases)
[![GitHub CI](https://img.shields.io/github/workflow/status/nlpsandbox/physical-address-annotator-example/CI.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/physical-address-annotator-example/actions)
[![GitHub License](https://img.shields.io/github/license/nlpsandbox/physical-address-annotator-example.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/physical-address-annotator-example/blob/develop/LICENSE)
[![GitHub Release](https://img.shields.io/github/release/nlpsandbox/location-annotator-example.svg?include_prereleases&color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/location-annotator-example/releases)
[![GitHub CI](https://img.shields.io/github/workflow/status/nlpsandbox/location-annotator-example/CI.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/location-annotator-example/actions)
[![GitHub License](https://img.shields.io/github/license/nlpsandbox/location-annotator-example.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&logo=github)](https://github.com/nlpsandbox/location-annotator-example/blob/develop/LICENSE)
[![Docker](https://img.shields.io/badge/docker-blue.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=nlpsandbox&logo=data:image/svg%2bxml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJtMy4yIDcuOS0xLjctMXYxMS40bDkuOSA1LjdWMTIuNkw1LjYgOS4zIDMuMiA3Ljl6bTE3LjEtMS4zIDEuNS0uOUwxMiAwIDIuMiA1LjdsMi42IDEuNS4xLjEgMS43IDEgNS41IDMuMiA1LjEtMyAzLjEtMS45ek0xMiA5LjUgOS4zIDcuOSA3LjQgNi44bC0xLjctMS0uMS0uMWgtLjFMMTIgMS45bDYuNSAzLjhMMTYuMyA3IDEyIDkuNXptOC44LTEuNi0yLjQgMS40LS41LjItNS4zIDMuMVYyNGw5LjktNS43VjYuOWwtMS43IDF6IiBmaWxsPSIjZmZmIi8+PC9zdmc+)](https://www.synapse.org/#!Synapse:syn25830546 "Get the Docker image of this tool on NLPSandbox.io")
[![Leaderboard](https://img.shields.io/badge/leaderboard-blue.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=nlpsandbox&logo=data:image/svg%2bxml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJtMy4yIDcuOS0xLjctMXYxMS40bDkuOSA1LjdWMTIuNkw1LjYgOS4zIDMuMiA3Ljl6bTE3LjEtMS4zIDEuNS0uOUwxMiAwIDIuMiA1LjdsMi42IDEuNS4xLjEgMS43IDEgNS41IDMuMiA1LjEtMyAzLjEtMS45ek0xMiA5LjUgOS4zIDcuOSA3LjQgNi44bC0xLjctMS0uMS0uMWgtLjFMMTIgMS45bDYuNSAzLjhMMTYuMyA3IDEyIDkuNXptOC44LTEuNi0yLjQgMS40LS41LjItNS4zIDMuMVYyNGw5LjktNS43VjYuOWwtMS43IDF6IiBmaWxsPSIjZmZmIi8+PC9zdmc+)](https://www.synapse.org/#!Synapse:syn22277123/wiki/609143 "View the performance of this tool on NLPSandbox.io")
[![Discord](https://img.shields.io/discord/770484164393828373.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=Discord&logo=discord)](https://nlpsandbox.io/discord "Realtime support / chat with the community and the team")
Expand All @@ -16,14 +16,14 @@ processing (NLP) tools on both public and private datasets. Academics, students,
and industry professionals are invited to browse the available tasks and
participate by developing and submitting an NLP Sandbox tool.

This repository provides an example implementation of the [NLP Sandbox Physical
Address Annotator API] written in Python-Flask. An NLP Sandbox physical address
annotator takes as input a clinical note (text) and outputs a list of predicted
physical address annotations found in the clinical note. Here physicall
addresses are identified using dictionaries.
This repository provides an example implementation of the [NLP Sandbox Location
Annotator API] written in Python-Flask. An NLP Sandbox location annotator takes
as input a clinical note (text) and outputs a list of predicted location
annotations found in the clinical note. Here locations are identified using
dictionaries.

This tool is provided to NLP developers who develop in Python as a starting
point to package their own physical address annotator as an NLP Sandbox tool
point to package their own location annotator as an NLP Sandbox tool
(see section [Development](#Development)). This section also describes how to
generate a tool "stub" using [openapi-generator] for 50+ programming
languages-frameworks. This repository includes a GitHub CI/CD workflow that
Expand Down Expand Up @@ -62,9 +62,9 @@ performance!

## Specification

- NLP Sandbox schemas version: 1.1.2
- NLP Sandbox tool version: 1.1.2
- Docker image: [docker.synapse.org/syn22277123/physical-address-annotator-example]
- NLP Sandbox schemas version: 1.2.0
- NLP Sandbox tool version: 1.2.0
- Docker image: [docker.synapse.org/syn22277123/location-annotator-example]


## Requirements
Expand All @@ -76,7 +76,7 @@ performance!

### Running with Docker

The command below starts this NLP Sandbox physical address annotator locally.
The command below starts this NLP Sandbox location annotator locally.

```console
docker compose up --build
Expand All @@ -89,11 +89,11 @@ You can stop the container run with `Ctrl+C`, followed by `docker compose down`.
Create a Conda environment.

```console
conda create --name physical-address-annotator python=3.9
conda activate physical-address-annotator
conda create --name location-annotator python=3.9
conda activate location-annotator
```

Install and start this NLP Sandbox physical address annotator.
Install and start this NLP Sandbox location annotator.

```console
cd server && pip install -r requirements.txt
Expand All @@ -114,10 +114,10 @@ the tool using Docker (production) or Python (development).

## Development

This section describes how to develop your own NLP Sandbox physical address
This section describes how to develop your own NLP Sandbox location
annotator in Python-Flask and other programming languages-frameworks. This
example tool is also available in Java in the GitHub repository
[nlpsandbox/physical-address-annotator-example-java].
[nlpsandbox/location-annotator-example-java].

### Development requirements

Expand Down Expand Up @@ -177,9 +177,9 @@ disabling version updates].

The development of new NLP Sandbox tools is streamlined by using the
[openapi-generator] to generate tool "stubs" for more than 50 programming
languages and frameworks. Here a physical address annotator stub refers to an
languages and frameworks. Here a location annotator stub refers to an
initial implementation that has been automatically generated by
[openapi-generator] from the [NLP Sandbox Physical Address Annotator API]
[openapi-generator] from the [NLP Sandbox Location Annotator API]
specification.

Run the command below to get the list of languages-framework supported by the
Expand All @@ -189,23 +189,23 @@ Run the command below to get the list of languages-framework supported by the
npx @openapitools/openapi-generator-cli list
```

Generate the physical address annotator stub from an empty GitHub repository
Generate the location annotator stub from an empty GitHub repository
(here in Python-Flask):

```console
mkdir server
npx @openapitools/openapi-generator-cli generate \
-g python-flask \
-o server \
-i https://nlpsandbox.github.io/nlpsandbox-schemas/physical-address-annotator/latest/openapi.json
-i https://nlpsandbox.github.io/nlpsandbox-schemas/location-annotator/latest/openapi.json
```

where the option `-i` refers to the OpenAPI specification of the [NLP Sandbox
Physical Address Annotator API].
Location Annotator API].

The URL is composed of different elements:

- `physical-address-annotator` - The type of NLP Sandbox tool to generate. The
- `location-annotator` - The type of NLP Sandbox tool to generate. The
list of all the NLP Sandbox tool types available is defined in the [NLP
Sandbox schemas].
- `latest` - The latest stable version of the [NLP Sandbox schemas]. This token
Expand Down Expand Up @@ -332,11 +332,11 @@ Thinking about contributing to this project? Get started by reading our
<!-- Links -->

[nlpsandbox.io]: https://www.synapse.org/nlpsandbox
[docker.synapse.org/syn22277123/physical-address-annotator-example]: https://www.synapse.org/#!Synapse:syn25828638
[docker.synapse.org/syn22277123/location-annotator-example]: https://www.synapse.org/#!Synapse:syn25828638
[Synapse.org]: https://synapse.org
[openapi-generator]: https://github.com/OpenAPITools/openapi-generator
[contribution guide]: .github/CONTRIBUTING.md
[Apache License 2.0]: https://github.com/nlpsandbox/physical-address-annotator-example/blob/main/LICENSE
[Apache License 2.0]: https://github.com/nlpsandbox/location-annotator-example/blob/main/LICENSE
[Docker Engine]: https://docs.docker.com/engine/install/
[Node]: https://nodejs.org/en/
[Java]: https://www.java.com/en/download/help/download_options.html
Expand All @@ -352,9 +352,9 @@ Thinking about contributing to this project? Get started by reading our
[Enabling and disabling version updates]: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/enabling-and-disabling-version-updates
[NLP Sandbox schemas]: https://github.com/nlpsandbox/nlpsandbox-schemas
[nlpsandbox/nlpsandbox-schemas]: https://github.com/nlpsandbox/nlpsandbox-schemas
[NLP Sandbox Physical Address Annotator API]: https://nlpsandbox.github.io/nlpsandbox-schemas/physical-address-annotator/latest/docs/
[this GitHub template]: https://github.com/nlpsandbox/physical-address-annotator-example/generate
[nlpsandbox/physical-address-annotator-example-java]: https://github.com/nlpsandbox/physical-address-annotator-example-java
[NLP Sandbox Location Annotator API]: https://nlpsandbox.github.io/nlpsandbox-schemas/location-annotator/latest/docs/
[this GitHub template]: https://github.com/nlpsandbox/location-annotator-example/generate
[nlpsandbox/location-annotator-example-java]: https://github.com/nlpsandbox/location-annotator-example-java
[Patient schema]: https://github.com/nlpsandbox/nlpsandbox-schemas/blob/develop/openapi/commons/components/schemas/Patient.yaml
[semantic versioning]: https://semver.org/
[NLP Sandbox schemas CHANGELOG]: .github/CHANGELOG.md
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
version: "3.8"

services:
physical-address-annotator:
image: docker.synapse.org/syn22277123/physical-address-annotator-example:1.1.2
location-annotator:
image: docker.synapse.org/syn22277123/location-annotator-example:1.2.0
build:
context: server
dockerfile: Dockerfile
container_name: physical-address-annotator
container_name: location-annotator
networks:
- nlpsandbox-internal

nginx:
image: nginx:1.19.6-alpine
container_name: physical-address-annotator-nginx
container_name: location-annotator-nginx
restart: always
environment:
- TOOL_HOST=physical-address-annotator
- TOOL_HOST=location-annotator
- TOOL_PORT=8080
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
Expand All @@ -26,7 +26,7 @@ services:
ports:
- "80:80"
depends_on:
- physical-address-annotator
- location-annotator

networks:
nlpsandbox:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
},
"scripts": {
"generate:server": "openapi-generator-cli generate -g python-flask -o server -i $npm_config_specification",
"generate:server:latest": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/physical-address-annotator/latest/openapi.json",
"generate:server:edge": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/physical-address-annotator/edge/openapi.json",
"generate:server:latest": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/location-annotator/latest/openapi.json",
"generate:server:edge": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/location-annotator/edge/openapi.json",
"lint": "cd server && flake8",
"test": "cd server && tox",
"install:dependencies": "npm ci && cd server && pip install -r requirements.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import re

from openapi_server.models.error import Error # noqa: E501
from openapi_server.models.text_physical_address_annotation_request import TextPhysicalAddressAnnotationRequest # noqa: E501
from openapi_server.models.text_physical_address_annotation import TextPhysicalAddressAnnotation # noqa: E501
from openapi_server.models.text_physical_address_annotation_response import TextPhysicalAddressAnnotationResponse # noqa: E501
from openapi_server.models.text_location_annotation import TextLocationAnnotation # noqa: E501
from openapi_server.models.text_location_annotation_request import TextLocationAnnotationRequest # noqa: E501
from openapi_server.models.text_location_annotation_response import TextLocationAnnotationResponse # noqa: E501


class Data:
Expand All @@ -29,18 +29,21 @@ def __init__(self):
data = Data()


def create_text_physical_address_annotations(): # noqa: E501
"""Annotate physical addresses in a clinical note
def create_text_location_annotations(): # noqa: E501
"""Annotate locations in a clinical note
Return the physical addresse annotations found in a clinical note # noqa: E501
Return the location annotations found in a clinical note # noqa: E501
:rtype: TextPhysicalAddressAnnotationResponse
:param text_location_annotation_request:
:type text_location_annotation_request: dict | bytes
:rtype: TextLocationAnnotationResponse
"""
res = None
status = None
if connexion.request.is_json:
try:
annotation_request = TextPhysicalAddressAnnotationRequest.from_dict(connexion.request.get_json()) # noqa: E501
annotation_request = TextLocationAnnotationRequest.from_dict(connexion.request.get_json()) # noqa: E501
note = annotation_request._note
annotations = []

Expand Down Expand Up @@ -70,25 +73,25 @@ def create_text_physical_address_annotations(): # noqa: E501
r'\b({})\b'.format(other), note._text, re.IGNORECASE)
add_annotations(annotations, matches, 'other')

res = TextPhysicalAddressAnnotationResponse(annotations)
res = TextLocationAnnotationResponse(annotations)
status = 200
except Exception as error:
status = 500
res = Error("Internal error", status, str(error))
return res, status


def add_annotations(annotations, matches, address_type):
def add_annotations(annotations, matches, location_type):
"""
Converts matches to TextPhysicalAddressAnnotation objects and adds them
Converts matches to TextLocationAnnotation objects and adds them
to the annotations array specified.
"""
for match in matches:
annotations.append(
TextPhysicalAddressAnnotation(
TextLocationAnnotation(
start=match.start(),
length=len(match[0]),
text=match[0],
address_type=address_type,
location_type=location_type,
confidence=95.5
))
17 changes: 9 additions & 8 deletions server/openapi_server/controllers/tool_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from openapi_server.models.tool import Tool # noqa: E501
from openapi_server.models.tool_dependencies import ToolDependencies # noqa: E501
from openapi_server.models.tool_type import ToolType
from openapi_server.models.license import License


Expand All @@ -12,17 +13,17 @@ def get_tool(): # noqa: E501
:rtype: Tool
"""
tool = Tool(
name="physical-address-annotator-example",
version="1.1.2",
name="location-annotator-example",
version="1.2.0",
license=License.APACHE_2_0,
repository="github:nlpsandbox/physical-address-annotator-example",
description="Example implementation of the NLP Sandbox Physical " +
"Address Annotator",
repository="github:nlpsandbox/location-annotator-example",
description="Example implementation of the NLP Sandbox Location " +
"Annotator API",
author="NLP Sandbox Team",
author_email="[email protected]",
url="https://github.com/nlpsandbox/physical-address-annotator-example",
type="nlpsandbox:physical-address-annotator",
api_version="1.1.2"
url="https://github.com/nlpsandbox/location-annotator-example",
type=ToolType.LOCATION_ANNOTATOR,
api_version="1.2.0"
)
return tool, 200

Expand Down
9 changes: 5 additions & 4 deletions server/openapi_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from openapi_server.models.license import License
from openapi_server.models.note import Note
from openapi_server.models.text_annotation import TextAnnotation
from openapi_server.models.text_physical_address_annotation import TextPhysicalAddressAnnotation
from openapi_server.models.text_physical_address_annotation_all_of import TextPhysicalAddressAnnotationAllOf
from openapi_server.models.text_physical_address_annotation_request import TextPhysicalAddressAnnotationRequest
from openapi_server.models.text_physical_address_annotation_response import TextPhysicalAddressAnnotationResponse
from openapi_server.models.text_location_annotation import TextLocationAnnotation
from openapi_server.models.text_location_annotation_all_of import TextLocationAnnotationAllOf
from openapi_server.models.text_location_annotation_request import TextLocationAnnotationRequest
from openapi_server.models.text_location_annotation_response import TextLocationAnnotationResponse
from openapi_server.models.tool import Tool
from openapi_server.models.tool_dependencies import ToolDependencies
from openapi_server.models.tool_type import ToolType
Loading

0 comments on commit 01ee359

Please sign in to comment.