Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021_123
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
2021_123
2021_123
Commits
385e99a4
Commit
385e99a4
authored
Oct 17, 2021
by
Rathnayake R.M.Y.A.B
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload Keyword comparing algorithm class
parent
621187b3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
Comparing.py
Comparing.py
+30
-0
No files found.
Comparing.py
0 → 100644
View file @
385e99a4
import
spacy
import
string
from
spacy.lang.en.stop_words
import
STOP_WORDS
from
string
import
punctuation
nlp
=
spacy
.
load
(
"en_core_web_sm"
)
stopwords
=
list
(
STOP_WORDS
)
punctuation
=
punctuation
+
'
\n
'
Topic
=
nlp
(
"black"
)
text2
=
open
(
"student_answer.txt"
,
encoding
=
"utf-8"
)
.
read
()
lower_case2
=
text2
.
lower
()
cleaned_text2
=
lower_case2
.
translate
(
str
.
maketrans
(
''
,
''
,
string
.
punctuation
))
Content
=
nlp
(
cleaned_text2
)
Total_similarity
=
0
for
token1
in
Content
:
if
token1
.
text
.
lower
()
not
in
stopwords
:
if
token1
.
text
.
lower
()
not
in
punctuation
:
for
token2
in
Topic
:
print
((
token1
.
text
,
token2
.
text
),
"similarity"
,
token1
.
similarity
(
token2
))
Total_similarity
=
Total_similarity
+
token1
.
similarity
(
token2
)
if
token1
.
similarity
(
token2
)
>
0.8
:
print
(
"Similar"
)
print
(
len
(
Content
))
print
(
Total_similarity
)
average_similarity
=
Total_similarity
/
len
(
Content
)
print
(
average_similarity
)
\ No newline at end of file
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