Skip to content

Commit

Permalink
solved bible
Browse files Browse the repository at this point in the history
  • Loading branch information
AthulyaMS committed Jan 9, 2024
1 parent bfd1445 commit b5e9674
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 198 deletions.
16 changes: 9 additions & 7 deletions app/crud/nlp_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_project_tokens(db_:Session, project_id, books, sentence_id_range, senten
raise NotAvailableException(f"Project with id, {project_id}, not found")
sentences = projects_crud.obtain_project_source(db_, project_id, books, sentence_id_range,
sentence_id_list)
sentences = sentences['db_content']
# sentences = sentences['db_content']
args = {"db_":db_, "src_language":project_row.sourceLanguage, "sentence_list":sentences,
'trg_language':project_row.targetLanguage,
"use_translation_memory":use_translation_memory, "include_phrases":include_phrases,
Expand All @@ -93,12 +93,12 @@ def get_project_tokens(db_:Session, project_id, books, sentence_id_range, senten
args['stopwords'] = project_row.metaData['stopwords']
if "punctuations" in project_row.metaData:
args['punctuations'] = project_row.metaData['punctuations']
# return get_generic_tokens( **args)
response = {
'db_content':get_generic_tokens( **args),
'project_content':project_row
}
return response
return get_generic_tokens( **args)
# response = {
# 'db_content':get_generic_tokens( **args),
# 'project_content':project_row
# }
# return response

###################### Token replacement translation ######################
def replace_bulk_tokens_gloss_list(token_translations, updated_sentences):
Expand Down Expand Up @@ -895,6 +895,7 @@ def obtain_draft(sentence_list, doc_type):
return result
return None


def create_usfm(sent_drafts):
'''Creates minimal USFM file with basic markers from the input verses list
input: List of (bbbcccvvv, "generated translation")
Expand Down Expand Up @@ -931,6 +932,7 @@ def create_usfm(sent_drafts):
usfm_files.append(file)
return usfm_files


def export_to_print(sentence_list):
'''get a response with just id and draft to print'''
output_json = {}
Expand Down
25 changes: 15 additions & 10 deletions app/crud/projects_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def get_sentences_from_usfm_json(contents_list, book_code, book_id):
surrogate_id = book_code
found_split_verse = None
splits = []
print("contents_list",contents_list)
for node in contents_list:
if isinstance(node, str):
sent_id = book_id*1000000+int(curr_chap)*1000+verse_number_int
Expand Down Expand Up @@ -150,7 +151,8 @@ def get_sentences_from_usfm_json(contents_list, book_code, book_id):
def update_translation_project_uploaded_book(db_,project_obj,project_id,new_books,user_id):
"""bulk uploaded book update in update translation project"""
for usfm in project_obj.uploadedUSFMs:
usfm_parser = USFMParser(usfm)
# usfm_parser = USFMParser(usfm)
usfm_parser = USFMParser(utils.normalize_unicode(usfm))
# usfm_json = utils.parse_usfm(usfm)
usfm_json =usfm_parser.to_usj(include_markers=Filter.BCV+Filter.TEXT)
book_code = usfm_json['content'][0]['code'].lower()
Expand All @@ -159,6 +161,8 @@ def update_translation_project_uploaded_book(db_,project_obj,project_id,new_book
book_id = utils.BOOK_CODES[book_code.lower()]['book_num']
new_books.append(book_code)
draft_rows = get_sentences_from_usfm_json(usfm_json['content'], book_code, book_id)
print("draft_rows",draft_rows)
print("usfm_json['content']",usfm_json['content'])
for item in draft_rows:
db_.add(db_models.TranslationDraft(
project_id=project_id,
Expand Down Expand Up @@ -409,9 +413,9 @@ def obtain_project_draft(db_:Session, project_id, books, sentence_id_list, sente
draft_rows = draft_rows['db_content']
if output_format == schemas_nlp.DraftFormats.USFM :
draft_out = nlp_crud.create_usfm(draft_rows)
# elif output_format == schemas_nlp.DraftFormats.JSON:
# draft_out = nlp_crud.export_to_json(project_row.sourceLanguage,
# project_row.targetLanguage, draft_rows, None)
elif output_format == schemas_nlp.DraftFormats.JSON:
draft_out = nlp_crud.export_to_json(project_row.sourceLanguage,
project_row.targetLanguage, draft_rows, None)
elif output_format == schemas_nlp.DraftFormats.PRINT:
draft_out = nlp_crud.export_to_print(draft_rows)
else:
Expand Down Expand Up @@ -764,11 +768,12 @@ def obtain_project_source(db_:Session, project_id, books=None, sentence_id_range
"surrogateId":row.surrogateId,"sentence":row.sentence}
result.append(obj)

response = {
'db_content':result,
'project_content':project_row
}
return response
# response = {
# 'db_content':result,
# 'project_content':project_row
# }
# return response
return result

def remove_project_sentence(db_, project_id, sentence_id,user_id):
'''To remove a sentence'''
Expand All @@ -785,7 +790,7 @@ def remove_project_sentence(db_, project_id, sentence_id,user_id):
db_.delete(sentence_row)
project_row.updatedUser = user_id
project_row.updateTime = datetime.datetime.now(ist_timezone).strftime('%Y-%m-%d %H:%M:%S')
# db_.commit()
db_.commit()
response = {
"db_content": sentence_row,
"project_content": project_row
Expand Down
13 changes: 10 additions & 3 deletions app/test/test_agmt_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ def test_bugfix_split_n_merged_verse():
}
headers_auth['Authorization'] = "Bearer"+" "+initial_test_users['AgAdmin']['token']
response = client.post(UNIT_URL, headers=headers_auth, json=post_data)
print("RESPONSE1",response.json())
# print("RESPONSE1",response.json())
assert response.status_code == 201
assert response.json()['message'] == "Project created successfully"
project_id = response.json()['data']['projectId']
Expand All @@ -1341,12 +1341,19 @@ def test_bugfix_split_n_merged_verse():
}
prj_update_resp = client.put(UNIT_URL+'?project_id='+str(project_id),\
json=prj_book_data, headers=headers_auth)
print("RESPONSE2",prj_update_resp.json())
# print("RESPONSE2",prj_update_resp.json())
assert prj_update_resp.status_code == 201
resp_obj = prj_update_resp.json()
# print("RESPONSE3",resp_obj)
assert resp_obj['message'] == 'Project updated successfully'

# print("USFM Data:", prj_book_data)
# # print("Project Update Response:", resp_obj)
# for verse_content in prj_book_data["uploadedUSFMs"]:
# verses = verse_content.split('\n\\v ')
# for verse in verses[1:]: # Skip the first element as it contains metadata
# print("Processing Verse:", '\\v ' + verse)
# verse_parts = verse.split(' ') # Split by space to get individual components
# print("Verse Parts:", verse_parts)
sentences_resp = client.get(f"{SENTENCE_URL}?project_id={project_id}", headers=headers_auth)
assert sentences_resp.status_code == 200
sentences = sentences_resp.json()
Expand Down
Loading

0 comments on commit b5e9674

Please sign in to comment.