예제 #1
0
 def put(self, request, book, document):
     book = DatabaseBook(book)
     documents = DatabaseBookDocuments().load(book)
     document: Document = documents.database_documents.get_document_by_id(
         document)
     obj = json.loads(request.body, encoding='utf-8')
     doc_obj = Document.from_json(obj)
     documents.database_documents.documents[
         documents.database_documents.documents.index(document)] = doc_obj
     documents.to_file(book=book)
     return Response()
예제 #2
0
    def put(self, request, book):
        book = DatabaseBook(book)
        ## Todo Mutex/lock
        obj = json.loads(request.body, encoding='utf-8')
        db = DatabaseBookDocuments.from_json(obj)
        db.to_file(book)
        logger.debug('Successfully saved DatabaseFile to {}'.format(
            book.local_path))

        return Response()
예제 #3
0
 def get(self, request, book):
     book = DatabaseBook(book)
     documents = DatabaseBookDocuments().load(book)
     filename = 'CM Default Metadatendatei'
     bytes = documents.database_documents.export_documents_to_xls(
         documents=documents.database_documents.documents,
         filename=filename,
         editor=str(request.user.username))
     return HttpResponse(
         bytes,
         content_type="application/vnd.oasis.opendocument.spreadsheet")
예제 #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()
예제 #5
0
 def get(self, request, book, document):
     book = DatabaseBook(book)
     documents = DatabaseBookDocuments().load(book)
     document: Document = documents.database_documents.get_document_by_id(
         document)
     filename = 'CM Default Metadatendatei'
     editor = request.session.get('monodi_user', None)
     user = editor if editor is not None else request.user.username
     bytes = document.export_to_xls(filename, user)
     return HttpResponse(
         bytes,
         content_type=
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
     )
예제 #6
0
    def get(self, request, book, document):
        book = DatabaseBook(book)
        documents = DatabaseBookDocuments().load(book)
        document: Document = documents.database_documents.get_document_by_id(
            document)
        pages = [DatabasePage(book, x) for x in document.pages_names]
        pcgts = [
            DatabaseFile(page, 'pcgts',
                         create_if_not_existing=True).page.pcgts()
            for page in pages
        ]
        midi = SimpleMidiExporter(pcgts)
        seq = midi.generate_note_sequence(document=document)

        return Response(seq)
예제 #7
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)
        text = document.get_text_of_document(book)
        text = self.text_normalizer.apply(text)
        text = text.split(' ')
        count = self.document_similar_tester.check_word_based_similarity(text)
        texts = []
        for key, count in count.most_common(5):
            #print(self.document_similar_tester.document_dict[key].sentence)
            #print(self.document_similar_tester.document_dict[key].get_word_list())
            #print(self.document_similar_tester.document_dict[key].get_text())
            texts.append(
                self.document_similar_tester.document_dict[key].get_text())

        yield Result(texts)
예제 #8
0
 def get(self, request, book, document, width):
     book = DatabaseBook(book)
     documents = DatabaseBookDocuments().load(book)
     document: Document = documents.database_documents.get_document_by_id(
         document)
     pages = [DatabasePage(book, x) for x in document.pages_names]
     pcgts = [
         DatabaseFile(page, 'pcgts',
                      create_if_not_existing=True).page.pcgts()
         for page in pages
     ]
     root = PcgtsToMonodiConverter(pcgts, document=document).root
     script_path = os.path.join(BASE_DIR, 'internal_storage', 'resources',
                                'monodi_svg_render', 'bin', 'one-shot')
     proc = subprocess.run([script_path, "-", "-w", width],
                           input=str(json.dumps(root.to_json())),
                           stdout=subprocess.PIPE,
                           universal_newlines=True,
                           stderr=subprocess.PIPE)
     str_result = proc.stdout
     reg = re.match(r".*(<svg.*</svg>).*", str_result,
                    flags=re.DOTALL).group(1)
     return HttpResponse(reg, content_type="image/svg+xml")
예제 #9
0
 def documents_of_book(b):
     d_b = DatabaseBookDocuments.update_book_documents(b)
     d_b.to_file(b)
     return d_b.to_json()
예제 #10
0
 def get(self, request, book, document):
     book = DatabaseBook(book)
     documents = DatabaseBookDocuments().load(book)
     document: Document = documents.database_documents.get_document_by_id(
         document)
     return Response(document.to_json())