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()
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()
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")
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()
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" )
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)
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)
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")
def documents_of_book(b): d_b = DatabaseBookDocuments.update_book_documents(b) d_b.to_file(b) return d_b.to_json()
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())