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
79e45a76
Commit
79e45a76
authored
6 years ago
by
Jonas Wolff
Browse files
Options
Downloads
Plain Diff
Merge branch '22-r-skript-fur-birthplace-erstellen' into 'master'
Resolve "R-Skript für Birthplace erstellen" Closes
#22
See merge request
!22
parents
09f9606d
d296ae8e
No related branches found
Branches containing commit
No related tags found
1 merge request
!22
Resolve "R-Skript für Birthplace erstellen"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
r/GetBirthplace.R
+64
-0
64 additions, 0 deletions
r/GetBirthplace.R
with
64 additions
and
0 deletions
r/GetBirthplace.R
0 → 100644
+
64
−
0
View file @
79e45a76
#!/usr/bin/env Rscript
# Author: Lukas
## librarys
library
(
rvest
)
library
(
stringr
)
library
(
data.table
)
#' This script extracts Birthplace from physicist texts
#' Try to get the infobox and extract the birthplace
#' If there is no infobox, 0 will be returned as
#' birthplace is hard to extract from text
#'
#' @param article Article in HTML-format
#' @return String with birthplace of the physicist|0
getBirthplace
<-
function
(
article
)
{
# If there is no infobox we return 0
if
(
!
grepl
(
"vcard"
,
article
))
{
return
(
0
)
}
# Use infobox to get Birthplace
infoBox
<-
getInfoBox
(
article
)
# Get 'Born' field
birthplace
<-
infoBox
[
infoBox
$
Desc
%like%
"Born"
,]
$
Content
# Remove everything in front of the "\n"
# Rest is birthplace
birthplace
<-
gsub
(
".*\\\n"
,
""
,
birthplace
)
# return birthplace
return
(
birthplace
)
}
### Converts info box to table
getInfoBox
<-
function
(
article
)
{
# Read page as html
page
<-
read_html
(
article
)
# Extracting text from the html will erase all <br> tags,
# this will replace them with line breaks
xml_find_all
(
page
,
".//br"
)
%>%
xml_add_sibling
(
"p"
,
"\n"
)
xml_find_all
(
page
,
".//br"
)
%>%
xml_remove
()
# Get the info box
# Will throw an error if there isnt any, so that should be checked beforehand
table
<-
page
%>%
html_nodes
(
"table.vcard"
)
%>%
html_table
(
fill
=
TRUE
)
%>%
.
[[
1
]]
colnames
(
table
)
<-
c
(
"Desc"
,
"Content"
)
return
(
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