Browse Source

Merge pull request #1826 from doccano/fix/relationExport

Fix relation export
pull/1827/head
Hiroki Nakayama 2 years ago
committed by GitHub
parent
commit
997a9bde15
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions
  1. 14
      backend/data_export/pipeline/catalog.py
  2. 3
      backend/data_export/views.py

14
backend/data_export/pipeline/catalog.py

@ -44,14 +44,18 @@ class Options:
options: Dict[str, List] = defaultdict(list)
@classmethod
def filter_by_task(cls, task_name: str):
def filter_by_task(cls, task_name: str, use_relation: bool = False):
options = cls.options[task_name]
return [{**file_format.dict(), "example": example} for file_format, example in options]
return [
{**file_format.dict(), "example": example}
for file_format, example, use_rel in options
if use_rel == use_relation
]
@classmethod
def register(cls, task: str, file_format: Type[Format], file: Path):
def register(cls, task: str, file_format: Type[Format], file: Path, use_relation: bool = False):
example = cls.load_example(file)
cls.options[task].append((file_format, example))
cls.options[task].append((file_format, example, use_relation))
@staticmethod
def load_example(file):
@ -70,7 +74,7 @@ Options.register(DOCUMENT_CLASSIFICATION, JSONL, TEXT_CLASSIFICATION_DIR / "exam
SEQUENCE_LABELING_DIR = EXAMPLE_DIR / "sequence_labeling"
RELATION_EXTRACTION_DIR = EXAMPLE_DIR / "relation_extraction"
Options.register(SEQUENCE_LABELING, JSONL, SEQUENCE_LABELING_DIR / "example.jsonl")
Options.register(SEQUENCE_LABELING, JSONL, RELATION_EXTRACTION_DIR / "example.jsonl")
Options.register(SEQUENCE_LABELING, JSONL, RELATION_EXTRACTION_DIR / "example.jsonl", True)
# Sequence to sequence
SEQ2SEQ_DIR = EXAMPLE_DIR / "sequence_to_sequence"

3
backend/data_export/views.py

@ -18,7 +18,8 @@ class DatasetCatalog(APIView):
def get(self, request, *args, **kwargs):
project_id = kwargs["project_id"]
project = get_object_or_404(Project, pk=project_id)
options = Options.filter_by_task(project.project_type)
use_relation = getattr(project, "use_relation", False)
options = Options.filter_by_task(project.project_type, use_relation)
return Response(data=options, status=status.HTTP_200_OK)

Loading…
Cancel
Save