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
543a7c8e
Commit
543a7c8e
authored
6 years ago
by
David Fuhry
Committed by
Lucas Schons
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "(Dummy) feature extraktion"
parent
7004a81f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
r/GetNoOfSpouses.R
+62
-0
62 additions, 0 deletions
r/GetNoOfSpouses.R
r/Master.R
+15
-4
15 additions, 4 deletions
r/Master.R
with
77 additions
and
4 deletions
r/GetNoOfSpouses.R
0 → 100755
+
62
−
0
View file @
543a7c8e
### GetNoOfSpouses.R
### This extracts the number of spouses from the infobox
### If no infobox or no information about spouses is found assumes there are none
### Not for use in production, this does not actually get information from text
# Author: David
## Librarys
library
(
rvest
)
library
(
data.table
)
### Get number of spouses
getNoOfSpouses
<-
function
(
article
)
{
# If there is no infobox we assume there were no spouses
if
(
!
grepl
(
"vcard"
,
article
))
{
return
(
0
)
}
infoBox
<-
getInfoBox
(
article
)
# Get the spouse field
spouses
<-
infoBox
[
infoBox
$
Desc
%like%
"Spouse"
,]
$
Content
# Remove everything in parentheses
spouses
<-
gsub
(
"\\s*\\([^\\)]+\\)"
,
""
,
spouses
)
# Split the strings by newlines to get one spouse per line
spouses
<-
strsplit
(
spouses
,
"\n"
)
spouses
<-
unlist
(
spouses
)
if
(
length
(
spouses
)
>
0
)
{
return
(
length
(
spouses
))
}
return
(
0
)
}
### 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.
r/Master.R
100644 → 100755
+
15
−
4
View file @
543a7c8e
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
cat
(
"Sourcing R scripts... "
)
cat
(
"Sourcing R scripts... "
)
source
(
"r/GetData.R"
)
source
(
"r/GetData.R"
)
source
(
"r/GetNoOfSpouses.R"
)
#source("r/getBirthday.R")
#source("r/getBirthday.R")
#source("r/getSomethingElse.R")
#source("r/getSomethingElse.R")
...
@@ -27,7 +28,10 @@ articles <- getData(use.cache = TRUE)
...
@@ -27,7 +28,10 @@ articles <- getData(use.cache = TRUE)
cat
(
"Processing data...\n"
)
cat
(
"Processing data...\n"
)
results
<-
lapply
(
articles
,
function
(
data
)
{
results
<-
apply
(
articles
,
1
,
function
(
article
)
{
# Within this function article is a vector representing a single row of our original data frame
# This means article[1] represents the Title, article[2] the PageID etc.
## Data cleaning
## Data cleaning
# cleaned.text <- someCleanFunctioN(data$Text)
# cleaned.text <- someCleanFunctioN(data$Text)
...
@@ -38,22 +42,29 @@ results <- lapply(articles, function(data) {
...
@@ -38,22 +42,29 @@ results <- lapply(articles, function(data) {
## Extract information from Text
## Extract information from Text
no.spouses
<-
getNoOfSpouses
(
article
[
4
])
# someFact <- getFactFromTextFunctioN(annotated.text)
# someFact <- getFactFromTextFunctioN(annotated.text)
# someOtherFact <- getOtherFactFromText(data$Text)
# someOtherFact <- getOtherFactFromText(data$Text)
## Create Results
## Create Results
# data.frame(Name = x$Name,
data.frame
(
Name
=
article
[
1
],
# FactOne = someFact,
NoSpouses
=
no.spouses
)
# FactTwo = someOtherFact)
})
})
results
<-
do.call
(
rbind
,
results
)
results
<-
do.call
(
rbind
,
results
)
cat
(
"Data processing finished.\n"
)
## Results are now in results
## Results are now in results
## Format for rasa
## Format for rasa
cat
(
"Writing rasa files to 'rasa/'...\n"
)
# someFormatFunction(results)
# someFormatFunction(results)
cat
(
"Data processing finished.\n"
)
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