From 17bcdd8e2de86a0d8dc8e4cde262b73610d01040 Mon Sep 17 00:00:00 2001 From: Javier Luna Molina Date: Fri, 13 Sep 2019 09:15:46 +0200 Subject: [PATCH 1/3] Add documentation (#7) * Add mkdocs dependency * Add index, project api and quickstart docs * Add format parameter to pycaprio * Add rest of documentation * Add format list to documentation * Add rtfd badge to README * Corrected some things. Thx Gonzalo! :) * Add @dswah's corrections * Add doc link to README --- Makefile | 14 +++- README.md | 7 +- docs/api/annotations.md | 55 ++++++++++++ docs/api/documents.md | 54 ++++++++++++ docs/api/formats.md | 25 ++++++ docs/api/projects.md | 70 ++++++++++++++++ docs/api/quickstart.md | 29 +++++++ docs/index.md | 28 +++++++ docs/license.md | 27 ++++++ docs/tests.md | 22 +++++ mkdocs.yml | 13 +++ poetry.lock | 111 +++++++++++++++++++++---- pycaprio/core/adapters/http_adapter.py | 22 ++--- pycaprio/core/interfaces/adapter.py | 2 +- pyproject.toml | 3 +- 15 files changed, 450 insertions(+), 32 deletions(-) create mode 100644 docs/api/annotations.md create mode 100644 docs/api/documents.md create mode 100644 docs/api/formats.md create mode 100644 docs/api/projects.md create mode 100644 docs/api/quickstart.md create mode 100644 docs/index.md create mode 100644 docs/license.md create mode 100644 docs/tests.md create mode 100644 mkdocs.yml diff --git a/Makefile b/Makefile index e2b2c00..9ed08b1 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,28 @@ +.PHONY: docs tests + +# Dependencies dependencies: poetry install +# Tests unit-tests: - poetry run py.test tests/unit_tests + poetry run py.test --cov=pycaprio --cov-branch --cov-fail-under=90 tests/unit_tests + +tests: unit-tests coverage: poetry run py.test --cov=pycaprio --cov-branch --cov-fail-under=90 --cov-report=html tests +# Static analysis/linting lint: poetry run flake8 pycaprio --max-line-length=120 poetry run flake8 tests --max-line-length=120 --ignore=E722 +# Docs +docs: + mkdocs serve + +# Building and publishing build: unit-tests lint poetry build diff --git a/README.md b/README.md index 0bdab6b..7c4a478 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PyCaprio -![Python versions](https://img.shields.io/badge/Python-3.6%2C%203.7-green.svg) [![PyPI version](https://badge.fury.io/py/pycaprio.svg)](https://badge.fury.io/py/pycaprio) [![CircleCI](https://circleci.com/gh/Savanamed/pycaprio.svg?style=svg)](https://circleci.com/gh/Savanamed/pycaprio) [![codecov](https://codecov.io/gh/Savanamed/Pycaprio/branch/master/graph/badge.svg)](https://codecov.io/gh/Savanamed/Pycaprio) +![Python versions](https://img.shields.io/badge/Python-3.6%2C%203.7-green.svg) [![PyPI version](https://badge.fury.io/py/pycaprio.svg)](https://badge.fury.io/py/pycaprio) [![Documentation Status](https://readthedocs.org/projects/pycaprio/badge/?version=latest)](https://pycaprio.readthedocs.io/en/latest/?badge=latest) [![CircleCI](https://circleci.com/gh/Savanamed/pycaprio.svg?style=svg)](https://circleci.com/gh/Savanamed/pycaprio) [![codecov](https://codecov.io/gh/Savanamed/Pycaprio/branch/master/graph/badge.svg)](https://codecov.io/gh/Savanamed/Pycaprio) -Python client to the [INCEpTION](https://github.com/inception-project/inception) annotation tool. +Python client for the [INCEpTION](https://github.com/inception-project/inception) annotation tool. ## Installation Pycaprio is on PyPi, you can install it via `pip`, `pipenv`, `poetry` or your favourite dependency management tool: @@ -24,8 +24,7 @@ pycaprio_client = Pycaprio("http://inception-host.com", ('username', 'password') pycaprio_client.api.create_project("Project name", "creator-username") ``` -And so on. -Although Pycaprio's API is simple and usable, proper documentation will roll in a few days. +Check the [documentation](https://pycaprio.readthedocs.io) if you want to know more. ## License Pycaprio is under the MIT license. Check it out [here](https://opensource.org/licenses/MIT) diff --git a/docs/api/annotations.md b/docs/api/annotations.md new file mode 100644 index 0000000..69955df --- /dev/null +++ b/docs/api/annotations.md @@ -0,0 +1,55 @@ +## The Annotation object + +Pycaprio uses the `Annotation` object to model INCEpTION's documents, and has the following properties: + +* `project_id`: Id of the project in which the annotated document is located (integer). +* `document_id`: Id of the annotated document (integer). +* `user_name`: Annotator's username (string). +* `annotation_state`: State in which the annotation is in (string, possible values in `pycaprio.core.mappings.AnnotationStatus`). +* `timestamp`: Annotation's creation date. + + +### List annotations +Lists all the annotations in an INCEpTION's document. + +Example: +```python +annotations = client.api.annotations(1, 4) # Annotations in document #4 in project #1 +print(annotations) # [, ] +``` + +### Download annotation +Downloads a document's annotation content. +You can specify the annotation's format via `annotation_format` (defaults to `webanno`). + +Example: + +```python +from pycaprio.core.mappings import DocumentFormats +annotation_content = client.api.annotation(1, 4, 'test-user', annotation_format=DocumentFormats.WEBANNO) # Downloads test-user's annotations on document 4 on project 1 + +with open("downloaded_annotation", 'wb') as annotation_file: + annotation_file.write(annotation_content) +``` + +### Upload annotation +Uploads an annotation to a document in INCEpTION. It requires the Id of the project, the Id of the document, the annotator's username and the annotation's content (io stream). +You can specify the annotation's format via `annotation_format` (defaults to `webanno`) and its state via `annotation_state` (defaults to `NEW`). + +Example: + +```python +from pycaprio.core.mappings import DocumentFormats, AnnotationStatus +with open("annotation") as annotation_file: + new_annotation = client.api.create_annotation(1, 4, 'leonardo-dicaprio', annotation_format=DocumentFormats.WEBANNO, annotation_state=AnnotationStatus.ANNOTATION_IN_PROGRESS) +print(new_annotation) # +``` + +### Delete annotation +Deletes a document from a project. + +Example: + +```python +client.api.delete_annotation(1, 4, 'leonardo-dicaprio') # Deletes annotation made by leonardo-dicaprio on document #4 from project #1 +``` diff --git a/docs/api/documents.md b/docs/api/documents.md new file mode 100644 index 0000000..cb92814 --- /dev/null +++ b/docs/api/documents.md @@ -0,0 +1,54 @@ +## The Document object + +Pycaprio uses the `Document` object to model INCEpTION's documents, and has the following properties: + +* `project_id`: Id of the project in which the document is located (integer). +* `document_id`: Id of the document (integer). +* `document_name`: Name of the document (string). +* `document_state`: State in which the document is in (string, possible values in `pycaprio.core.mappings.DocumentStatus`). + +### List documents +Lists all the documents in a project that are in INCEpTION. + +Example: +```python +documents = client.api.documents(1) # In project #1 +print(documents) # [, ] +``` + +### Download document +Downloads a document's content. +You can specify the annotation's format via `document_format` (defaults to `webanno`). + +Example: + +```python +from pycaprio.core.mappings import DocumentFormats +document_content = client.api.document(1, 4, document_format=DocumentFormats.WEBANNO) # Downloads document 4 from project 1 + +with open("downloaded_document", 'wb') as document_file: + document_file.write(document_content) +``` + +### Upload document +Uploads a document to a project in INCEpTION. It requires the Id of the project, the name of the document and the content of it (io stream). +You can specify the document's format via `document_format` (defaults to `webanno`). +You can specify the document's state via `document_state` (defaults to `NEW`). + +Example: + +```python +from pycaprio.core.mappings import DocumentFormats, DocumentStatus +with open("document") as document_file: + new_document = client.api.create_document(1, "Test document name", document_file, document_format=DocumentFormats.WEBANNO, document_state=DocumentStatus.IN_PROGRESS) +print(new_document) # +``` + +### Delete document +Deletes a document from a project. + +Example: + +```python +client.api.delete_document(1, 4) # Deletes document #4 from project #1 +``` diff --git a/docs/api/formats.md b/docs/api/formats.md new file mode 100644 index 0000000..fbb7ed6 --- /dev/null +++ b/docs/api/formats.md @@ -0,0 +1,25 @@ +# List of formats + +Documents, annotations and exports can be downloaded/created in different formats. + +INCEpTION doesn't specify in their documentation which formats are supported, but the following have been found and included in `pycaprio`: + +* `webanno`: Webanno. This is the default format INCEpTION uses +* `nif`: NIF +* `lif`: LIF +* `dkpro-core-tei`: TEI +* `perseus_2.1`: Perseus +* `conllu`: Conllu +* `text`: Plain text +* `json`: Json +* `xmi`: XMI + +You can find a class with all the formats in `pycaprio.core.mappings.DocumentFormats`: + +```python +from pycaprio.core.mappings import DocumentFormats + +DocumentFormats.DEFAULT +DocumentFormats.TEI +... +``` diff --git a/docs/api/projects.md b/docs/api/projects.md new file mode 100644 index 0000000..8b50663 --- /dev/null +++ b/docs/api/projects.md @@ -0,0 +1,70 @@ +## The Project object + +Pycaprio uses the `Project` object to model INCEpTION's projects, and has these properties: + +* `project_id`: Id of the project (integer). +* `project_name`: Project name (string). + + +### List projects +Lists all the projects that are in INCEpTION. + +Example: +```python +projects = client.api.projects() +print(projects) # [, ] +``` + +### Fetch project +Fetches a project by its `project_id`. + +Example: + +```python +project = client.api.project(1) +print(project) # +``` + +### Create project +Creates a project in INCEpTION. It requires the project's name and optionally the creator's username. +If no `creator_name` is provided, pycaprio will use the one of the user that is currently logged in to the API. + +Example: + +```python +new_project = client.api.create_project("New project name", creator_name="other user") +print(new_project) # +``` + +### Delete project +Deletes a project. + +Example: + +```python +client.api.delete_project(3) +``` + +### Export project +Exports a project into a zip. Pycaprio returns the zip's content in bytes to allow flexibility in use/storage. +You can specify the export file format using the `format` parameter. By default, it uses the `webanno` format. + +Example: + +```python +from pycaprio.core.mappings import DocumentFormats +content = client.api.export_project(1, format=DocumentFormats.XMI) # type(content) is bytes +with open("exported_project.zip", 'wb') as zip_file: + zip_file.write(content) +``` + +### Import project +Imports a project given a zip file's content. + +Example: + +```python +with open("exported_project.zip", 'rb') as zip_file: + project = client.api.import_project(zip_file) +print(project) # +``` diff --git a/docs/api/quickstart.md b/docs/api/quickstart.md new file mode 100644 index 0000000..354a8f6 --- /dev/null +++ b/docs/api/quickstart.md @@ -0,0 +1,29 @@ +## Requirements +For `pycaprio` to be able to access the API, you will need the API to be activated and have a user with +the `ROLE_REMOTE` role assigned. You can find more information on how to achieve this [here](https://inception-project.github.io//releases/0.11.2/docs/admin-guide.html#sect_remote_api). + +## Creating the pycaprio client + +The `pycaprio` client requires the inception host and the username and password of the remote user you want to use. + + +You can specify this information either by using environment variables or by explicitly passing the values to the client as arguments: + +### Environment variables (preferred way) +``` +export INCEPTION_HOST=http://your-inception-host.com +export INCEPTION_USERNAME=remote-user +export INCEPTION_PASSWORD=password +``` +And then in your python code: + +```python +from pycaprio import Pycaprio +client = Pycaprio() +``` + +### Passing the values as parameters +```python +from pycaprio import Pycaprio +client = Pycaprio("http://your-inception-host.com", authentication=("remote-user", "password")) +``` diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..944ca6f --- /dev/null +++ b/docs/index.md @@ -0,0 +1,28 @@ +# Pycaprio + +Python client for the [INCEpTION](https://github.com/inception-project/inception) annotation tool. + +At the moment, it serves as an API wrapper, supporting the AERO format INCEpTION serves. + +## Installation +Pycaprio is hosted in [PyPi](https://pypi.org/project/pycaprio/) and can be installed via `pip`: +``` +pip install pycaprio +``` + +## Basic usage +First, you must instantiate a `pycaprio` client: +```python +from pycaprio import Pycaprio +client = Pycaprio("http://your-inception-host.com", authentication=("remote-user", "password")) + +# List projects +projects = client.api.projects() + +# Export all projects in XMI format +from pycaprio.core.mappings import DocumentFormats +for project in projects: + zip_content = client.api.export_project(project.project_id, format=DocumentFormats.XMI) + with open(f"{project.project_name}.zip", 'wb') as zip_file: + zip_file.write(zip_content) +``` diff --git a/docs/license.md b/docs/license.md new file mode 100644 index 0000000..be20227 --- /dev/null +++ b/docs/license.md @@ -0,0 +1,27 @@ +# MIT License + +`pycaprio` is under the MIT License. + +You can read more about it [here](https://tldrlegal.com/license/mit-license). + +```text +Copyright (c) 2019 Savanamed + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/docs/tests.md b/docs/tests.md new file mode 100644 index 0000000..246f45f --- /dev/null +++ b/docs/tests.md @@ -0,0 +1,22 @@ +# Running the tests + +To be able to run the tests you must execute from your already cloned repo's root: +``` +make tests +``` + +### Quality Assurance + +The following quality checks are in place: + +* 90% branch coverage +* `pycaprio` passes flake8 +* Tests also pass flake8 + +Current coverage is [![codecov](https://codecov.io/gh/Savanamed/Pycaprio/branch/master/graph/badge.svg)](https://codecov.io/gh/Savanamed/Pycaprio) + +### Warning +Integration tests are being developed to test INCEpTION's API and will be integrated into pycaprio when considered ready, +at the moment there are only unit tests. + + diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..7dcfe90 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,13 @@ +site_name: Pycaprio +site_description: Python client to the INCEpTION annotation tool. +nav: + - Home: 'index.md' + - Api: + - Quickstart: 'api/quickstart.md' + - Projects: 'api/projects.md' + - Documents: 'api/documents.md' + - Annotations: 'api/annotations.md' + - Formats: 'api/formats.md' + - Tests: 'tests.md' + - License: 'license.md' +theme: readthedocs diff --git a/poetry.lock b/poetry.lock index 06824a9..d9d6fc1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -7,7 +7,7 @@ python-versions = "*" version = "1.4.3" [[package]] -category = "main" +category = "dev" description = "Atomic file writes." name = "atomicwrites" optional = false @@ -15,7 +15,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "1.3.0" [[package]] -category = "main" +category = "dev" description = "Classes Without Boilerplate" name = "attrs" optional = false @@ -61,7 +61,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "7.0" [[package]] -category = "main" +category = "dev" description = "Cross-platform colored terminal text." marker = "sys_platform == \"win32\"" name = "colorama" @@ -70,7 +70,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "0.4.1" [[package]] -category = "main" +category = "dev" description = "Code coverage measurement for Python" name = "coverage" optional = false @@ -108,7 +108,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.8" [[package]] -category = "main" +category = "dev" description = "Read metadata from Python packages" name = "importlib-metadata" optional = false @@ -118,6 +118,48 @@ version = "0.19" [package.dependencies] zipp = ">=0.5" +[[package]] +category = "dev" +description = "A small but fast and easy to use stand-alone template engine written in pure python." +name = "jinja2" +optional = false +python-versions = "*" +version = "2.10.1" + +[package.dependencies] +MarkupSafe = ">=0.23" + +[[package]] +category = "dev" +description = "Python LiveReload is an awesome tool for web developers" +name = "livereload" +optional = false +python-versions = "*" +version = "2.6.1" + +[package.dependencies] +six = "*" +tornado = "*" + +[[package]] +category = "dev" +description = "Python implementation of Markdown." +name = "markdown" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" +version = "3.1.1" + +[package.dependencies] +setuptools = ">=36" + +[[package]] +category = "dev" +description = "Safely add untrusted strings to HTML/XML markup." +name = "markupsafe" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" +version = "1.1.1" + [[package]] category = "dev" description = "McCabe checker, plugin for flake8" @@ -127,7 +169,23 @@ python-versions = "*" version = "0.6.1" [[package]] -category = "main" +category = "dev" +description = "Project documentation with Markdown." +name = "mkdocs" +optional = false +python-versions = ">=2.7.9,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" +version = "1.0.4" + +[package.dependencies] +Jinja2 = ">=2.7.1" +Markdown = ">=2.3.1" +PyYAML = ">=3.10" +click = ">=3.3" +livereload = ">=2.5.1" +tornado = ">=5.0" + +[[package]] +category = "dev" description = "More routines for operating on iterables, beyond itertools" name = "more-itertools" optional = false @@ -135,7 +193,7 @@ python-versions = ">=3.4" version = "7.2.0" [[package]] -category = "main" +category = "dev" description = "Core utilities for Python packages" name = "packaging" optional = false @@ -148,7 +206,7 @@ pyparsing = ">=2.0.2" six = "*" [[package]] -category = "main" +category = "dev" description = "plugin and hook calling mechanisms for python" name = "pluggy" optional = false @@ -159,7 +217,7 @@ version = "0.12.0" importlib-metadata = ">=0.12" [[package]] -category = "main" +category = "dev" description = "library with cross-python path, ini-parsing, io, code, log facilities" name = "py" optional = false @@ -183,7 +241,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.1.1" [[package]] -category = "main" +category = "dev" description = "Python parsing module" name = "pyparsing" optional = false @@ -191,7 +249,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" version = "2.4.2" [[package]] -category = "main" +category = "dev" description = "pytest: simple powerful testing with Python" name = "pytest" optional = false @@ -210,7 +268,7 @@ py = ">=1.5.0" wcwidth = "*" [[package]] -category = "main" +category = "dev" description = "Pytest plugin for measuring coverage." name = "pytest-cov" optional = false @@ -232,6 +290,14 @@ version = "1.10.4" [package.dependencies] pytest = ">=2.7" +[[package]] +category = "dev" +description = "YAML parser and emitter for Python" +name = "pyyaml" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "5.1.2" + [[package]] category = "main" description = "Python HTTP for Humans." @@ -285,6 +351,14 @@ optional = false python-versions = "*" version = "0.10.0" +[[package]] +category = "dev" +description = "Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed." +name = "tornado" +optional = false +python-versions = ">= 3.5" +version = "6.0.3" + [[package]] category = "main" description = "HTTP library with thread-safe connection pooling, file post, and more." @@ -294,7 +368,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4" version = "1.25.3" [[package]] -category = "main" +category = "dev" description = "Measures number of Terminal column cells of wide-character codes" name = "wcwidth" optional = false @@ -302,7 +376,7 @@ python-versions = "*" version = "0.1.7" [[package]] -category = "main" +category = "dev" description = "Backport of pathlib-compatible object wrapper for zip files" name = "zipp" optional = false @@ -310,7 +384,7 @@ python-versions = ">=2.7" version = "0.5.2" [metadata] -content-hash = "7ac7c3faf8b2a52ca27cdada3bbf95753aaf4a0706bb6411d18a6c1683810851" +content-hash = "a91c228498d75956c4b88cba3cbf19b2aebac7502115a32d77e55b8cee2d8f43" python-versions = "^3.6" [metadata.hashes] @@ -327,7 +401,12 @@ entrypoints = ["589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19 flake8 = ["19241c1cbc971b9962473e4438a2ca19749a7dd002dd1a946eaba171b4114548", "8e9dfa3cecb2400b3738a42c54c3043e821682b9c840b0448c0503f781130696"] idna = ["c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", "ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"] importlib-metadata = ["23d3d873e008a513952355379d93cbcab874c58f4f034ff657c7a87422fa64e8", "80d2de76188eabfbfcf27e6a37342c2827801e59c4cc14b0371c56fed43820e3"] +jinja2 = ["065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", "14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b"] +livereload = ["78d55f2c268a8823ba499305dcac64e28ddeb9a92571e12d543cd304faf5817b", "89254f78d7529d7ea0a3417d224c34287ebfe266b05e67e51facaf82c27f0f66"] +markdown = ["2e50876bcdd74517e7b71f3e7a76102050edec255b3983403f1a63e7c8a41e7a", "56a46ac655704b91e5b7e6326ce43d5ef72411376588afa1dd90e881b83c7e8c"] +markupsafe = ["00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", "09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", "09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", "1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", "24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", "29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", "43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", "46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", "500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", "535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", "62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", "6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", "717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", "79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", "7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", "88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", "8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", "98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", "9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", "9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", "ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", "b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", "b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", "b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", "ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", "c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", "cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", "e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"] mccabe = ["ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", "dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"] +mkdocs = ["17d34329aad75d5de604b9ed4e31df3a4d235afefdc46ce7b1964fddb2e1e939", "8cc8b38325456b9e942c981a209eaeb1e9f3f77b493ad755bfef889b9c8d356a"] more-itertools = ["409cd48d4db7052af495b09dec721011634af3753ae1ef92d2b32f73a745f832", "92b8c4b06dac4f0611c0729b2f2ede52b2e1bac1ab48f089c7ddc12e26bb60c4"] packaging = ["a7ac867b97fdc07ee80a8058fe4435ccd274ecc3b0ed61d852d7d53055528cf9", "c491ca87294da7cc01902edbe30a5bc6c4c28172b5138ab4e4aa1b9d7bfaeafe"] pluggy = ["0825a152ac059776623854c1543d65a4ad408eb3d33ee114dff91e57ec6ae6fc", "b9817417e95936bf75d85d3f8767f7df6cdde751fc40aed3bb3074cbcb77757c"] @@ -338,11 +417,13 @@ pyparsing = ["6f98a7b9397e206d78cc01df10131398f1c8b8510a2f4d97d9abd82e1aacdd80", pytest = ["6ef6d06de77ce2961156013e9dff62f1b2688aa04d0dc244299fe7d67e09370d", "a736fed91c12681a7b34617c8fcefe39ea04599ca72c608751c31d89579a3f77"] pytest-cov = ["2b097cde81a302e1047331b48cadacf23577e431b61e9c6f49a1170bbe3d3da6", "e00ea4fdde970725482f1f35630d12f074e121a23801aabf2ae154ec6bdd343a"] pytest-mock = ["43ce4e9dd5074993e7c021bb1c22cbb5363e612a2b5a76bc6d956775b10758b7", "5bf5771b1db93beac965a7347dc81c675ec4090cb841e49d9d34637a25c30568"] +pyyaml = ["0113bc0ec2ad727182326b61326afa3d1d8280ae1122493553fd6f4397f33df9", "01adf0b6c6f61bd11af6e10ca52b7d4057dd0be0343eb9283c878cf3af56aee4", "5124373960b0b3f4aa7df1707e63e9f109b5263eca5976c66e08b1c552d4eaf8", "5ca4f10adbddae56d824b2c09668e91219bb178a1eee1faa56af6f99f11bf696", "7907be34ffa3c5a32b60b95f4d95ea25361c951383a894fec31be7252b2b6f34", "7ec9b2a4ed5cad025c2278a1e6a19c011c80a3caaac804fd2d329e9cc2c287c9", "87ae4c829bb25b9fe99cf71fbb2140c448f534e24c998cc60f39ae4f94396a73", "9de9919becc9cc2ff03637872a440195ac4241c80536632fffeb6a1e25a74299", "a5a85b10e450c66b49f98846937e8cfca1db3127a9d5d1e31ca45c3d0bef4c5b", "b0997827b4f6a7c286c01c5f60384d218dca4ed7d9efa945c3e1aa623d5709ae", "b631ef96d3222e62861443cc89d6563ba3eeb816eeb96b2629345ab795e53681", "bf47c0607522fdbca6c9e817a6e81b08491de50f3766a7a0e6a5be7905961b41", "f81025eddd0327c7d4cfe9b62cf33190e1e736cc6e97502b3ec425f574b3e7a8"] requests = ["11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", "9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"] requests-mock = ["12e17c7ad1397fd1df5ead7727eb3f1bdc9fe1c18293b0492e0e01b57997e38d", "dc9e416a095ee7c3360056990d52e5611fb94469352fc1c2dc85be1ff2189146"] six = ["3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"] tenacity = ["6a7511a59145c2e319b7d04ddd93c12d48cc3d3c8fa42c2846d33a620ee91f57", "a4eb168dbf55ed2cae27e7c6b2bd48ab54dabaf294177d998330cf59f294c112"] toml = ["229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", "235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e", "f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"] +tornado = ["349884248c36801afa19e342a77cc4458caca694b0eda633f5878e458a44cb2c", "398e0d35e086ba38a0427c3b37f4337327231942e731edaa6e9fd1865bbd6f60", "4e73ef678b1a859f0cb29e1d895526a20ea64b5ffd510a2307b5998c7df24281", "559bce3d31484b665259f50cd94c5c28b961b09315ccd838f284687245f416e5", "abbe53a39734ef4aba061fca54e30c6b4639d3e1f59653f0da37a0003de148c7", "c845db36ba616912074c5b1ee897f8e0124df269468f25e4fe21fe72f6edd7a9", "c9399267c926a4e7c418baa5cbe91c7d1cf362d505a1ef898fde44a07c9dd8a5"] urllib3 = ["b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1", "dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232"] wcwidth = ["3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", "f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c"] zipp = ["4970c3758f4e89a7857a973b1e2a5d75bcdc47794442f2e2dd4fe8e0466e809a", "8a5712cfd3bb4248015eb3b0b3c54a5f6ee3f2425963ef2a0125b8bc40aafaec"] diff --git a/pycaprio/core/adapters/http_adapter.py b/pycaprio/core/adapters/http_adapter.py index ae39221..c64f0a9 100644 --- a/pycaprio/core/adapters/http_adapter.py +++ b/pycaprio/core/adapters/http_adapter.py @@ -41,8 +41,9 @@ def documents(self, project_id: int) -> List[Document]: document.project_id = project_id return document_list - def document(self, project_id: int, document_id: int) -> bytes: - response = self.client.get(f'/projects/{project_id}/documents/{document_id}', allowed_statuses=(200,)) + def document(self, project_id: int, document_id: int, document_format: str = DocumentFormats.DEFAULT) -> bytes: + response = self.client.get(f'/projects/{project_id}/documents/{document_id}', allowed_statuses=(200,), + params={'format': document_format}) return response.content def annotations(self, project_id: int, document_id: int) -> List[Annotation]: @@ -55,9 +56,9 @@ def annotations(self, project_id: int, document_id: int) -> List[Annotation]: return annotation_list def annotation(self, project_id: int, document_id: int, user_name: str, - format: str = DocumentFormats.DEFAULT) -> bytes: + annotation_format: str = DocumentFormats.DEFAULT) -> bytes: response = self.client.get(f'/projects/{project_id}/documents/{document_id}/annotations/{user_name}', - allowed_statuses=(200,), params={'format': format}) + allowed_statuses=(200,), params={'format': annotation_format}) return response.content def create_project(self, project_name: str, creator_name: Optional[str] = None) -> Project: @@ -67,10 +68,10 @@ def create_project(self, project_name: str, creator_name: Optional[str] = None) return ProjectSchema().load(response.json()['body']) def create_document(self, project_id: int, document_name: str, content: IO, - document_format: str = DocumentFormats.DEFAULT, state: str = DocumentStatus.DEFAULT): + document_format: str = DocumentFormats.DEFAULT, document_state: str = DocumentStatus.DEFAULT): response = self.client.post(f"/projects/{project_id}/documents", form_data={"name": document_name, "format": document_format, - "state": state}, + "state": document_state}, files={"content": ('test/path', content)}, allowed_statuses=(201, 200)) document = DocumentSchema().load(response.json()['body'], many=False) @@ -78,9 +79,10 @@ def create_document(self, project_id: int, document_name: str, content: IO, return document def create_annotation(self, project_id: int, document_id: int, user_name: str, content: IO, - annotation_format: str = DocumentFormats.DEFAULT, state: str = AnnotationStatus.DEFAULT): + annotation_format: str = DocumentFormats.DEFAULT, + annotation_state: str = AnnotationStatus.DEFAULT): response = self.client.post(f"/projects/{project_id}/documents/{document_id}/annotations/{user_name}", - form_data={'format': annotation_format, 'state': state}, + form_data={'format': annotation_format, 'state': annotation_state}, files={"content": ('test/path', content)}, allowed_statuses=(201, 200)) annotation = AnnotationSchema().load(response.json()['body'], many=False) @@ -101,9 +103,9 @@ def delete_annotation(self, project_id: int, document_id: int, user_name: str): allowed_statuses=(204, 200)) return True - def export_project(self, project_id: int, format: str = DocumentFormats.DEFAULT) -> bytes: + def export_project(self, project_id: int, project_format: str = DocumentFormats.DEFAULT) -> bytes: response = self.client.get(f"/projects/{project_id}/export.zip", allowed_statuses=(200,), - params={'format': format}) + params={'format': project_format}) return response.content def import_project(self, zip_stream: IO) -> Project: diff --git a/pycaprio/core/interfaces/adapter.py b/pycaprio/core/interfaces/adapter.py index c1f89d4..885c1ce 100644 --- a/pycaprio/core/interfaces/adapter.py +++ b/pycaprio/core/interfaces/adapter.py @@ -41,7 +41,7 @@ def documents(self, project_id: int) -> List[Document]: pass # pragma: no cover @abstractmethod - def document(self, project_id: int, document_id: int) -> bytes: + def document(self, project_id: int, document_id: int, format: str = DocumentFormats.DEFAULT) -> bytes: """ Retrieves a Document :param project_id: The project_id of the Project where the Document is located diff --git a/pyproject.toml b/pyproject.toml index 8de9132..deccb21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,6 @@ packages = [ python = "^3.6" requests = "*" tenacity = "^5.1" -pytest-cov = "^2.7" [tool.poetry.dev-dependencies] pytest = "*" @@ -21,6 +20,8 @@ requests-mock = "*" flake8 = "*" black = { version = "*", allows-prereleases = true } coverage = "*" +mkdocs = "^1.0" +pytest-cov = "^2.7" [tool.black] line-length = 120 From 0cb6913d17eb2b5bb5d936caab812e9c258519fc Mon Sep 17 00:00:00 2001 From: Javier Luna Molina Date: Fri, 13 Sep 2019 10:10:46 +0200 Subject: [PATCH 2/3] Standarize api (#10) * Rename DocumentFormats to InceptionFormat, DocumentStatus to DocumentState, AnnotationStatus to AnnotationState. Reflect changes in docs. * Add mappings file to improve API * Update tests --- docs/api/annotations.md | 8 +++---- docs/api/documents.md | 8 +++---- docs/api/formats.md | 6 +++--- docs/api/projects.md | 4 ++-- docs/index.md | 4 ++-- pycaprio/core/adapters/http_adapter.py | 18 ++++++++-------- pycaprio/core/interfaces/adapter.py | 29 ++++++++++++++------------ pycaprio/core/mappings.py | 6 +++--- pycaprio/mappings.py | 2 ++ tests/unit_tests/core/conftest.py | 8 +++---- 10 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 pycaprio/mappings.py diff --git a/docs/api/annotations.md b/docs/api/annotations.md index 69955df..1bf0fce 100644 --- a/docs/api/annotations.md +++ b/docs/api/annotations.md @@ -25,8 +25,8 @@ You can specify the annotation's format via `annotation_format` (defaults to `we Example: ```python -from pycaprio.core.mappings import DocumentFormats -annotation_content = client.api.annotation(1, 4, 'test-user', annotation_format=DocumentFormats.WEBANNO) # Downloads test-user's annotations on document 4 on project 1 +from pycaprio.mappings import InceptionFormat +annotation_content = client.api.annotation(1, 4, 'test-user', annotation_format=InceptionFormat.WEBANNO) # Downloads test-user's annotations on document 4 on project 1 with open("downloaded_annotation", 'wb') as annotation_file: annotation_file.write(annotation_content) @@ -39,9 +39,9 @@ You can specify the annotation's format via `annotation_format` (defaults to `we Example: ```python -from pycaprio.core.mappings import DocumentFormats, AnnotationStatus +from pycaprio.mappings import InceptionFormat, AnnotationState with open("annotation") as annotation_file: - new_annotation = client.api.create_annotation(1, 4, 'leonardo-dicaprio', annotation_format=DocumentFormats.WEBANNO, annotation_state=AnnotationStatus.ANNOTATION_IN_PROGRESS) + new_annotation = client.api.create_annotation(1, 4, 'leonardo-dicaprio', annotation_format=InceptionFormat.WEBANNO, annotation_state=AnnotationState.ANNOTATION_IN_PROGRESS) print(new_annotation) # ``` diff --git a/docs/api/documents.md b/docs/api/documents.md index cb92814..9229f92 100644 --- a/docs/api/documents.md +++ b/docs/api/documents.md @@ -23,8 +23,8 @@ You can specify the annotation's format via `document_format` (defaults to `weba Example: ```python -from pycaprio.core.mappings import DocumentFormats -document_content = client.api.document(1, 4, document_format=DocumentFormats.WEBANNO) # Downloads document 4 from project 1 +from pycaprio.mappings import InceptionFormat +document_content = client.api.document(1, 4, document_format=InceptionFormat.WEBANNO) # Downloads document 4 from project 1 with open("downloaded_document", 'wb') as document_file: document_file.write(document_content) @@ -38,9 +38,9 @@ You can specify the document's state via `document_state` (defaults to `NEW`). Example: ```python -from pycaprio.core.mappings import DocumentFormats, DocumentStatus +from pycaprio.mappings import InceptionFormat, DocumentState with open("document") as document_file: - new_document = client.api.create_document(1, "Test document name", document_file, document_format=DocumentFormats.WEBANNO, document_state=DocumentStatus.IN_PROGRESS) + new_document = client.api.create_document(1, "Test document name", document_file, document_format=InceptionFormat.WEBANNO, document_state=DocumentState.IN_PROGRESS) print(new_document) # ``` diff --git a/docs/api/formats.md b/docs/api/formats.md index fbb7ed6..9a46156 100644 --- a/docs/api/formats.md +++ b/docs/api/formats.md @@ -17,9 +17,9 @@ INCEpTION doesn't specify in their documentation which formats are supported, bu You can find a class with all the formats in `pycaprio.core.mappings.DocumentFormats`: ```python -from pycaprio.core.mappings import DocumentFormats +from pycaprio.core.mappings import InceptionFormat -DocumentFormats.DEFAULT -DocumentFormats.TEI +InceptionFormat.DEFAULT +InceptionFormat.TEI ... ``` diff --git a/docs/api/projects.md b/docs/api/projects.md index 8b50663..f18f346 100644 --- a/docs/api/projects.md +++ b/docs/api/projects.md @@ -52,8 +52,8 @@ You can specify the export file format using the `format` parameter. By default, Example: ```python -from pycaprio.core.mappings import DocumentFormats -content = client.api.export_project(1, format=DocumentFormats.XMI) # type(content) is bytes +from pycaprio.mappings import InceptionFormat +content = client.api.export_project(1, project_format=InceptionFormat.XMI) # type(content) is bytes with open("exported_project.zip", 'wb') as zip_file: zip_file.write(content) ``` diff --git a/docs/index.md b/docs/index.md index 944ca6f..ce0b1fb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,9 +20,9 @@ client = Pycaprio("http://your-inception-host.com", authentication=("remote-user projects = client.api.projects() # Export all projects in XMI format -from pycaprio.core.mappings import DocumentFormats +from pycaprio.mappings import InceptionFormat for project in projects: - zip_content = client.api.export_project(project.project_id, format=DocumentFormats.XMI) + zip_content = client.api.export_project(project.project_id, format=InceptionFormat.XMI) with open(f"{project.project_name}.zip", 'wb') as zip_file: zip_file.write(zip_content) ``` diff --git a/pycaprio/core/adapters/http_adapter.py b/pycaprio/core/adapters/http_adapter.py index c64f0a9..37cffbf 100644 --- a/pycaprio/core/adapters/http_adapter.py +++ b/pycaprio/core/adapters/http_adapter.py @@ -5,9 +5,9 @@ from pycaprio.core.clients.retryable_client import RetryableInceptionClient from pycaprio.core.interfaces.adapter import BaseInceptionAdapter from pycaprio.core.interfaces.types import authentication_type -from pycaprio.core.mappings import AnnotationStatus -from pycaprio.core.mappings import DocumentFormats -from pycaprio.core.mappings import DocumentStatus +from pycaprio.core.mappings import AnnotationState +from pycaprio.core.mappings import InceptionFormat +from pycaprio.core.mappings import DocumentState from pycaprio.core.objects.annotation import Annotation from pycaprio.core.objects.document import Document from pycaprio.core.objects.project import Project @@ -41,7 +41,7 @@ def documents(self, project_id: int) -> List[Document]: document.project_id = project_id return document_list - def document(self, project_id: int, document_id: int, document_format: str = DocumentFormats.DEFAULT) -> bytes: + def document(self, project_id: int, document_id: int, document_format: str = InceptionFormat.DEFAULT) -> bytes: response = self.client.get(f'/projects/{project_id}/documents/{document_id}', allowed_statuses=(200,), params={'format': document_format}) return response.content @@ -56,7 +56,7 @@ def annotations(self, project_id: int, document_id: int) -> List[Annotation]: return annotation_list def annotation(self, project_id: int, document_id: int, user_name: str, - annotation_format: str = DocumentFormats.DEFAULT) -> bytes: + annotation_format: str = InceptionFormat.DEFAULT) -> bytes: response = self.client.get(f'/projects/{project_id}/documents/{document_id}/annotations/{user_name}', allowed_statuses=(200,), params={'format': annotation_format}) return response.content @@ -68,7 +68,7 @@ def create_project(self, project_name: str, creator_name: Optional[str] = None) return ProjectSchema().load(response.json()['body']) def create_document(self, project_id: int, document_name: str, content: IO, - document_format: str = DocumentFormats.DEFAULT, document_state: str = DocumentStatus.DEFAULT): + document_format: str = InceptionFormat.DEFAULT, document_state: str = DocumentState.DEFAULT): response = self.client.post(f"/projects/{project_id}/documents", form_data={"name": document_name, "format": document_format, "state": document_state}, @@ -79,8 +79,8 @@ def create_document(self, project_id: int, document_name: str, content: IO, return document def create_annotation(self, project_id: int, document_id: int, user_name: str, content: IO, - annotation_format: str = DocumentFormats.DEFAULT, - annotation_state: str = AnnotationStatus.DEFAULT): + annotation_format: str = InceptionFormat.DEFAULT, + annotation_state: str = AnnotationState.DEFAULT): response = self.client.post(f"/projects/{project_id}/documents/{document_id}/annotations/{user_name}", form_data={'format': annotation_format, 'state': annotation_state}, files={"content": ('test/path', content)}, @@ -103,7 +103,7 @@ def delete_annotation(self, project_id: int, document_id: int, user_name: str): allowed_statuses=(204, 200)) return True - def export_project(self, project_id: int, project_format: str = DocumentFormats.DEFAULT) -> bytes: + def export_project(self, project_id: int, project_format: str = InceptionFormat.DEFAULT) -> bytes: response = self.client.get(f"/projects/{project_id}/export.zip", allowed_statuses=(200,), params={'format': project_format}) return response.content diff --git a/pycaprio/core/interfaces/adapter.py b/pycaprio/core/interfaces/adapter.py index 885c1ce..cb2db6c 100644 --- a/pycaprio/core/interfaces/adapter.py +++ b/pycaprio/core/interfaces/adapter.py @@ -4,9 +4,9 @@ from typing import List -from pycaprio.core.mappings import AnnotationStatus -from pycaprio.core.mappings import DocumentFormats -from pycaprio.core.mappings import DocumentStatus +from pycaprio.core.mappings import AnnotationState +from pycaprio.core.mappings import InceptionFormat +from pycaprio.core.mappings import DocumentState from pycaprio.core.objects.annotation import Annotation from pycaprio.core.objects.document import Document from pycaprio.core.objects.project import Project @@ -41,11 +41,12 @@ def documents(self, project_id: int) -> List[Document]: pass # pragma: no cover @abstractmethod - def document(self, project_id: int, document_id: int, format: str = DocumentFormats.DEFAULT) -> bytes: + def document(self, project_id: int, document_id: int, document_format: str = InceptionFormat.DEFAULT) -> bytes: """ Retrieves a Document :param project_id: The project_id of the Project where the Document is located :param document_id: Document id + :param document_format: Format in which the document will be downloaded :return: Content of the Document in bytes """ pass # pragma: no cover @@ -62,12 +63,13 @@ def annotations(self, project_id: int, document_id: int) -> List[Annotation]: @abstractmethod def annotation(self, project_id: int, document_id: int, annotation_id: int, - format: str = DocumentFormats.DEFAULT) -> bytes: + annotation_format: str = InceptionFormat.DEFAULT) -> bytes: """ Retrieves a Document :param project_id: The project_id of the Project where the Annotation is located :param document_id: The document_id of the Document where the Annotation is located - :param format: Format in which the annotation will be downloaded + :param annotation_id: The annotation's id + :param annotation_format: Format in which the annotation will be downloaded :return: Content of the Annotation in bytes """ pass # pragma: no cover @@ -85,22 +87,23 @@ def create_project(self, project_name: str, creator_name: str) -> Project: @abstractmethod def create_document(self, project_id: int, document_name: str, content: IO, - document_format: str = DocumentFormats.DEFAULT, - state: str = DocumentStatus.DEFAULT) -> Document: + document_format: str = InceptionFormat.DEFAULT, + document_state: str = DocumentState.DEFAULT) -> Document: """ Creates a Document :param project_id: Id of the Project where the new Document will be created :param document_name: Document name. :param content: Content of the Document. :param document_format: Document format. - :param state: State of the Document. + :param document_state: State of the Document. :return: Recently created Document """ pass # pragma: no cover @abstractmethod def create_annotation(self, project_id: int, document_id: int, user_name: str, content: IO, - annotation_format: str = DocumentFormats.DEFAULT, state: str = AnnotationStatus.DEFAULT): + annotation_format: str = InceptionFormat.DEFAULT, + annotation_state: str = AnnotationState.DEFAULT): """ Creates a Document :param project_id: Id of the Project where the new Document will be created @@ -108,7 +111,7 @@ def create_annotation(self, project_id: int, document_id: int, user_name: str, c :param user_name: Annotator's username. :param content: Content of the Annotation. :param annotation_format: Annotation format. - :param state: State of the Annotation. + :param annotation_state: State of the Annotation. :return: Recently created Document. """ pass # pragma: no cover @@ -141,11 +144,11 @@ def delete_annotation(self, project_id: int, document_id: int, user_name: str) - pass # pragma: no cover @abstractmethod - def export_project(self, project_id: int, format: str = DocumentFormats.DEFAULT) -> bytes: + def export_project(self, project_id: int, project_format: str = InceptionFormat.DEFAULT) -> bytes: """ Exports a Project into a .zip file. :param project_id: Project id. - :param format: Format in which the documents and annotations will be exported. + :param project_format: Format in which the documents and annotations will be exported. :return: Zip file in bytes. """ pass # pragma: no cover diff --git a/pycaprio/core/mappings.py b/pycaprio/core/mappings.py index 1fd94ea..1a8d7df 100644 --- a/pycaprio/core/mappings.py +++ b/pycaprio/core/mappings.py @@ -3,7 +3,7 @@ NO_DOCUMENT = -1 -class DocumentFormats: +class InceptionFormat: DEFAULT = 'webanno' WEBANNO = 'webanno' NIF = 'nif' @@ -16,7 +16,7 @@ class DocumentFormats: XMI = 'xmi' -class DocumentStatus: +class DocumentState: DEFAULT = 'NEW' NEW = 'NEW' LOCKED = 'LOCKED' @@ -24,7 +24,7 @@ class DocumentStatus: COMPLETE = 'COMPLETE' -class AnnotationStatus: +class AnnotationState: DEFAULT = 'ANNOTATION-IN-PROGRESS' ANNOTATION_IN_PROGRESS = 'ANNOTATION-IN-PROGRESS' ANNOTATION_COMPLETE = 'ANNOTATION-COMPLETE' diff --git a/pycaprio/mappings.py b/pycaprio/mappings.py new file mode 100644 index 0000000..5e24a7a --- /dev/null +++ b/pycaprio/mappings.py @@ -0,0 +1,2 @@ +# flake8: noqa +from pycaprio.core.mappings import InceptionFormat, DocumentState, AnnotationState diff --git a/tests/unit_tests/core/conftest.py b/tests/unit_tests/core/conftest.py index 2c1d194..2b3f0e1 100644 --- a/tests/unit_tests/core/conftest.py +++ b/tests/unit_tests/core/conftest.py @@ -3,9 +3,9 @@ import pytest -from pycaprio.core.mappings import AnnotationStatus +from pycaprio.core.mappings import AnnotationState from pycaprio.core.mappings import DATE_FORMAT_ISO8601 -from pycaprio.core.mappings import DocumentStatus +from pycaprio.core.mappings import DocumentState from pycaprio.core.mappings import NO_DOCUMENT from pycaprio.core.mappings import NO_PROJECT from pycaprio.core.objects.annotation import Annotation @@ -62,7 +62,7 @@ def mock_document_name(): @pytest.fixture def mock_document_state(): - return DocumentStatus.DEFAULT + return DocumentState.DEFAULT @pytest.fixture @@ -89,7 +89,7 @@ def mock_annotation_user(): @pytest.fixture def mock_annotation_state(): - return AnnotationStatus.DEFAULT + return AnnotationState.DEFAULT @pytest.fixture From b990970a11da82df79eca989e71dca04b356f2ee Mon Sep 17 00:00:00 2001 From: JavierLuna Date: Fri, 13 Sep 2019 10:13:30 +0200 Subject: [PATCH 3/3] Bump version to 0.0.2rc4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7397320..4a51097 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pycaprio" -version = "0.0.2rc3" +version = "0.0.2rc4" description = "Python client for the INCEpTION annotation tool API" authors = ["Savanamed"] license = "MIT"