diff --git a/.nlpsandbox-version b/.nlpsandbox-version index 45a1b3f..26aaba0 100644 --- a/.nlpsandbox-version +++ b/.nlpsandbox-version @@ -1 +1 @@ -1.1.2 +1.2.0 diff --git a/README.md b/README.md index 565f7ad..05085df 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ performance -- just don't expect a high performance! ## Specification -- NLP Sandbox schemas version: 1.1.2 -- NLP Sandbox tool version: 1.1.2 +- NLP Sandbox schemas version: 1.2.0 +- NLP Sandbox tool version: 1.2.0 - Docker image: [docker.synapse.org/syn22277123/id-annotator-example] diff --git a/docker-compose.yml b/docker-compose.yml index 21217a5..9e5035d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.8" services: id-annotator: - image: docker.synapse.org/syn22277123/id-annotator-example:1.1.2 + image: docker.synapse.org/syn22277123/id-annotator-example:1.2.0 build: context: server dockerfile: Dockerfile diff --git a/package.json b/package.json index 82b2a35..5139a21 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ }, "private": true, "scripts": { - "generate:server": "openapi-generator-cli generate -g python-flask -o server -i $npm_config_specification", + "generate:server": "openapi-generator-cli generate -g python-flask -o server -i $npm_config_openapi", "generate:server:latest": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/id-annotator/latest/openapi.json", "generate:server:edge": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/id-annotator/edge/openapi.json", + "generate:server:version": "openapi-generator-cli generate -g python-flask -o server -i https://nlpsandbox.github.io/nlpsandbox-schemas/id-annotator/$npm_config_schemas_version/openapi.json", "lint": "cd server && flake8", "test": "cd server && tox", "install:dependencies": "npm ci && cd server && pip install -r requirements.txt", diff --git a/server/openapi_server/controllers/tool_controller.py b/server/openapi_server/controllers/tool_controller.py index 03ae2e8..18b2b31 100644 --- a/server/openapi_server/controllers/tool_controller.py +++ b/server/openapi_server/controllers/tool_controller.py @@ -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 @@ -13,15 +14,16 @@ def get_tool(): # noqa: E501 """ tool = Tool( name="id-annotator-example", - version="1.1.2", + version="1.2.0", license=License.APACHE_2_0, repository="github:nlpsandbox/id-annotator-example", - description="Example implementation of the NLP Sandbox ID Annotator", + description="Example implementation of the NLP Sandbox ID Annotator " + + " API", author="NLP Sandbox Team", author_email="team@nlpsandbox.io", url="https://github.com/nlpsandbox/id-annotator-example", - type="nlpsandbox:id-annotator", - api_version="1.1.2" + type=ToolType.ID_ANNOTATOR, + api_version="1.2.0" ) return tool, 200 diff --git a/server/openapi_server/models/__init__.py b/server/openapi_server/models/__init__.py index ce6915e..1afcad1 100644 --- a/server/openapi_server/models/__init__.py +++ b/server/openapi_server/models/__init__.py @@ -14,3 +14,4 @@ from openapi_server.models.text_id_annotation_response import TextIdAnnotationResponse from openapi_server.models.tool import Tool from openapi_server.models.tool_dependencies import ToolDependencies +from openapi_server.models.tool_type import ToolType diff --git a/server/openapi_server/models/tool.py b/server/openapi_server/models/tool.py index 15a4628..ed54381 100644 --- a/server/openapi_server/models/tool.py +++ b/server/openapi_server/models/tool.py @@ -7,10 +7,12 @@ from openapi_server.models.base_model_ import Model from openapi_server.models.license import License +from openapi_server.models.tool_type import ToolType import re from openapi_server import util from openapi_server.models.license import License # noqa: E501 +from openapi_server.models.tool_type import ToolType # noqa: E501 import re # noqa: E501 class Tool(Model): @@ -39,7 +41,7 @@ def __init__(self, name=None, version=None, license=None, repository=None, descr :param url: The url of this Tool. # noqa: E501 :type url: str :param type: The type of this Tool. # noqa: E501 - :type type: str + :type type: ToolType :param api_version: The api_version of this Tool. # noqa: E501 :type api_version: str """ @@ -52,7 +54,7 @@ def __init__(self, name=None, version=None, license=None, repository=None, descr 'author': str, 'author_email': str, 'url': str, - 'type': str, + 'type': ToolType, 'api_version': str } @@ -221,8 +223,8 @@ def description(self, description): """ if description is None: raise ValueError("Invalid value for `description`, must not be `None`") # noqa: E501 - if description is not None and len(description) > 100: - raise ValueError("Invalid value for `description`, length must be less than or equal to `100`") # noqa: E501 + if description is not None and len(description) > 280: + raise ValueError("Invalid value for `description`, length must be less than or equal to `280`") # noqa: E501 self._description = description @@ -305,10 +307,9 @@ def url(self, url): def type(self): """Gets the type of this Tool. - The type of this tool # noqa: E501 :return: The type of this Tool. - :rtype: str + :rtype: ToolType """ return self._type @@ -316,19 +317,12 @@ def type(self): def type(self, type): """Sets the type of this Tool. - The type of this tool # noqa: E501 :param type: The type of this Tool. - :type type: str + :type type: ToolType """ if type is None: raise ValueError("Invalid value for `type`, must not be `None`") # noqa: E501 - if type is not None and len(type) > 60: - raise ValueError("Invalid value for `type`, length must be less than or equal to `60`") # noqa: E501 - if type is not None and len(type) < 3: - raise ValueError("Invalid value for `type`, length must be greater than or equal to `3`") # noqa: E501 - if type is not None and not re.search(r'^[a-z0-9]+(?:-[a-z0-9]+)*(:)[a-z0-9]+(?:-[a-z0-9]+)*$', type): # noqa: E501 - raise ValueError("Invalid value for `type`, must be a follow pattern or equal to `/^[a-z0-9]+(?:-[a-z0-9]+)*(:)[a-z0-9]+(?:-[a-z0-9]+)*$/`") # noqa: E501 self._type = type diff --git a/server/openapi_server/models/tool_type.py b/server/openapi_server/models/tool_type.py new file mode 100644 index 0000000..f1f2a31 --- /dev/null +++ b/server/openapi_server/models/tool_type.py @@ -0,0 +1,49 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class ToolType(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + CONTACT_ANNOTATOR = "nlpsandbox:contact-annotator" + COVID_SYMPTOM_ANNOTATOR = "nlpsandbox:covid-symptom-annotator" + DATA_NODE = "nlpsandbox:data-node" + DATE_ANNOTATOR = "nlpsandbox:date-annotator" + ID_ANNOTATOR = "nlpsandbox:id-annotator" + LOCATION_ANNOTATOR = "nlpsandbox:location-annotator" + PERSON_NAME_ANNOTATOR = "nlpsandbox:person-name-annotator" + PHI_ANNOTATOR = "nlpsandbox:phi-annotator" + PHI_DEIDENTIFIER = "nlpsandbox:phi-deidentifier" + def __init__(self): # noqa: E501 + """ToolType - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'ToolType': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ToolType of this ToolType. # noqa: E501 + :rtype: ToolType + """ + return util.deserialize_model(dikt, cls) diff --git a/server/openapi_server/openapi/openapi.yaml b/server/openapi_server/openapi/openapi.yaml index 7967060..0bb10ff 100644 --- a/server/openapi_server/openapi/openapi.yaml +++ b/server/openapi_server/openapi/openapi.yaml @@ -6,13 +6,13 @@ info: url: https://nlpsandbox.io description: | # Introduction - An ID Annotator takes as input a clinical note and outputs a list of predicted ID annotations found in the clinical note. This OpenAPI document describes the specification of a ID Annotator. This specification includes the schemas of the input and output data, and the conditions that this annotator must meet if you want to benchmark its performance on [nlpsandbox.io](https://nlpsandbox.io). + An ID annotator takes as input a clinical note and outputs a list of predicted ID annotations found in the clinical note. This OpenAPI document describes the specification of the NLP Sandbox ID Annotator API. This specification includes the schemas of the input and output data, and the requirements that this annotator must meet if you want to benchmark its performance on [nlpsandbox.io](https://nlpsandbox.io). # Getting Started - The GitHub repository (will be added later) [nlpsandbox/id-annotator-example](https://github.com/nlpsandbox/id-annotator-example) provides a simple example implementation of a Python-Flask ID Annotator. By the end of the tutorial available in the README, you will have built a Docker image for a simple ID Annotator. You will then be able to submit this image to [nlpsandbox.io](https://nlpsandbox.io) to benchmark its performance. + The GitHub repository [nlpsandbox/id-annotator-example](https://github.com/nlpsandbox/id-annotator-example) provides an example implementation of the NLP Sandbox ID Annotator API in Python-Flask. By the end of the tutorial available in the README, you will have built a Docker image for this NLP Sandbox tool. You will then be able to submit this image to [nlpsandbox.io](https://nlpsandbox.io) to benchmark its performance. # Benchmarking Requirements - Your NLP Sandbox tool must meet the following conditions before evaluating its performance on [nlpsandbox.io](https://nlpsandbox.io). + Your NLP Sandbox tool must meet the following requirements before evaluating its performance on [nlpsandbox.io](https://nlpsandbox.io). - The endpoint `/` must redirect to `/api/v1/tool`. - - The endpoint `/ui` must redirect to the web interface (UI). + - The endpoint `/ui` must redirect to the Swagger User Interface (UI). - The output of this tool must be reproducible: a given input should always generate the same output. @@ -22,14 +22,14 @@ info: connect to remote servers. # Examples - - [ID Annotator Example (Python)](https://github.com/nlpsandbox/id-annotator-example) + - [NLP Sandbox ID Annotator Example (Python)](https://github.com/nlpsandbox/id-annotator-example) license: name: Apache 2.0 - url: https://github.com/nlpsandbox/nlpsandbox-schemas/blob/develop/LICENSE + url: https://github.com/nlpsandbox/nlpsandbox-schemas/blob/main/LICENSE title: NLP Sandbox ID Annotator API - version: 1.1.2 + version: 1.2.0 x-logo: - url: https://nlpsandbox.github.io/nlpsandbox-schemas/logo.png + url: https://github.com/nlpsandbox/nlpsandbox-schemas/raw/main/docs/logo.png servers: - url: http://example.com/api/v1 - url: https://example.com/api/v1 @@ -395,10 +395,18 @@ components: type: string ToolType: description: The type of this tool + enum: + - nlpsandbox:contact-annotator + - nlpsandbox:covid-symptom-annotator + - nlpsandbox:data-node + - nlpsandbox:date-annotator + - nlpsandbox:id-annotator + - nlpsandbox:location-annotator + - nlpsandbox:person-name-annotator + - nlpsandbox:phi-annotator + - nlpsandbox:phi-deidentifier example: nlpsandbox:date-annotator - maxLength: 60 - minLength: 3 - pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*(:)[a-z0-9]+(?:-[a-z0-9]+)*$ + title: ToolType type: string Tool: description: Information about an NLP tool @@ -412,7 +420,7 @@ components: authorEmail: author@example.com url: https://example.com type: nlpsandbox:date-annotator - apiVersion: 1.1.2 + apiVersion: 1.2.0 properties: name: description: The tool name @@ -432,7 +440,7 @@ components: type: string description: description: A short, one-sentence summary of the tool - maxLength: 100 + maxLength: 280 type: string author: description: The author of the tool @@ -446,12 +454,7 @@ components: format: uri type: string type: - description: The type of this tool - example: nlpsandbox:date-annotator - maxLength: 60 - minLength: 3 - pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*(:)[a-z0-9]+(?:-[a-z0-9]+)*$ - type: string + $ref: '#/components/schemas/ToolType' apiVersion: description: The version of the tool OpenAPI specification minLength: 1 @@ -483,7 +486,7 @@ components: authorEmail: author@example.com url: https://example.com type: nlpsandbox:date-annotator - apiVersion: 1.1.2 + apiVersion: 1.2.0 - name: awesome-nlp-tool version: 1.0.6 license: apache-2.0 @@ -493,7 +496,7 @@ components: authorEmail: author@example.com url: https://example.com type: nlpsandbox:date-annotator - apiVersion: 1.1.2 + apiVersion: 1.2.0 properties: tools: description: A list of tools