Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
phonological_error_python
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-025
phonological_error_python
Commits
8d2c463f
Commit
8d2c463f
authored
Oct 27, 2023
by
KMaleesha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update python backend.
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
0 deletions
+176
-0
BackCodes.py
BackCodes.py
+96
-0
DataSet.xlsx
DataSet.xlsx
+0
-0
FlutterAPI_Word.py
FlutterAPI_Word.py
+80
-0
No files found.
BackCodes.py
0 → 100644
View file @
8d2c463f
import
pandas
as
pd
import
difflib
# Read data
df
=
pd
.
read_excel
(
'DataSet.xlsx'
)
def
find_most_similar_word
(
input_word
,
word_list
):
similarities
=
difflib
.
get_close_matches
(
input_word
,
word_list
)
return
similarities
[
0
]
if
similarities
else
None
def
find_different_letters
(
input_word
,
similar_word
):
differences
=
[]
for
char1
,
char2
in
zip
(
input_word
,
similar_word
):
if
char1
!=
char2
:
differences
.
append
(
char1
)
return
''
.
join
(
differences
)
# Input word
input_word
=
input
()
most_similar_word
=
find_most_similar_word
(
input_word
,
df
[
'words'
])
if
most_similar_word
:
# Find different letters
different_letters
=
find_different_letters
(
input_word
,
most_similar_word
)
print
(
"User Input:"
,
input_word
)
print
(
"Most Match:"
,
most_similar_word
)
else
:
print
(
"No similar word found in the dataset."
)
user_input
=
input_word
candidate_words
=
[
most_similar_word
]
# Function to find differing letters
def
find_differing_letters
(
input_word
,
candidate_word
):
differing_letters
=
list
(
difflib
.
ndiff
(
input_word
,
candidate_word
))
differing_letters
=
[
char
[
2
]
for
char
in
differing_letters
if
char
[
0
]
!=
' '
]
return
''
.
join
(
differing_letters
)
# Initialize variables to track the most matching word and its differing letters
most_matching_word
=
None
differing_letters
=
None
for
candidate_word
in
candidate_words
:
candidate_differing_letters
=
find_differing_letters
(
user_input
,
candidate_word
)
if
differing_letters
is
None
or
len
(
candidate_differing_letters
)
<
len
(
differing_letters
):
differing_letters
=
candidate_differing_letters
most_matching_word
=
candidate_word
if
differing_letters
:
print
(
f
"Differing Letters: {differing_letters}"
)
# Differentiating stage here
else
:
print
(
"No differing letters found."
)
#--------------xxxxx
# Input word and letter
input_word
=
most_similar_word
input_letter
=
differing_letters
# Find the first row
row
=
df
[
df
[
'words'
]
==
input_word
]
.
iloc
[
0
]
initial_position
=
None
middle_position
=
None
end_position
=
None
if
input_letter
in
row
[
'initial'
]:
initial_position
=
row
[
'initial'
]
.
index
(
input_letter
)
if
input_letter
in
row
[
'middle'
]:
middle_position
=
row
[
'middle'
]
.
index
(
input_letter
)
if
input_letter
in
row
[
'end'
]:
end_position
=
row
[
'end'
]
.
index
(
input_letter
)
# Print
if
initial_position
is
not
None
:
print
(
"Position: initial"
)
if
middle_position
is
not
None
:
print
(
"Position: middle"
)
if
end_position
is
not
None
:
print
(
"Position: end"
)
# Check if differing_letter is not None before getting its length
if
differing_letters
is
not
None
:
differing_letter_count
=
len
(
differing_letters
)
print
(
f
"Number of Different Letters: {differing_letter_count}"
)
else
:
print
(
"No differing letter found."
)
DataSet.xlsx
0 → 100644
View file @
8d2c463f
File added
FlutterAPI_Word.py
0 → 100644
View file @
8d2c463f
from
flask
import
Flask
,
request
,
jsonify
from
flask_cors
import
CORS
import
pandas
as
pd
import
difflib
# Read data
df
=
pd
.
read_excel
(
'DataSet.xlsx'
)
app
=
Flask
(
__name__
)
CORS
(
app
)
def
find_most_similar_word
(
input_word
,
word_list
):
similarities
=
difflib
.
get_close_matches
(
input_word
,
word_list
)
return
similarities
[
0
]
if
similarities
else
None
def
find_different_letters
(
input_word
,
similar_word
):
differences
=
[]
for
char1
,
char2
in
zip
(
input_word
,
similar_word
):
if
char1
!=
char2
:
differences
.
append
(
char1
)
return
''
.
join
(
differences
)
@
app
.
route
(
'/API_Word'
,
methods
=
[
'POST'
])
def
compare_words
():
try
:
data
=
request
.
get_json
()
input_word
=
data
[
'input_word'
]
user_input
=
input_word
most_similar_word
=
find_most_similar_word
(
input_word
,
df
[
'words'
])
if
most_similar_word
:
different_letters
=
find_different_letters
(
input_word
,
most_similar_word
)
user_input
=
input_word
candidate_words
=
[
most_similar_word
]
def
find_differing_letters
(
input_word
,
candidate_word
):
differing_letters
=
list
(
difflib
.
ndiff
(
input_word
,
candidate_word
))
differing_letters
=
[
char
[
2
]
for
char
in
differing_letters
if
char
[
0
]
!=
' '
]
return
''
.
join
(
differing_letters
)
most_matching_word
=
None
differing_letters
=
None
for
candidate_word
in
candidate_words
:
candidate_differing_letters
=
find_differing_letters
(
user_input
,
candidate_word
)
if
differing_letters
is
None
or
len
(
candidate_differing_letters
)
<
len
(
differing_letters
):
differing_letters
=
candidate_differing_letters
most_matching_word
=
candidate_word
if
differing_letters
:
position_info
=
[]
input_word
=
most_matching_word
input_letter
=
differing_letters
row
=
df
[
df
[
'words'
]
==
input_word
]
.
iloc
[
0
]
if
input_letter
in
row
[
'initial'
]:
position_info
.
append
(
"Position: initial"
)
if
input_letter
in
row
[
'middle'
]:
position_info
.
append
(
"Position: middle"
)
if
input_letter
in
row
[
'end'
]:
position_info
.
append
(
"Position: end"
)
differing_letter_count
=
len
(
differing_letters
)
position_info
.
append
(
f
"Number of Different Letters: {differing_letter_count}"
)
return
jsonify
({
"User Input"
:
user_input
,
"Most Match"
:
most_matching_word
,
"Differing Letters"
:
differing_letters
,
"Position Info"
:
position_info
})
return
jsonify
({
"message"
:
"No similar word found in the dataset."
})
except
Exception
as
e
:
return
jsonify
({
"error"
:
str
(
e
)}),
400
if
__name__
==
'__main__'
:
app
.
run
(
host
=
'0.0.0.0'
,
debug
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment