Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
COM6001M Computer Science Major Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
benjamin.clough
COM6001M Computer Science Major Project
Commits
ce68db1d
Commit
ce68db1d
authored
May 17, 2023
by
benjamin.clough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete preprocessing_functionality.py
parent
459e77fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
49 deletions
+0
-49
preprocessing_functionality.py
project_utilities/preprocessing_functionality.py
+0
-49
No files found.
project_utilities/preprocessing_functionality.py
deleted
100644 → 0
View file @
459e77fa
import
nltk
import
pandas
from
nltk.stem
import
WordNetLemmatizer
,
PorterStemmer
from
bs4
import
BeautifulSoup
import
re
lemmatizer
=
nltk
.
stem
.
WordNetLemmatizer
()
stemmer
=
nltk
.
PorterStemmer
()
def
clean_text
(
text
:
str
)
->
str
:
# Strip HTML & XML
text
=
BeautifulSoup
(
text
,
"lxml"
)
.
text
text
=
re
.
sub
(
r'\|\|\|'
,
r' '
,
text
)
# Strip Hyperlinks & URLs
text
=
re
.
sub
(
r'http\S+'
,
r'<URL>'
,
text
)
# Strip Non-word characters
text
=
re
.
sub
(
r'[^\w\s]'
,
''
,
text
)
# Convert string to lowercase
text
=
text
.
replace
(
'x'
,
''
)
text
=
text
.
lower
()
return
text
def
tokenize_text
(
text
):
untokenized_sentences
=
nltk
.
sent_tokenize
(
text
)
tokenized_sentences
=
[
tokenize_sentence
(
sentence
)
for
sentence
in
untokenized_sentences
]
tokens
=
[
token
for
tokenized_sentence
in
tokenized_sentences
for
token
in
tokenized_sentence
]
return
tokens
def
tokenize_sentence
(
sentence
):
tokenized_sentence
=
nltk
.
word_tokenize
(
sentence
)
tokenized_sentence
=
[
word
for
word
in
tokenized_sentence
if
len
(
word
)
>
2
]
return
tokenized_sentence
def
lemmatize_text
(
text
:
list
):
lemmatized
=
[
lemmatizer
.
lemmatize
(
word
)
for
word
in
text
]
return
' '
.
join
(
lemmatized
)
def
stem_text
(
text
:
list
):
stemmed
=
[
stemmer
.
stem
(
word
)
for
word
in
text
]
return
' '
.
join
(
stemmed
)
if
__name__
==
'__main__'
:
print
(
stemmer
.
stem
(
'connecting'
))
\ 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