def post(self,request,*args,**kwargs): foundPersons=[] givenTerm=request.POST.get('givenTerm') searchBy=request.POST.get('searchBy') if searchBy=='serial_number': '''Search By Serial Number''' try: givenSN=int(givenTerm) a=Person.objects.filter(person_id=givenSN) foundPersons=[person for person in a] except:pass elif searchBy=='name': '''Search By Name''' try: import nepali_roman as nr foundPersons=[person for person in Person.objects.all() if nr.romanize_text(givenTerm).lower() in nr.romanize_text(person.full_name).lower()] except:pass elif searchBy=='batch_no': '''Search By batch no''' try: givenBatchNo=int(givenTerm) foundPersons=[person for person in Person.objects.filter(batch_no=givenBatchNo)] except:pass elif searchBy=='phone_number': '''Search By phone_number''' try: foundPersons=[person for person in Person.objects.all() if givenTerm in person.contact_number] except:pass elif searchBy=='grandfather': '''Search By Grandfather Name''' try: import nepali_roman as nr foundPersons=[] for person in Person.objects.all(): try: if givenTerm.lower()==nr.romanize_text(person.father.father.full_name).lower(): foundPersons.append(person) except:pass except:pass return render(request,peoples_table_template,{"persons":foundPersons})
def save(self, *args, **kwargs): childUpdateOnly = False suggestionUpdateOnly = False if "childUpdateOnly" in args: childUpdateOnly = True if "suggestionUpdateOnly" in args: suggestionUpdateOnly = True self.full_name_romanized = nr.romanize_text(self.full_name).lower() super(Person, self).save() if (not childUpdateOnly and not suggestionUpdateOnly): if self.father: self.batch_no = self.father.batch_no + 1 if self.father.batch_no else 1 max_person_id = Person.objects.all().aggregate( Max('person_id'))['person_id__max'] self.person_id = max_person_id if max_person_id > 0 else 0 self.same_vamsha = True super(Person, self).save( update_fields=["batch_no", "person_id", "same_vamsha"]) parent = self.father elif self.mother: self.batch_no = self.mother.batch_no + 1 if self.mother.batch_no else 1 self.same_vamsha = False self.person_id = 0 super(Person, self).save(update_fields=["person_id", "same_vamsha"]) parent = self.mother else: pass '''Update the father -> children field with self id''' try: parent_children = parent.children if parent.children else {} parent_children.update({self.id: self.full_name}) parent.children = parent_children parent.save("childUpdateOnly", update_fields=["children"]) except Exception as e: pass if (suggestionUpdateOnly): suggestion = None person_suggestions = self.suggestions if self.suggestions else {} for key, value in kwargs.items(): if key == "suggestion": suggestion = value if (suggestion): person_suggestions.update( {suggestion['suggester_name']: { 0: suggestion }}) self.suggestions = person_suggestions super(Person, self).save(update_fields=["suggestions"]) else: pass
def accounts(num=5): for _ in range(num): city_name = nr.romanize_text(f.city_name()) street_name = nr.romanize_text(f.street_address()) postcode = f.postcode() name = '{} {}'.format( nr.romanize_text(f.first_name()).capitalize(), nr.romanize_text(f.last_name()).capitalize()) email = name.replace(' ', '_') + '@gmail.com' addr = '{}, {}-{}'.format(street_name, city_name, postcode) phone_number = '+91' + str(f.random_number(10)) print(name, phone_number, email) print(addr) obj = CustomUser( email=email, password='******', name=name, mobile_number=phone_number, job='NA', address=addr, ) obj.save()
def spacy_predicter(text): return_arr = [] nlp = spacy.load(R".\output\model-best") new_inp = text new_data = nr.romanize_text(new_inp) new_data = new_data.strip(" ") filt_data = nepali_word_filter(new_data) doc = nlp(filt_data) entitities = doc.ents for ent in doc.ents: ent_dict = { 'text': ent.text, 'start_index': ent.start_char, 'end_index': ent.end_char, 'entity': ent.label_ } return_arr.append(ent_dict)
def text_finder(link): num_array = [] gh = link new_text = nr.romanize_text(link) new_text = nepali_word_filter(new_text) top = new_text.split(" ") threshold = 0.80 for key in new_arr: for word in top: try: res = cosdis(word2vec(word), word2vec(key)) if res != False: if res > threshold: pattern = re.compile(rf'{key}[a-z]+') if pattern.match(word): new_text = re.sub(pattern, key, new_text) except IndexError: pass for i in new_text.split(" "): if i in new_arr: res = [[ele.start(), ele.end() - 1] for ele in re.finditer(rf"{i}", new_text)] blo = [txt for txt in re.finditer(rf"{i}", new_text)] if num_array == None: num_array = res else: for j in res: if j not in num_array: num_array.append(j) m = sorted(num_array) word_value = word_indent(m) if word_value != []: app_arr = [new_text, word_value] global_arr.append(app_arr) return word_value