Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Wiki Rasa
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
tm-chatbot
Wiki Rasa
Commits
ce74ec5b
Commit
ce74ec5b
authored
6 years ago
by
Lukas Gehrke
Browse files
Options
Downloads
Plain Diff
Merge branch '43-make-create_annotation-parameteters-optional' into 'master'
Resolve "Make create_annotation parameteters optional" Closes
#43
See merge request
!37
parents
e3702c0e
911bb9a1
No related branches found
Branches containing commit
No related tags found
1 merge request
!37
Resolve "Make create_annotation parameteters optional"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
processing/wikiproc/R/nlp_annotate.R
+37
-25
37 additions, 25 deletions
processing/wikiproc/R/nlp_annotate.R
processing/wikiproc/man/create_annotations.Rd
+2
-2
2 additions, 2 deletions
processing/wikiproc/man/create_annotations.Rd
with
39 additions
and
27 deletions
processing/wikiproc/R/nlp_annotate.R
+
37
−
25
View file @
ce74ec5b
...
...
@@ -25,8 +25,8 @@ init_nlp <- function(type, value) {
#' Create annotations for the given text
#'
#' @param text Text to annotate
#' @param article.id ArticleID used for cashing
#' @param article.rev.id ArticleRevisionID used for cashing
#' @param article.id ArticleID used for cashing
. **Optional** as long as cache is not to be used.
#' @param article.rev.id ArticleRevisionID used for cashing
. **Optional** as long as cache is not to be used.
#' @param use.cache Should cashed data be uses
#' @param write.cache Should the generated annotations be cashed
#' @param data.dir Directory the data should be read from and/or written to
...
...
@@ -34,22 +34,29 @@ init_nlp <- function(type, value) {
#' @return Annotation object for use with cleanNLP methods
#' @export
create_annotations
<-
function
(
text
,
article.id
,
article.rev.id
,
use.cache
=
TRUE
,
write.cache
=
FALSE
,
data.dir
=
"data"
)
{
# Generate filename, for some reason there paste0 will pad the article id with leading whitespaces
# To prevent this we stip 'em again
filename
<-
gsub
(
" "
,
""
,
paste
(
data.dir
,
"annotations"
,
paste0
(
article.id
,
"-"
,
article.rev.id
,
".RDS"
),
sep
=
.Platform
$
file.sep
),
fixed
=
TRUE
)
# Check if there is a cached version of the annotations for this article in this specific revision
if
(
use.cache
&
file.exists
(
filename
))
{
res
<-
tryCatch
({
data
<-
readRDS
(
filename
)
data
},
error
=
function
(
e
)
{
cat
(
"Cached data seems to be corrupted, redoing annotation.\n"
)
})
return
(
res
)
if
(
use.cache
||
write.cache
)
{
if
(
!
missing
(
article.id
)
&&
!
(
article.rev.id
))
{
# Generate filename, for some reason there paste0 will pad the article id with leading whitespaces
# To prevent this we stip 'em again
filename
<-
gsub
(
" "
,
""
,
paste
(
data.dir
,
"annotations"
,
paste0
(
article.id
,
"-"
,
article.rev.id
,
".RDS"
),
sep
=
.Platform
$
file.sep
),
fixed
=
TRUE
)
# Check if there is a cached version of the annotations for this article in this specific revision
if
(
use.cache
&
file.exists
(
filename
))
{
res
<-
tryCatch
({
data
<-
readRDS
(
filename
)
data
},
error
=
function
(
e
)
{
cat
(
"Cached data seems to be corrupted, redoing annotation.\n"
)
})
return
(
res
)
}
}
else
if
(
use.cache
)
{
warning
(
"use.cache was set to true without providing article id and revision id, cache will not be used."
)
}
}
annotation
<-
cleanNLP
::
cnlp_annotate
(
text
,
as_strings
=
TRUE
)
...
...
@@ -57,13 +64,18 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU
# Write cache if desired
if
(
write.cache
)
{
if
(
!
dir.exists
(
"data"
))
{
dir.create
(
"data"
)
if
(
!
missing
(
article.id
)
&&
!
missing
(
article.rev.id
))
{
if
(
!
dir.exists
(
"data"
))
{
dir.create
(
"data"
)
}
if
(
!
dir.exists
(
"data/annotations"
))
{
dir.create
(
"data/annotations"
)
}
saveRDS
(
annotation
,
filename
)
}
else
{
warning
(
"write.cache was set to true without providing article id and revision id, cache will not be written"
)
}
if
(
!
dir.exists
(
"data/annotations"
))
{
dir.create
(
"data/annotations"
)
}
saveRDS
(
annotation
,
filename
)
}
# Return data
...
...
@@ -71,4 +83,4 @@ create_annotations <- function(text, article.id, article.rev.id, use.cache = TRU
# But then again, it suggests snake case for variables...
return
(
annotation
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
processing/wikiproc/man/create_annotations.Rd
+
2
−
2
View file @
ce74ec5b
...
...
@@ -10,9 +10,9 @@ create_annotations(text, article.id, article.rev.id, use.cache = TRUE,
\arguments{
\item{text}{Text to annotate}
\item{article.id}{ArticleID used for cashing}
\item{article.id}{ArticleID used for cashing
. **Optional** as long as cache is not to be used.
}
\item{article.rev.id}{ArticleRevisionID used for cashing}
\item{article.rev.id}{ArticleRevisionID used for cashing
. **Optional** as long as cache is not to be used.
}
\item{use.cache}{Should cashed data be uses}
...
...
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