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
10013fb8
Commit
10013fb8
authored
6 years ago
by
Lucas Schons
Browse files
Options
Downloads
Plain Diff
Merge branch '46-enhancing-r-optimize-getbirthplace-r' into 'master'
Adds use of annotations to get_birthplace.R. Closes
#46
See merge request
!44
parents
79e281db
d402c31e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!44
Adds use of annotations to get_birthplace.R.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
processing/wikiproc/R/get_birthplace.R
+41
-20
41 additions, 20 deletions
processing/wikiproc/R/get_birthplace.R
with
41 additions
and
20 deletions
processing/wikiproc/R/get_birthplace.R
+
41
−
20
View file @
10013fb8
...
...
@@ -4,29 +4,50 @@
#' This script extracts Birthplace from physicist texts
#' Try to get the infobox and extract the birthplace
#' If there is no infobox,
NA will be returned as
#'
b
ir
thplace is hard to extract from text
#' If there is no infobox,
try to search text for
#'
f
ir
st occurence of an NORP entity
#'
#' @export
#' @param article Article in HTML-format
#' @return String with birthplace of the physicist|0
get_birthplace
<-
function
(
article
)
{
#' @param annotations CNLP Annotations
#' @return String with birthplace of the physicist|NA
get_birthplace
<-
function
(
article
,
annotations
)
{
# If there is no infobox we return 0
if
(
!
grepl
(
"vcard"
,
article
))
{
return
(
NA
)
}
# Use infobox to get Birthplace
infoBox
<-
get_infobox
(
article
)
# Get 'Born' field
birthplace
<-
infoBox
[
infoBox
$
Desc
%like%
"Born"
,]
$
Content
if
(
grepl
(
"vcard"
,
article
))
{
# Use infobox to get Birthplace
infoBox
<-
get_infobox
(
article
)
# Assumption: In most cases birthplace is after newline in Born
# field of infobox
# - Get 'Born' field
# - Remove everything in front of the "\n"
# - Rest is birthplace in most cases
birthplace
<-
infoBox
[
infoBox
$
Desc
%like%
"Born"
,]
$
Content
birthplace
<-
gsub
(
".*\\\n"
,
""
,
birthplace
)
# Remove everything in front of the "\n"
# Rest is birthplace
birthplace
<-
gsub
(
".*\\\n"
,
""
,
birthplace
)
# return birthplace
return
(
birthplace
)
}
else
{
# Try to extract birthplace from text as first NORP entitiy
# Not beautiful, because it mostly is Nationality of the physicist
# - Get named entities
# - Get NORP entities
# - Get first NORP
entities
<-
cnlp_get_entity
(
annotations
)
norps
<-
entities
[
entities
$
entity_type
==
"NORP"
,]
birthplace
<-
norps
$
entity
[
1
]
}
# Trim whitespaces
birthplace
<-
trimws
(
birthplace
)
# Return birthplace or NA
if
(
!
is.null
(
birthplace
))
{
return
(
birthplace
)
}
else
{
return
(
NA
)
}
}
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