Skip to content

Commit

Permalink
Fixed a bug where row mapper variable wouldn't be anything when only …
Browse files Browse the repository at this point in the history
…one word in entity. Now will choose lowercase entity if one word, else take first characters of both words. Fixed issue if first row of data had empty cells, variable would assume integer. Now scans until it has a full line of data.
  • Loading branch information
majora2007 committed May 4, 2020
1 parent b125ad8 commit 9362fbc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ N.B. This code is pretty messy, I wrote this in 2 hours. Don't judge.
Build:
pyinstaller --onefile --add-data "templates/*.*;./templates" --add-data "words.txt;." easyjava.py

BUGS:
- first_chars is returning the first word. Which works but not when there is only 1 word
7 changes: 6 additions & 1 deletion easyjava.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def parse_data(data_file):
header = lines[0].split('|')
print(header)

line_data = lines[1].split('|')
line_data = []
for idx, cell in enumerate(lines):
line_data = [c for c in lines[idx].split('|') if c != '' and c != ' ']
if len(line_data) is len(lines[0]):
break

for idx, cell in enumerate(line_data):
types.append(TypeInfo(parse.parse_type(cell, header[idx]), camel_case(header[idx]), header[idx]))

Expand Down
16 changes: 10 additions & 6 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ def camel_case(s):
def first_chars(s):
""" Returns first characters combined of string. ApplicationGroup returns ag """
words = viterbi_segment(s.lower())[0]
end = len(words) - 1
return ''.join(words[0:end])
end = (len(words) - 1) or 1
if len(words) is 1:
return ''.join(words[0:end])
else:
return ''.join([a[0] for a in words])

def spinal_case(s):
sentence = ' '.join(viterbi_segment(s.lower())[0])
Expand All @@ -75,10 +78,11 @@ def spinal_case(s):


if __name__ == '__main__':
print(viterbi_segment('ACTIONITEMIMPACTID'.lower()))

sentence = ' '.join(viterbi_segment('ACTIONITEMIMPACTID'.lower())[0])
""" sentence = ' '.join(viterbi_segment('ACTIONITEMIMPACTID'.lower())[0])
print('sentence: {0}'.format(sentence))
word = ''.join(a.capitalize() for a in split('([^a-zA-Z0-9])', sentence)
if a.isalnum())
print('word: {0}'.format(word[0].lower() + word[1:]))
print('word: {0}'.format(word[0].lower() + word[1:])) """

print('application: {0}'.format(first_chars('application')))
print('applicationgroup: {0}'.format(first_chars('applicationgroup')))

0 comments on commit 9362fbc

Please sign in to comment.