The examples below demonstrates the usage of the GrammarMain class to correct an informal Sinhala sentence into a formal one.
If a sentence starts with “මම” or “මා” in present tense, it should end with “මි”.
Consider the following code segment:
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "මා සතුන්ට දානයක් දෙන්න හිතන් ඉන්නවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
මම සතුන්ට දානයක් දෙන්න හිතන් ඉන්නෙමි
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "මා සතුන්ට දානයක් දෙන්න හිතන් ඉන්වා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
මම සතුන්ට දානයක් දෙන්න හිතන් ඉන්නෙමි
If a sentence starts with “අප” or “අපි” in present tense, it should end with “මු”.
Consider the following code segment:
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "අපි පොසොන් පෝයට දන්සලක් සංවිධානය කරනවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
අපි පොසොන් පෝයට දන්සලක් සංවිධානය කරමු
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "අපි පොසොන් පෝයට දන්සලක් සංවිධානය කරවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
අපි පොසොන් පෝයට දන්සලක් සංවිධානය කරමු
If a sentence starts with “මම” or “මා” in future tense, it should end with “න්නෙමි” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "මම මේ ටික හොඳට බලන් කියලා දෙන්නම්"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
මම මේ ටික හොඳට බලන් කියලා දෙන්නෙමි
If a sentence starts with “අප” or “අපි” in future tense, it should end with “න්නෙමු” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "අප හෙට මේ වෙලාවට නිදාගෙන හිඳීවි"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
අපි හෙට මේ වෙලාවට නිදාගෙන හිඳන්නෙමු
If a sentence starts with “මම” or “මා” in past tense, it should end with “ෙමි” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "මා කෝප්පෙන් වතුර බිව්වා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
මම කෝප්පෙන් වතුර බිව්වෙමි
If a sentence starts with “අප” or “අපි” in past tense, it should end with “ෙමු” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "අපි කෑම කෑවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
අපි කෑම කෑවෙමු
If a sentence starts with “ඇය” or “ඈ” in present tense, it should end with “යි” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඇය පිටිසර පාසලක උත්සහයෙන් උගන්වනවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඇය පිටිසර පාසලක උත්සහයෙන් උගන්වයි
If a sentence starts with “ඇය” or “ඈ” in past tense, it should end with “ය” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඇය මල් නෙලුවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඇය මල් නෙලුවාය
If a sentence starts with “ඔහු” in present tense, it should end with “යි” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔහු ඉතා ආදරයෙන් දෙමාපියන් නමදිනවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔහු ඉතා ආදරයෙන් දෙමාපියන් නමදියි
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔහු ඉතා ආදරයෙන් දෙමාපියන් නමදිනව"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔහු ඉතා ආදරයෙන් දෙමාපියන් නමදියි
If a sentence starts with “ඔහු” in past tense, it should end with “ේය” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔහු මල් නෙලුවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔහු මල් නෙලුවේය
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔහු මල් නෙලුව"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔහු මල් නෙලුවේය
If a sentence starts with “ඔවුන්” or “ඔවුහු” in present tense, it should end with “ති” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔවුන් නොයෙක් ආකාරයේ ඇඳුම් මහනවාලු"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔවුන් නොයෙක් ආකාරයේ ඇඳුම් මහති
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔවුන් නොයෙක් ආකාරයේ ඇඳුම් මහනව"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔවුන් නොයෙක් ආකාරයේ ඇඳුම් මහති
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔවුහු නොයෙක් ආකාරයේ ඇඳුම් මහනව"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔවුහු නොයෙක් ආකාරයේ ඇඳුම් මහති
If a sentence starts with “ඔවුන්” or “ඔවුහු” in past tense, it should end with “ෝය” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔවුන් හවස් වී ගෙදර ගියා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔවුන් හවස් වී ගෙදර ගියෝය
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ඔවුහු හවස් වී ගෙදර ගියා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ඔවුහු හවස් වී ගෙදර ගියෝය
If a sentence starts with “තී” or “තෝ” or “ඔබ” or “නුඹ” in past tense, it should end with “ෙහි” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "තී මල් කැඩුවද"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
තී මල් කැඩුවෙහි
If a sentence starts with “තෙපි” or “තොපි” in past tense, it should end with “ෙහු” according to the tense and verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "තොපි ආහාර ලෑස්ති කරාද"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
තොපි ආහාර ලෑස්ති කරෙහු
If a sentence starts with a plural subject in present tense, it should end with a plural verb in present tense.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ගොවියෝ මහන්සි වී රටට සහල් සපයනවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ගොවියෝ මහන්සි වී රටට සහල් සපයති
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ගොවියෝ මහන්සි වී රටට සහල් සපයන"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ගොවියෝ මහන්සි වී රටට සහල් සපයති
If a sentence starts with a plural subject in past tense, it should end with a plural verb in past tense.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "ගුරුවරු පිටතට පැමිණ සිටියා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
ගුරුවරු පිටතට පැමිණ සිටියෝය
If a sentence starts with a singular subject in present tense, it should end with a singular verb.
from sinlingua.grammar_rule.grammar_main import GrammarMain
# Create an instance of GrammarMain
obj = GrammarMain()
# Original informal sentence
sentence = "දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ගන්නවා"
# Apply grammar correction
corrected_sentence = obj.mapper(sentence=sentence)
print(corrected_sentence)
Output:
දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ගනියි
There is a way to suggest the appropriate word for a given sentence.
Provide the most appropriate suggestion
Consider the following code segment:
from sinlingua.grammar_rule.LLM_config import LLMConfig
# Create an instance of GrammarMain
obj = LLMConfig()
# Original informal sentence
sentence = "දරුවා වෙහෙස මහන්සියෙන් ඉගෙන <mask>"
sequence, token_str = obj.berto_predict(sentence=sentence)
print(f"Sequence: {sequence}")
print(f"Token String: {token_str}")
Output:
Sequence: දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ඇත
Token String: ඇත
Provide more than one appropriate suggestions(upto 5 suggestions)
Consider the following code segment:
from sinlingua.grammar_rule.LLM_config import LLMConfig
# Create an instance of GrammarMain
obj = LLMConfig()
# Original informal sentence
sentence = "දරුවා වෙහෙස මහන්සියෙන් ඉගෙන <mask>"
out = obj.berto_predict_top(sentence=sentence)
for p in out:
print(*p)
Output:
දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ඇත ඇත
දරුවා වෙහෙස මහන්සියෙන් ඉගෙනේ. ේ.
දරුවා වෙහෙස මහන්සියෙන් ඉගෙන... ...
දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ඒමට ඒමට
දරුවා වෙහෙස මහන්සියෙන් ඉගෙන ඒම ඒම