def update(self, text=Text()): """ (Text) -> (Text) Update database text """ session = self.session_factory() textDB = session.query(TextDB).filter_by(id=text.id).first() dic = {} if (textDB.language != text.language): dic['language'] = text.language if (textDB.plant != text.plant): dic['plant'] = text.plant if (textDB.status != text.status): dic['status'] = text.status if (textDB.attribute != text.attribute): dic['attribute'] = text.attribute if (textDB.value != text.value): dic['value'] = text.value if (textDB.reference != text.reference): dic['reference'] = text.reference if (dic != {}): session.query(TextDB).filter_by(id=text.id).update(dic) session.commit() session.flush() session.refresh(textDB) return Text(textDB.id, textDB.language, textDB.plant, textDB.status, textDB.attribute, textDB.value, textDB.reference)
def create(self, text=Text()): """ (Image) -> (Image) Add image to database """ textDB = TextDB(text=text) session = self.session_factory() session.add(textDB) session.flush() session.refresh(textDB) session.commit() return Text(textDB.id, textDB.language, textDB.tag, textDB.value, textDB.description)
def create(self, text=Text()): """ (Image) -> (Image) Add image to database """ textDB = TextDB(text=text) session = self.session_factory() session.add(textDB) session.flush() session.refresh(textDB) session.commit() return Text(textDB.id, textDB.language, textDB.plant, textDB.status, textDB.attribute, textDB.value, textDB.reference)
def searchByID(self, textId): """ (Int) -> (Text) """ session = self.session_factory() textDB = session.query(TextDB).get(textId) return Text(textDB.id, textDB.language, textDB.tag, textDB.value, textDB.description)
def codage_huffman(list_traite): dictForHuffman = Text.getDictByASCII() dictValues = list(dictForHuffman.values()) minProba = min(list(filter(lambda a: a != 0.0, dictValues))) for key in dictForHuffman: if dictForHuffman[key] == 0.0 or dictForHuffman[key] == 0: dictForHuffman[key] = minProba codage_huffman(dictForHuffman)
def searchByID(self, textId): """ (Int) -> (Text) """ session = self.session_factory() textDB = session.query(TextDB).get(textId) return Text(textDB.id, textDB.language, textDB.plant, textDB.status, textDB.attribute, textDB.value, textDB.reference)
def search(self, text=Text(), pageSize=10, offset=0): """ (Text, pageSize, offset) -> [Text] """ session = self.session_factory() query = session.query(TextDB).filter( and_(TextDB.language.like('%' + text.language + '%'), TextDB.tag.like('%' + text.tag + '%'), TextDB.value.like('%' + text.value + '%'), TextDB.description.like('%' + text.description + '%'))) content = query.slice(offset, pageSize).all() total = query.count() texts = [] for textDB in content: texts.append( Text(textDB.id, textDB.language, textDB.tag, textDB.value, textDB.description)) return {'total': total, 'content': texts}
def search(self, text=Text(), pageSize=10, offset=0): """ (Text, pageSize, offset) -> [Text] """ session = self.session_factory() query = session.query(TextDB).filter( and_(TextDB.language.like('%' + text.language + '%'), TextDB.plant.like('%' + text.plant + '%'), TextDB.status.like('%' + text.status + '%'), TextDB.attribute.like('%' + text.attribute + '%'), TextDB.value.like('%' + text.value + '%'), TextDB.reference.like('%' + text.reference + '%'))) content = query.slice(offset, pageSize).all() total = query.count() texts = [] for textDB in content: texts.append( Text(textDB.id, textDB.language, textDB.plant, textDB.status, textDB.attribute, textDB.value, textDB.reference)) return {'total': total, 'content': texts}
def delete(self, text=Text()): """ (Text) -> (bool) Delete database text """ status = False session = self.session_factory() textDB = session.query(TextDB).filter_by(id=text.id).first() session.delete(textDB) session.commit() session.flush() if (not session.query(TextDB).filter_by(id=textDB.id).count()): status = True session.close() return status
def update(self, text=Text()): """ (Text) -> (Text) Update database text """ session = self.session_factory() textDB = session.query(TextDB).filter_by(id=text.id).first() dic = {} if (textDB.language != text.language): dic['language'] = text.language if (textDB.tag != text.tag): dic['tag'] = text.tag if (textDB.value != text.value): dic['value'] = text.value if (textDB.description != text.description): dic['description'] = text.description if (dic != {}): session.query(TextDB).filter_by(id=text.id).update(dic) session.commit() session.flush() session.refresh(textDB) return Text(textDB.id, textDB.language, textDB.tag, textDB.value, textDB.description)
dictForHuffman = Text.getDictByASCII() dictValues = list(dictForHuffman.values()) minProba = min(list(filter(lambda a: a != 0.0, dictValues))) for key in dictForHuffman: if dictForHuffman[key] == 0.0 or dictForHuffman[key] == 0: dictForHuffman[key] = minProba codage_huffman(dictForHuffman) def codage_arithmetique(dict_pixel_proba, list_length): pass if __name__ == '__main__': # transform text to ascii Text.transformationText() # genere 3 dictionnaire en fonction des unigramme, digramme et trigramme dicoUnigram = Text.generer_dico_ngramme(1) dicoDigram = Text.generer_dico_ngramme(2) dicoTrigram = Text.generer_dico_ngramme(3) print(len(dicoUnigram)) print(len(dicoDigram)) print(len(dicoTrigram)) # associe un byte à un n_gramme dans un nouveau dictionnaire dicoNgram = Text.creerDictionnaire(dicoUnigram, dicoDigram[:100], dicoTrigram[:98]) print(len(dicoNgram)) finalDictionnary = Text.generateByteList(dicoNgram) print(finalDictionnary) newText = Text.encode(finalDictionnary)