Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
softwareprojektws17
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Steffen Knapp
softwareprojektws17
Commits
5156a102
Commit
5156a102
authored
7 years ago
by
blunck
Browse files
Options
Downloads
Patches
Plain Diff
Added pos_tags and lemmas to corpus instance dict: Access via keys: "POS" & "LEMMAS"
parent
6812b516
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
corpus.py
+31
-0
31 additions, 0 deletions
corpus.py
with
31 additions
and
0 deletions
corpus.py
+
31
−
0
View file @
5156a102
...
...
@@ -2,8 +2,11 @@ import os, os.path
import
re
import
csv
from
nltk.tokenize
import
word_tokenize
from
nltk.stem
import
WordNetLemmatizer
import
nltk
from
random
import
shuffle
def
read_corpus
(
csv_corpus_path
):
"""
Reads a csv-file and returns a list of dicts.
...
...
@@ -21,6 +24,12 @@ def read_corpus(csv_corpus_path):
# tokenization
data
[
"
TOKENS
"
]
=
word_tokenize
(
row
[
'
REVIEW
'
])
# pos-tagging
data
[
"
POS
"
]
=
nltk
.
pos_tag
(
data
[
"
TOKENS
"
])
# lemmatizing
data
[
"
LEMMAS
"
]
=
get_lemmas
(
data
[
"
POS
"
])
corpus
.
append
(
data
)
return
corpus
...
...
@@ -92,6 +101,28 @@ def get_tag_content(tag, text):
return
match
[
0
].
strip
()
def
get_lemmas
(
instance_pos_tags
):
lemmatizer
=
WordNetLemmatizer
()
pos_map
=
{
"
VB
"
:
"
v
"
,
"
NN
"
:
"
n
"
,
"
JJ
"
:
"
a
"
}
lemmas
=
[]
for
pair
in
instance_pos_tags
:
token
=
pair
[
0
]
pos_tag
=
pair
[
1
][
0
:
2
]
simple_pos
=
"
n
"
if
pos_tag
in
pos_map
.
keys
():
simple_pos
=
pos_map
[
pos_tag
]
lemma
=
lemmatizer
.
lemmatize
(
token
,
pos
=
simple_pos
)
lemmas
.
append
(
lemma
)
return
lemmas
if
__name__
==
'
__main__
'
:
"""
corpus_path =
"
../corpus/SarcasmAmazonReviewsCorpus
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment