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/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" 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