Skip to content

Commit

Permalink
0.0.2rc4
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierLuna committed Sep 13, 2019
2 parents b785d73 + b990970 commit 9d99f8a
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 45 deletions.
8 changes: 4 additions & 4 deletions docs/api/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) # <Annotation by leonardo-dicaprio (Project: 1, Document: 4)>
```

Expand Down
8 changes: 4 additions & 4 deletions docs/api/documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) # <Document #5: Test document name (Project: 1)>
```

Expand Down
6 changes: 3 additions & 3 deletions docs/api/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
```
4 changes: 2 additions & 2 deletions docs/api/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
18 changes: 9 additions & 9 deletions pycaprio/core/adapters/http_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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},
Expand All @@ -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)},
Expand All @@ -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
Expand Down
29 changes: 16 additions & 13 deletions pycaprio/core/interfaces/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -85,30 +87,31 @@ 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
:param document_id: Id of the Document which is targeted for annotation.
: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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pycaprio/core/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
NO_DOCUMENT = -1


class DocumentFormats:
class InceptionFormat:
DEFAULT = 'webanno'
WEBANNO = 'webanno'
NIF = 'nif'
Expand All @@ -16,15 +16,15 @@ class DocumentFormats:
XMI = 'xmi'


class DocumentStatus:
class DocumentState:
DEFAULT = 'NEW'
NEW = 'NEW'
LOCKED = 'LOCKED'
IN_PROGRESS = 'IN-PROGRESS'
COMPLETE = 'COMPLETE'


class AnnotationStatus:
class AnnotationState:
DEFAULT = 'ANNOTATION-IN-PROGRESS'
ANNOTATION_IN_PROGRESS = 'ANNOTATION-IN-PROGRESS'
ANNOTATION_COMPLETE = 'ANNOTATION-COMPLETE'
Expand Down
2 changes: 2 additions & 0 deletions pycaprio/mappings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# flake8: noqa
from pycaprio.core.mappings import InceptionFormat, DocumentState, AnnotationState
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +62,7 @@ def mock_document_name():

@pytest.fixture
def mock_document_state():
return DocumentStatus.DEFAULT
return DocumentState.DEFAULT


@pytest.fixture
Expand All @@ -89,7 +89,7 @@ def mock_annotation_user():

@pytest.fixture
def mock_annotation_state():
return AnnotationStatus.DEFAULT
return AnnotationState.DEFAULT


@pytest.fixture
Expand Down

0 comments on commit 9d99f8a

Please sign in to comment.