Exemplo n.º 1
0
    def predict_single(self, page: DatabasePage) -> Result:
        pcgts = page.pcgts()
        import pickle
        staff_lines: List[Coords] = []
        pcgts = pcgts
        for mr in pcgts.page.music_blocks():
            for ml in mr.lines:
                staff_lines += [
                    pcgts.page.page_to_image_scale(
                        s.coords, PageScaleReference.NORMALIZED)
                    for s in ml.staff_lines
                ]

        with open(
                page.file('connected_components_norm',
                          create_if_not_existing=True).local_path(),
                'rb') as pkl:
            polys = extract_components(
                pickle.load(pkl),
                pcgts.page.page_to_image_scale(self.initial_line,
                                               PageScaleReference.NORMALIZED),
                staff_lines)
            polys = [
                pcgts.page.image_to_page_scale(c,
                                               PageScaleReference.NORMALIZED)
                for c in polys
            ]

        return Result(polys)
Exemplo n.º 2
0
    def delete(self, request, book, page, operation):
        page = DatabasePage(DatabaseBook(book), page)

        if operation == 'clean':
            for key, _ in DatabaseFile.file_definitions().items():
                if key != 'color_original':
                    DatabaseFile(page, key).delete()

            return Response()
        elif operation == 'delete':
            page.delete()
            return Response()
Exemplo n.º 3
0
    def op_to_task_runner(operation, page: DatabasePage, body: dict):
        # check if operation is linked to a task
        from omr.steps.algorithmtypes import AlgorithmTypes
        for at in AlgorithmTypes:
            if at.value == operation:
                from restapi.operationworker.taskrunners.taskrunnerprediction import TaskRunnerPrediction, AlgorithmPredictorParams, Settings
                r = OperationView.AlgorithmRequest.from_dict(body)
                if 'pcgts' in body:
                    page.pcgts_from_dict(body['pcgts'])

                meta = page.book.get_meta()
                meta.algorithmPredictorParams[at] = r.params
                return TaskRunnerPrediction(
                    at, PageSelection.from_page(page),
                    Settings(meta.algorithm_predictor_params(at),
                             store_to_pcgts=False))

        return None
Exemplo n.º 4
0
 def predict(
     self,
     pages: List[DatabasePage],
     callback: Optional[PredictionCallback] = None
 ) -> AlgorithmPredictionResultGenerator:
     book = pages[0].book
     documents = DatabaseBookDocuments().load(book)
     document: Document = documents.database_documents.get_document_by_id(
         self.document_id)
     pages = [DatabasePage(book, x) for x in document.pages_names]
     # Todo Not Implemented yet
     yield Result()
Exemplo n.º 5
0
    def get(self, request, book, page, operation):
        page = DatabasePage(DatabaseBook(book), page)
        body = json.loads(request.body, encoding='utf-8') if request.body else {}
        task_runner = OperationView.op_to_task_runner(operation, page, body)
        if task_runner is not None:
            task_id = operation_worker.id_by_task_runner(task_runner)
            op_status = operation_worker.status(task_id)
            if op_status:
                return Response({'status': op_status.to_dict()})
            else:
                return Response(status.HTTP_204_NO_CONTENT)

        return Response(status=status.HTTP_204_NO_CONTENT)
Exemplo n.º 6
0
    def post(self, request, book, page, operation):
        body = json.loads(request.body, encoding='utf-8')
        page = DatabasePage(DatabaseBook(book), page)
        task_runner = OperationView.op_to_task_runner(operation, page, body)
        if task_runner:
            try:
                id = operation_worker.id_by_task_runner(task_runner)
                return Response({'task_id': id}, status=status.HTTP_202_ACCEPTED)
            except Exception as e:
                logger.error(e)
                return Response(str(e), status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
Exemplo n.º 7
0
    def get_text_of_document(self, book):
        text = ""
        started = False
        pages = [DatabasePage(book, x) for x in self.pages_names]
        for page in pages:
            for line in page.pcgts().page.all_text_lines():

                if page.pcgts().page.p_id == self.end.page_id:
                    if line.id == self.end.line_id:
                        break
                if line.id == self.start.line_id or started:
                    started = True
                    text += line.text() + " "
            else:
                continue
            break
        return text
Exemplo n.º 8
0
 def unprocessed(cls, page: DatabasePage) -> bool:
     return any([not page.file(f).exists() for f in files])
Exemplo n.º 9
0
 def unprocessed(cls, page: DatabasePage) -> bool:
     return all(
         [len(l.symbols) == 0 for l in page.pcgts().page.all_music_lines()])
Exemplo n.º 10
0
 def unprocessed(cls, page: DatabasePage) -> bool:
     return len(page.pcgts().page.text_blocks()) == 0
Exemplo n.º 11
0
 def unprocessed(cls, page: DatabasePage) -> bool:
     if not page.pcgts():
         return True
     return len(page.pcgts().page.annotations.connections) == 0