Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Statistical_Grammar_Checker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
NLP_WS_2021
Statistical_Grammar_Checker
Commits
9537e0c2
Commit
9537e0c2
authored
3 years ago
by
jmzk96
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug for empty list in google ngram function
parent
bc7af70e
No related branches found
No related tags found
1 merge request
!3
Google ngram
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/create_corpus.py
+12
-7
12 additions, 7 deletions
src/create_corpus.py
with
12 additions
and
7 deletions
src/create_corpus.py
+
12
−
7
View file @
9537e0c2
...
...
@@ -193,15 +193,20 @@ def get_google_ngram_occurences(query:str,corpus:str,start_year:int,end_year:int
corpus
=
"
eng_us_2012
"
url
=
f
"
https://books.google.com/ngrams/json?content=
{
query
}
&year_start=
{
str
(
start_year
)
}
&year_end=
{
str
(
end_year
)
}
&corpus=
{
str
(
corpora
[
corpus
])
}
&smoothing=
{
str
(
smoothing
)
}
&case_insensitive=
{
str
(
case_insensitive
)
}
"
response
=
requests
.
get
(
url
)
print
(
response
.
content
)
if
response
.
ok
:
results
=
json
.
loads
(
response
.
content
)
if
specific_year
and
start_year
<=
specific_year
<=
end_year
:
index
=
[
i
for
i
in
range
(
end_year
-
start
_year
+
1
)].
index
(
specific_year
)
specified_year
=
results
[
"
timeseries
"
][
index
]
if
results
and
specific_year
and
start_year
<=
specific_year
<=
end_year
:
index
=
[
i
for
i
in
range
(
start_year
,
end
_year
+
1
)].
index
(
specific_year
)
specified_year
=
results
[
0
][
"
timeseries
"
][
index
]
return
specified_year
else
:
log
.
info
(
"
No specific year chosen
"
)
return
results
[
"
timeseries
"
]
if
len
(
results
)
==
0
:
log
.
info
(
"
No record or results
"
)
return
None
else
:
log
.
info
(
"
No specific year chosen or wrong year order
"
)
return
results
else
:
log
.
info
(
"
No response found for query
"
)
return
None
...
...
@@ -236,5 +241,5 @@ if __name__ == "__main__":
# threshold = 10
# print(f"threshold={threshold}")
# trim_corpus(n, threshold)
create_POS_corpus
(
3
)
\ No newline at end of file
print
(
get_google_ngram_occurences
(
"
I lovess Jesus
"
,
"
eng_2012
"
,
2002
,
2003
,
2003
))
# create_POS_corpus(3)
\ No newline at end of file
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