def import_andalusian_elements(request): message="" if request.method == 'POST': form = forms.CsvAndalusianForm(request.POST, request.FILES) if form.is_valid(): transliterator = ALA_LC_Transliterator() vocalizer=TashkeelClass() csv_file = form.cleaned_data['csv_file'] reader = csv.reader(csv_file.read().splitlines()) klass = None if form.cleaned_data['elem_type'] == 'tabs': klass = andalusian.models.Tab elif form.cleaned_data['elem_type'] == 'nawbas': klass = andalusian.models.Nawba elif form.cleaned_data['elem_type'] == 'forms': klass = andalusian.models.Form elif form.cleaned_data['elem_type'] == 'mizans': klass = andalusian.models.Mizan if klass: for row in reader: elem, created = klass.objects.get_or_create(name = row[0].decode('utf8')) voc = vocalizer.tashkeel(row[0].decode('utf8')) tr = transliterator.do(voc.strip()) elem.transliterated_name = arabic_reshaper.reshape(tr) elem.save() message = "The elements has been successfully loaded" else: form = forms.CsvAndalusianForm() params = {"form": form, "message": message} return render(request, "dashboard/load_csv.html", params)
def import_andalusian_catalog(request): message="" if request.method == 'POST': form = forms.CsvAndalusianCatalogForm(request.POST, request.FILES) if form.is_valid(): transliterator = ALA_LC_Transliterator() vocalizer=TashkeelClass() omited = 0 csv_file = form.cleaned_data['csv_file'] reader = csv.reader(csv_file.read().splitlines()) next(reader) for row in reader: genre = row[0] rec_mbid = row[11] nawba = row[14] tab = row[15] form = row[16] mizan = row[17] if rec_mbid: section_start = row[18] section_end = row[19] genre, created = andalusian.models.Genre.objects.get_or_create(name = genre.decode('utf8')) rec = andalusian.models.Recording.objects.get(mbid = rec_mbid) sec, created = andalusian.models.Section.objects.get_or_create(recording=rec, start_time=section_start, end_time=section_end) tab = andalusian.models.Tab.objects.get(name=tab.decode('utf8')) form = andalusian.models.Form.objects.get(name=form.decode('utf8')) nawba = andalusian.models.Nawba.objects.get(name=nawba.decode('utf8')) mizan = andalusian.models.Mizan.objects.get(name=mizan.decode('utf8')) voc = vocalizer.tashkeel(row[0].decode('utf8')) tr = transliterator.do(voc.strip()) genre.transliterated_name = arabic_reshaper.reshape(tr) genre.save() voc = vocalizer.tashkeel(rec.title) tr = transliterator.do(voc.strip()) rec.transliterated_title = arabic_reshaper.reshape(tr) rec.genre = genre rec.save() sec.mizan = mizan sec.tab = tab sec.form = form sec.nawba = nawba sec.save() else: omited += 1 message = "The elements has been successfully loaded" if omited: message += "(%d rows omited)" % omited else: form = forms.CsvAndalusianCatalogForm() params = {"form": form, "message": message} return render(request, "dashboard/load_catalog_csv.html", params)
import tashkeel.tashkeel as tashkeel def reshape(text): """Reshapes arabic in order to display characters from right to left """ if platform.system() == "Darwin": return text else: reshaped_text = arabic_reshaper.reshape(text) bidi_text = get_display(reshaped_text) return bidi_text if __name__ == '__main__': f = codecs.open("example_arabic_script.dat", "r", "utf-8") transliterator = ALA_LC_Transliterator() for line in f: print("--------------Original Text--------------") text = line.strip() print(reshape(text)) print("--------------Vocalized Text--------------") vocalizer = tashkeel.TashkeelClass() voc = vocalizer.tashkeel(text) print(reshape(voc)) print("--------------Transliterated Text--------------") tr = transliterator.do(voc.strip()) print(reshape(tr)) print("#########################################") f.close()
sys.path.append('mishkal/lib/') import tashkeel.tashkeel as tashkeel def reshape(text): """Reshapes arabic in order to display characters from right to left """ if platform.system() == "Darwin": return text else: reshaped_text = arabic_reshaper.reshape(text) bidi_text = get_display(reshaped_text) return bidi_text if __name__ == '__main__': f = codecs.open("example_arabic_script.dat", "r", "utf-8") transliterator = ALA_LC_Transliterator() for line in f: print("--------------Original Text--------------") text = line.strip() print(reshape(text)) print("--------------Vocalized Text--------------") vocalizer=tashkeel.TashkeelClass() voc = vocalizer.tashkeel(text) print(reshape(voc)) print("--------------Transliterated Text--------------") tr = transliterator.do(voc.strip()) print(reshape(tr)) print("#########################################") f.close()