Skip to content

Commit e844089

Browse files
committed
big asoiaf update
1 parent 22889aa commit e844089

7 files changed

Lines changed: 305 additions & 119 deletions

File tree

src/common/table_cols.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ COL_VOLUMES_BY_ARC <- "AvgVolumesByArc" # average number of volumes by arc
3232

3333

3434

35+
###############################################################################
36+
# chapters
37+
COL_CHAP <- "Chapter" # chapter number, relative to a (novel) volume
38+
COL_CHAP_ID <- "ChapterId" # unique chapter id (overall)
39+
COL_CHAPS <- "Chapters" # number of chapters in a volume/arc
40+
# TODO implement stat computation for chapters, which were added afterwards (to handle ASOIAF)
41+
42+
43+
44+
3545
###############################################################################
3646
# pages
3747
COL_PAGE <- "Page" # page number, relative to a volume

src/corpus/read_data.R

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ read.inter.table <- function(
642642
inter.df[,COL_RANK] <- rank(volume.stats[inter.df[,COL_VOLUME_ID],COL_RANK]*(nrow(inter.df)+1) + 1:nrow(inter.df), ties.method="first")
643643

644644
# check unused characters
645-
pb.char <- setdiff(char.stats[,COL_NAME], unique(unlist(scene.chars)))
645+
pb.chars <- setdiff(char.stats[,COL_NAME], unique(unlist(scene.chars)))
646646
if(length(pb.chars)>0)
647647
{ #cat(paste(pb.chars,collapse="\n"))
648648
msg <- paste0("WARNING: while reading file \"",inter.file,"\". The following names are defined in file \"",CHAR_FILE,"\", but appear in no scene: ",paste(pb.chars,colapse=","))
@@ -918,47 +918,56 @@ read.char.list <- function(file)
918918
###############################################################################
919919
read.corpus.data <- function(char.det)
920920
{ tlog(2,"Reading statistics and character lists")
921+
result <- list()
921922

922923
# interactions
923924
file <- get.path.stats.corpus(char.det=char.det, pref="_interactions")
924925
tlog(2,"Reading interaction file \"",file,"\"")
925926
inter.df <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
926927
for(col in c(COL_CHAR_FROM, COL_CHAR_TO))
927928
inter.df[,col] <- fix.encoding(strings=inter.df[,col])
929+
result$inter.df <- inter.df
928930

929931
# panel stats
930932
file <- get.path.stats.corpus(object="panels", char.det=char.det, pref="_panel_stats")
931933
tlog(2,"Reading panel stats file \"",file,"\"")
932934
panel.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
935+
result$panel.stats <- panel.stats
933936
# panel chars
934937
file <- get.path.stats.corpus(object="panels", char.det=char.det, pref="_panel_chars")
935938
tlog(2,"Reading panel chars file \"",file,"\"")
936939
panel.chars <- read.char.list(file=paste0(file,".txt"))
940+
result$panel.chars <- panel.chars
937941

938942
# page stats
939943
file <- get.path.stats.corpus(object="pages", char.det=char.det, pref="_page_stats")
940944
tlog(2,"Reading page stats file \"",file,"\"")
941945
page.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
946+
result$page.stats <- page.stats
942947
# page chars
943948
file <- get.path.stats.corpus(object="pages", char.det=char.det, pref="_page_chars")
944949
tlog(2,"Reading page chars file \"",file,"\"")
945950
page.chars <- read.char.list(file=paste0(file,".txt"))
951+
result$page.chars <- page.chars
946952

947953
# scene stats
948954
file <- get.path.stats.corpus(object="scenes", char.det=char.det, pref="_scene_stats")
949955
tlog(2,"Reading scene stats file \"",file,"\"")
950956
scene.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
957+
result$scene.stats <- scene.stats
951958
# scene chars
952959
file <- get.path.stats.corpus(object="scenes", char.det=char.det, pref="_scene_chars")
953960
tlog(2,"Reading scene chars file \"",file,"\"")
954961
scene.chars <- read.char.list(file=paste0(file,".txt"))
962+
result$scene.chars <- scene.chars
955963

956964
# characters
957965
file <- get.path.stats.corpus(object="characters", char.det=char.det, subfold="unfiltered", pref="_char_stats")
958966
tlog(2,"Reading char stats file \"",file,"\"")
959967
char.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
960968
for(col in c(COL_NAME, COL_NAME_SHORT))
961969
char.stats[,col] <- fix.encoding(strings=char.stats[,col])
970+
result$char.stats <- char.stats
962971

963972
# possibly deal with chapters
964973
file <- get.path.stats.corpus(object="chapters", char.det=char.det, pref="_chapter_stats")
@@ -968,10 +977,12 @@ read.corpus.data <- function(char.det)
968977
chapter.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
969978
for(col in c(COL_TITLE, COL_VOLUME, COL_ARC))
970979
chapter.stats[,col] <- fix.encoding(strings=chapter.stats[,col])
980+
result$chapter.stats <- chapter.stats
971981
# chapter chars
972982
file <- get.path.stats.corpus(object="chapters", char.det=char.det, pref="_chapter_chars")
973983
tlog(2,"Reading chapter chars file \"",file,"\"")
974984
chapter.chars <- read.char.list(file=paste0(file,".txt"))
985+
result$chapter.chars <- chapter.chars
975986
}
976987

977988
# volume stats
@@ -980,33 +991,27 @@ read.corpus.data <- function(char.det)
980991
volume.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
981992
for(col in c(COL_SERIES, COL_TITLE, COL_ARC))
982993
volume.stats[,col] <- fix.encoding(strings=volume.stats[,col])
994+
result$volume.stats <- volume.stats
983995
# volume chars
984996
file <- get.path.stats.corpus(object="volumes", char.det=char.det, pref="_volume_chars")
985997
tlog(2,"Reading volume chars file \"",file,"\"")
986998
volume.chars <- read.char.list(file=paste0(file,".txt"))
999+
result$volume.chars <- volume.chars
9871000

9881001
# arc stats
9891002
file <- get.path.stats.corpus(object="arcs", char.det=char.det, pref="_arc_stats")
9901003
tlog(2,"Reading arc stats file \"",file,"\"")
9911004
arc.stats <- read.csv(file=paste0(file,".csv"), header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
9921005
for(col in c(COL_TITLE))
9931006
arc.stats[,col] <- fix.encoding(strings=arc.stats[,col])
1007+
result$arc.stats <- arc.stats
9941008
# arc chars
9951009
file <- get.path.stats.corpus(object="arcs", char.det=char.det, pref="_arc_chars")
9961010
tlog(2,"Reading arc chars file \"",file,"\"")
9971011
arc.chars <- read.char.list(file=paste0(file,".txt"))
1012+
result$arc.chars <- arc.chars
9981013

999-
# build result list and return
1000-
result <- list(
1001-
inter.df=inter.df, # interactions
1002-
panel.stats=panel.stats, panel.chars=panel.chars, # panels
1003-
page.stats=page.stats, page.chars=page.chars, # pages
1004-
scene.stats=scene.stats, scene.chars=scene.chars, # scenes
1005-
char.stats=char.stats, # characters
1006-
chapter.stats=chapter.stats, chapter.chars=chapter.chars, # chapters
1007-
volume.stats=volume.stats, volume.chars=volume.chars, # volumes
1008-
arc.stats=arc.stats, arc.chars=arc.chars # arcs
1009-
)
1014+
# return result list
10101015
return(result)
10111016
}
10121017

src/dev_ASOIAF.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ SERIES <- "ASOIAF"
2222
###############################################################################
2323
# load scripts
2424
source("src/common/_include.R")
25+
source("src/post/asoiaf/add_chapters.R")
26+
source("src/post/asoiaf/extr_dyn.R")
2527

2628
# start logging
2729
start.rec.log(text=SERIES)
@@ -32,7 +34,7 @@ start.rec.log(text=SERIES)
3234
###############################################################################
3335
###############################################################################
3436
# read raw data
35-
data <- read.raw.data(char.det="implicit")
37+
data <- read.raw.data.asoiaf()
3638
# OR, if already computed, read from file
3739
#data <- read.corpus.data(char.det="implicit")
3840

@@ -65,10 +67,19 @@ generate.static.plots.base(data=data)
6567

6668

6769

70+
###############################################################################
71+
# extract dynamic networks
72+
extract.dyn.nets.asoiaf(data)
73+
74+
# compute and plot their stats
75+
# TODO
76+
77+
78+
79+
6880
###############################################################################
6981
# stop logging
7082
end.rec.log()
7183

7284
# TODO
7385
# - sortir mêmes figures que padraig
74-
# - extraire cum net par chap au lieu de scènes

src/dynamic/cumulative.R

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cum.graph.extraction <- function(inter.df, char.stats, scene.chars, scene.stats,
5050
res <- list()
5151
prev.unit <- NA
5252
for(s in 1:length(gg))
53-
{ tlog(4,"Processing scene ",s,"/",length(gg))
53+
{ #tlog(4,"Processing scene ",s,"/",length(gg))
5454

5555
# retrieve current scene graph
5656
sc.g <- gg[[s]]
@@ -60,11 +60,13 @@ cum.graph.extraction <- function(inter.df, char.stats, scene.chars, scene.stats,
6060
sc.idx <- which(scene.stats[,COL_SCENE_ID]==sc.id)
6161
if(narr.unit=="scene")
6262
cur.unit <- sc.id
63+
else if(narr.unit=="chapter")
64+
cur.unit <- scene.stats[sc.idx,COL_CHAP_ID]
6365
else if(narr.unit=="volume")
6466
cur.unit <- scene.stats[sc.idx,COL_VOLUME_ID]
6567
else if(narr.unit=="arc")
6668
cur.unit <- scene.stats[sc.idx,COL_ARC_ID]
67-
tlog(4,"Current ",narr.unit,": ",cur.unit," (previous ",narr.unit,": ",prev.unit,")")
69+
#tlog(4,"Current ",narr.unit,": ",cur.unit," (previous ",narr.unit,": ",prev.unit,")")
6870

6971
# very first graph of the sequence
7072
if(s==1)
@@ -180,14 +182,3 @@ cum.read.graph <- function(filtered, remove.isolates=TRUE, pub.order=TRUE, char.
180182

181183
return(gs)
182184
}
183-
184-
185-
186-
187-
################################################################################
188-
## test
189-
#data <- read.corpus.data(char.det="implicit")
190-
#filtered <- FALSE
191-
#pub.order <- FALSE
192-
#gg <- cum.graph.extraction(inter.df=data$inter.df, char.stats=data$char.stats, scene.chars=data$scene.chars, scene.stats=data$scene.stats, volume.stats=data$volume.stats, filtered=filtered, pub.order=pub.order)
193-
#cum.write.graph(gs=gg, filtered=filtered, pub.order=pub.order, char.det="implicit")

0 commit comments

Comments
 (0)