Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code to Change Words to LowerCase #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mepripri
Copy link

No description provided.

@Tanvipatel23
Copy link

new Locale(language)
new Locale(language, country)
new Locale(language, country, variant)

class JavaCharactertoLowerCaseExample1 {
public static void main(String[] args) {

	String s2 = Normalizer.normalize(s, Normalizer.Form.NFD);
		return s2.replaceAll("(?s)\\p{InCombiningDiacriticalMarks}", "");

 char ch1, ch2, ch3, ch4;    
  ch1 = 'TANVI';  
  ch2 = 'PATEL';  
    
  ch3 = Character.toLowerCase(ch1);  
  ch4 = Character.toLowerCase(ch2);  
  String str1 = "The lowercase for the first character '" + ch1 + "' is given as: " + ch3;  
  String str2 = "The lowercase for the second character '" + ch2 + "' is given as: " + ch4;  

  System.out.println( str1 );  
  System.out.println( str2 );  
  }  

}

String myString="YAŞAT Patel";
Locale trlocale= new Locale("tr-TR");
Locale enLocale = new Locale("en_US");

Log.v("mainlist", "en source: " +myString.toLowerCase(enLocale));
Log.v("mainlist", "tr source: " +myString.toLowerCase(trlocale));

@@ -0,0 +1,49 @@
import csv

def splitLang(l):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is great for getting the first part of the language input, but we should make l a little more descriptive in terms of the variable name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i will work on the variable name.

lang=splitLang(lang)
if lang=='tr' or lang=='az':
for i in s:
if ord(i)==73:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this may work, I think the use of hard coded numbers is not ideal. Maybe if the function merely searches for 'I' instead of using ord() that would be a little clearer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that also perfect that will be a direct search.

str+=chr(962)
else:
str=str+s.lower()
elif lang=='zh' or lang=='th' or lang=='ja' or lang=='en':
Copy link

@thofstrand thofstrand Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to specify these four languages, as anything else would be just lower cased. So this could just be an else:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, i also have a non-language condition there. To solve this I can add that condition in elif and make the rest as else. This will be more better.

str=str+s.lower()
elif lang=='zh' or lang=='th' or lang=='ja' or lang=='en':
str+=s.lower()
else:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this as any other language is just lower cased.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to the above one I guess

first=1
else:
str+=s[i].lower()
elif i==1 and first==1:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the elif at line 28 is doing. This may be omitted as it doesn't appear to do anything as of this moment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This elif condition is actually working as a flag. I will try to look into the code again, if this can be avoided.

@@ -1,18 +1,29 @@
HELLO en hello
WORLD en-US world
WORLD eng-US Invalid Language

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eng would likely produce an invalid language type, but it could also just be lower cased since any other language that is not of the ones specified is just lowered.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added because this doesn't fit in the language requirement. If any language is greater than or less than 2 letters will be an invalid language.

Copy link

@thofstrand thofstrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this code looks good and you added a decent number of test cases. There is room for improvement in terms of readability and some unnecessary lines. Well done!

@mepripri mepripri requested a review from thofstrand February 17, 2023 21:21
@mepripri
Copy link
Author

I have made the changes to the code. @thofstrand, Can you please review them again

import csv

def splitLang(lang):
lang=lang.split('-')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but I don't really like the change of type here from str to list.

if lang=='tr' or lang=='az':
for i in s:
if i=='I':
str+=chr(305)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number.

str+=i.lower()
elif lang=='ga':
if (s[0]=='n' or s[0]=='t') and s[1] in ['A','E','I','O','U','Á','É','Í','Ó','Ú']:
str+=s[0].lower()+'-'+s[1:].lower()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s[0] already lowercase here?

else:
str+=s.lower()
elif lang=='el':
if ord(s[-1])==931:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic numbers — unreadable.

str+=chr(962)
else:
str=str+s.lower()
elif len(lang)!=2:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the BCP-47 spec. Language codes can have 2 or 3 letters.

else:
str=str+s.lower()
elif len(lang)!=2:
str+='Invalid Language'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should raise an exception here, not return an error string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants