You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
2.4 KiB

  1. import {AnnotationApplicationService} from '../annotationApplicationService'
  2. import {SequenceLabelingDTO} from './sequenceLabelingData'
  3. import {APISequenceLabelingRepository} from '~/repositories/tasks/sequenceLabeling/apiSequenceLabeling'
  4. import {SequenceLabelingLabel} from '~/domain/models/tasks/sequenceLabeling'
  5. import {LinkRepository} from "~/domain/models/links/linkRepository";
  6. import {LinkItem} from "~/domain/models/links/link";
  7. export class SequenceLabelingApplicationService extends AnnotationApplicationService<SequenceLabelingLabel> {
  8. constructor(
  9. readonly repository: APISequenceLabelingRepository,
  10. readonly linkRepository: LinkRepository
  11. ) {
  12. super(new APISequenceLabelingRepository())
  13. }
  14. public async list(projectId: string, docId: number): Promise<SequenceLabelingDTO[]> {
  15. const items = await this.repository.list(projectId, docId)
  16. return items.map(item => new SequenceLabelingDTO(item))
  17. }
  18. public async create(projectId: string, docId: number, labelId: number, startOffset: number, endOffset: number): Promise<void> {
  19. const item = new SequenceLabelingLabel(0, labelId, 0, startOffset, endOffset)
  20. try {
  21. await this.repository.create(projectId, docId, item)
  22. } catch(e) {
  23. console.log(e.response.data.detail)
  24. }
  25. }
  26. public async changeLabel(projectId: string, docId: number, annotationId: number, labelId: number): Promise<void> {
  27. try {
  28. await this.repository.update(projectId, docId, annotationId, labelId)
  29. } catch(e) {
  30. console.log(e.response.data.detail)
  31. }
  32. }
  33. public async listLinks(projectId: string): Promise<LinkItem[]> {
  34. return await this.linkRepository.list(projectId);
  35. }
  36. public async createLink(projectId: string, sourceId: number, targetId: number, linkType: number, userId: number): Promise<void> {
  37. const link = new LinkItem(0, sourceId, targetId, linkType, userId, (new Date()).toISOString());
  38. await this.linkRepository.create(projectId, link);
  39. }
  40. public async deleteLink(projectId: string, linkId: number): Promise<void> {
  41. await this.linkRepository.bulkDelete(projectId, [linkId]);
  42. }
  43. public async updateLink(projectId: string, linkId: number, linkType: number): Promise<void> {
  44. await this.linkRepository.update(projectId, linkId, linkType);
  45. }
  46. }