0% found this document useful (0 votes)
8 views

Code

trt

Uploaded by

Hemn Dasky
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Code

trt

Uploaded by

Hemn Dasky
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

# Define vocabulary dictionaries

english_to_kurdish = {
"I": "‫"من‬,
"you": "‫"تۆ‬,
"he": "‫"ئەو‬,
"she": "‫"ئەو‬,
"it": "‫"ئەو‬,
"we": "‫"ئێمە‬,
"they": "‫"ئەوان‬,
"eat": "‫"خواردن‬,
"drink": "‫"خواردن‬,
"apple": "‫"سێو‬,
"water": "‫"ئاو‬,
"book": "‫"کتێب‬,
"read": "‫"خوێندن‬,
"write": "‫"نووسین‬,
"go": "‫"چوون‬,
"come": "‫"هاتن‬,
"school": "‫"قوتابخانە‬,
"house": "‫"خانوو‬,
"happy": "‫"دڵخۆش‬,
"intelligent": "‫"زیرەک‬,
"story": "‫"چیرۆک‬,
"from": "‫"لە‬,
"to": "‫"بۆ‬,
"the": "‫"ی‬,
"a": "‫"ێک‬,
"an": "‫"ێک‬,
"do": "‫"کردن‬,
"does": "‫"کردن‬,
"not": "‫"نا‬,
"is": "‫"ە‬,
"am": "‫"م‬,
"are": "‫"ن‬,
"more": "‫"تر‬,
"most": "‫"ترین‬,
"this": "‫"ئەم‬,
"that": "‫"ئەو‬,
"these": "‫"ئەمانە‬,
"those": "‫"ئەوانە‬,
"they": "‫"ئەوان‬,
"water?": "‫"ئاو‬,
"apple?": "‫"سێو‬,
"book?": "‫"کتێب‬,
"houses":"‫"خانى‬,
"apples": "‫"سيف‬

kurdish_to_english = {v: k for k, v in english_to_kurdish.items()}

# Define verb conjugation rules


verb_conjugations = {
"present": {
"i": "‫"م‬,
"you": "‫"یت‬,
"he": "‫"ێت‬,
"she": "‫"ێت‬,
"it": "‫"ێت‬,
"we": "‫"ین‬,
"they": "‫"ن‬
},
"past": {
"i": "‫"م‬,
"you": "‫"ت‬,
"he": "‫"ی‬,
"she": "‫"ی‬,
"it": "‫"ی‬,
"we": "‫"مان‬,
"they": "‫"یان‬
},
"future": {
"i": "‫"م‬,
"you": "‫"یت‬,
"he": "‫"ێت‬,
"she": "‫"ێت‬,
"it": "‫"ێت‬,
"we": "‫"ین‬,
"they": "‫"ن‬
}
}

pronouns = {
"personal": {
"bound": {
"i": "-‫"م‬,
"you": "-‫"ت‬,
"he": "-‫"ی‬,
"she": "-‫"ی‬,
"it": "-‫"ی‬,
"we": "-‫"مان‬,
"they": "-‫"یان‬
},
"independent": {
"i": "‫"من‬,
"you": "‫"تو‬,
"he": "‫"ئەو‬,
"she": "‫"ئەو‬,
"it": "‫"ئەو‬,
"we": "‫"ئێمە‬,
"they": "‫"ئەوان‬
}
},
"demonstrative": {
"this": "‫"ئەمە‬,
"that": "‫"ئەوە‬,
"these": "‫"ئەمانە‬,
"those": "‫"ئەوانە‬
}
}

noun_suffixes = {
"absolute": "",
"indefinite": "‫"ێک‬,
"definite": "-‫"ی‬,
"possessive": {
"i": "-‫"م‬,
"you": "-‫"ت‬,
"he": "-‫"ی‬,
"she": "-‫"ی‬,
"it": "-‫"ی‬,
"we": "-‫"مان‬,
"they": "-‫"یان‬
}
}

def conjugate_verb(subject, verb, tense="present", negation=False):


if verb not in english_to_kurdish:
return verb # Return the verb as is if it's not in the dictionary

kurdish_verb = english_to_kurdish[verb]

# Special case for "be" verb and handling "do"


if verb in ["is", "am", "are"]:
conjugation_suffix = verb_conjugations[tense][subject.lower()]
return conjugation_suffix
# If it's "do" or "does", no need for conjugation
elif verb in ["do", "does"]:
return "" # Return empty string since "do" has no Kurdish equivalent in
this context

conjugation_suffix = verb_conjugations[tense][subject.lower()]
negation_prefix = "‫ "نا‬if negation else ""

return f"{negation_prefix}{kurdish_verb}{conjugation_suffix}"

def translate_to_kurdish(sentence, tense="present"):

words = sentence.split()
# Handle questions starting with "Do" or "Does"
if words[0].lower() in ["do", "does"]:
subject = words[1].lower()
verb = words[2].lower() if len(words) > 2 else None
obj_words = words[3:] if len(words) > 3 else []
# Check for negation in questions
negation = "not" in words
else:
subject = words[0].lower()
verb = words[1].lower()
obj_words = words[2:]
# Check for negation in declarative sentences
negation = "not" in words
# Translate subject
subject_kurdish = english_to_kurdish.get(subject, subject)

subject_kurdish = pronouns["personal"]["independent"].get(subject, subject)

# Apply noun suffixes (example for indefinite nouns)


if "a" in obj_words or "an" in obj_words:
obj_index = obj_words.index("a") if "a" in obj_words else
obj_words.index("an")
noun = obj_words[obj_index + 1]

# Translate verb and conjugate it


verb_kurdish_conjugated = conjugate_verb(subject, verb, tense=tense,
negation=negation)

# Handle "do" separately


if verb in ["do", "does"]:
if obj_words and obj_words[0] in english_to_kurdish:
verb = obj_words.pop(0)
else:
return f"{subject_kurdish} {english_to_kurdish.get(verb, verb)}"

# Translate verb and conjugate it


verb_kurdish_conjugated = conjugate_verb(subject, verb, tense=tense,
negation=negation)

# Translate object words


obj_kurdish = [english_to_kurdish.get(word.lower(), word) for word in
obj_words]

# Construct the final Kurdish sentence


kurdish_sentence = f"{subject_kurdish} {' '.join(obj_kurdish)}
{verb_kurdish_conjugated}"

return kurdish_sentence.strip()

# Function to translate from Kurdish to English


def translate_to_english(sentence):
words = sentence.split()
translated_words = []
for word in words:
if word in kurdish_to_english:
translated_words.append(kurdish_to_english[word])
elif word.endswith("‫)"ەکە‬:
# Handle definite article
base_word = word[:-2]
if base_word in kurdish_to_english:
translated_words.append("the")
translated_words.append(kurdish_to_english[base_word])
elif word.endswith("‫)"ێک‬:
# Handle indefinite article
base_word = word[:-2]
if base_word in kurdish_to_english:
translated_words.append("a")
translated_words.append(kurdish_to_english[base_word])
elif word.endswith("‫)"تر‬:
# Handle comparatives
base_word = word[:-2]
if base_word in kurdish_to_english:
translated_words.append("more")
translated_words.append(kurdish_to_english[base_word])
elif word.endswith("‫)"ترین‬:
# Handle superlatives
base_word = word[:-4]
if base_word in kurdish_to_english:
translated_words.append("most")
translated_words.append(kurdish_to_english[base_word])
elif word.startswith("‫)"نا‬:
# Handle negation
neg_word = word[2:]
if neg_word in kurdish_to_english:
translated_words.append("not")
translated_words.append(kurdish_to_english[neg_word])
else:
translated_words.append(word)

translated_sentence = " ".join(translated_words)

return translated_sentence

# Test the updated translation functions


english_sentences = [
"I eat the apple",
"You drink water",
"He reads a book",
"She writes this story",
"We go to that school",
"They come from those houses",
"I am more happy",
"You are the most intelligent",
"He does not eat apples",
"Do they drink water?"
]
for sentence in english_sentences:
kurdish_sentence = translate_to_kurdish(sentence, tense="present") # Pass
tense
print(f"English: {sentence}")
print(f"Kurdish: {kurdish_sentence}")
translated_sentence = translate_to_english(kurdish_sentence)
print(f"Translated: {translated_sentence}\n")

You might also like