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
efd32184
Commit
efd32184
authored
6 years ago
by
Lukas Gehrke
Browse files
Options
Downloads
Patches
Plain Diff
Aendert if-Verzweigung in getBirthdate.R.
parent
a40ac74b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!21
Resolve "R-Skript für Birthdate erstellen"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
r/GetBirthdate.R
+31
-25
31 additions, 25 deletions
r/GetBirthdate.R
with
31 additions
and
25 deletions
r/GetBirthdate.R
+
31
−
25
View file @
efd32184
...
@@ -14,36 +14,42 @@ library(xml2)
...
@@ -14,36 +14,42 @@ library(xml2)
#' will be checked for birthdate
#' will be checked for birthdate
#'
#'
#' @param article Article in HTML-format
#' @param article Article in HTML-format
#' @return String birthdate as string
#' @return String birthdate as string
|NULL
getBirthdate
<-
function
(
article
)
{
getBirthdate
<-
function
(
article
)
{
# Check if there is an infobox
if
(
!
grepl
(
"vcard"
,
article
))
{
# Check first paragraph
introduction
<-
getIntroduction
(
article
)
if
(
!
introduction
==
""
)
{
# Get birthdate inside of parentheses
birthdate
<-
str_extract_all
(
introduction
,
"\\([^()]+\\)"
)[[
1
]]
# Remove parentheses
birthdate
<-
substring
(
birthdate
,
2
,
nchar
(
birthdate
)
-1
)
}
else
{
# Return Null if there is no birthdate
return
(
NULL
)
}
}
# Try to get birthdate via infobox
if
(
grepl
(
"vcard"
,
article
))
{
infoBox
<-
getInfoBox
(
article
)
# Get the born field
# Check if there is an infobox
birthdate
<-
infoBox
[
infoBox
$
Desc
%like%
"Born"
,]
$
Content
infoBox
<-
getInfoBox
(
article
)
# Get the Born field
birthdate
<-
infoBox
[
infoBox
$
Desc
%like%
"Born"
,]
$
Content
# Remove everything except the birthdate:
# - Remove everything in round brackets
birthdate
<-
gsub
(
"\\s*\\([^\\)]+\\)"
,
""
,
birthdate
)
# - Remove everything starting with newline
birthdate
<-
gsub
(
"\\n.*$"
,
""
,
birthdate
)
return
(
birthdate
)
# Remove everything except the birthdate
# Remove everything in round brackets
birthdate
<-
gsub
(
"\\s*\\([^\\)]+\\)"
,
""
,
birthdate
)
# Remove everything starting with newline
birthdate
<-
gsub
(
"\\n.*$"
,
""
,
birthdate
)
return
(
birthdate
)
}
else
if
(
!
getIntroduction
(
article
)
==
""
)
{
# Check first paragraph
introduction
<-
getIntroduction
(
article
)
# Get birthdate inside of parentheses
birthdate
<-
str_extract_all
(
introduction
,
"\\([^()]+\\)"
)[[
1
]]
# Remove parentheses
birthdate
<-
substring
(
birthdate
,
2
,
nchar
(
birthdate
)
-1
)
return
(
birthdate
)
}
else
{
# Return Null if there is no birthdate
return
(
NULL
)
}
}
}
### Converts info box to table
### Converts info box to table
...
...
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