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
881f4eac
Commit
881f4eac
authored
6 years ago
by
David Fuhry
Committed by
Leonard Haas
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Implement NER"
parent
79e45a76
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
r/Master.R
+2
-1
2 additions, 1 deletion
r/Master.R
r/ProcessNER.R
+61
-0
61 additions, 0 deletions
r/ProcessNER.R
with
63 additions
and
1 deletion
r/Master.R
+
2
−
1
View file @
881f4eac
...
...
@@ -16,6 +16,7 @@ cat("Sourcing R scripts... ")
source
(
"r/GetData.R"
)
source
(
"r/GetNoOfSpouses.R"
)
source
(
"r/CleanHtml.R"
)
source
(
"r/ProcessNER.R"
)
#source("r/getSomethingElse.R")
cat
(
"Done.\n"
)
...
...
@@ -40,7 +41,7 @@ results <- pbapply(articles, 1, function(article) {
## Data preprocessing/annotating
#
annotat
ed.text <- annotationFunction(data$Text
)
annotat
ion
<-
createAnnotations
(
cleaned.text
,
article
[
2
],
article
[
3
]
)
## Extract information from Text
...
...
This diff is collapsed.
Click to expand it.
r/ProcessNER.R
0 → 100644
+
61
−
0
View file @
881f4eac
#!/usr/bin/env Rscript
### Provides functionality to use NER, POS and Dependency Grammers
## Author: David
cat
(
"Initializing spacy backend...\n"
)
# It's important to do this prior to loading any python related stuff
reticulate
::
use_condaenv
(
"spcy"
,
required
=
TRUE
)
# Load librarys
library
(
cleanNLP
)
# Init nlp models
cnlp_init_spacy
(
entity_flag
=
TRUE
)
cat
(
"Done.\n"
)
createAnnotations
<-
function
(
text
,
article.id
,
article.rev.id
,
use.cache
=
TRUE
,
write.cache
=
FALSE
)
{
# Generate filename, for some reason there paste0 will pad the article id with leading whitespaces
# To prevent this we stip 'em again
filename
<-
gsub
(
" "
,
""
,
paste0
(
"data/annotations/"
,
article.id
,
"-"
,
article.rev.id
,
".RDS"
),
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
)
}
annotation
<-
cnlp_annotate
(
text
,
as_strings
=
TRUE
)
# Write cache if desired
if
(
write.cache
)
{
if
(
!
dir.exists
(
"data"
))
{
dir.create
(
"data"
)
}
if
(
!
dir.exists
(
"data/annotations"
))
{
dir.create
(
"data/annotations"
)
}
saveRDS
(
annotation
,
filename
)
}
# Return data
# On a side note: Should we do this? The tidyverse style guide discourages explicit returns.
# 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.
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