Skip to content

Commit add4ba3

Browse files
committed
finished cum dyn net extr
1 parent 46d10d8 commit add4ba3

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

src/dev_ASOIAF.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ generate.static.plots.base(data=data)
7070
end.rec.log()
7171

7272
# TODO
73-
# - cum net: test if pub order extr works
74-
# - code novel order dyn net extr, and anal
73+
# - sortir mêmes figures que padraig
74+
# - transformer chapitres en volumes ?

src/post/asoiaf/extr_dyn.R

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Extracts dynamic ASOIAF networks.
1+
# Extracts dynamic ASOIAF networks. The "publication" order follows the comic publication
2+
# order. The "story" order matches parts of issues to novel chapter and reorder them
3+
# accordingly, in order to match the books.
24
#
35
# Vincent Labatut
46
# 02/2023
@@ -24,6 +26,7 @@ inter.df <- data$inter.df
2426
char.stats <- data$char.stats
2527
scene.stats <- data$scene.stats
2628
scene.chars <- data$scene.chars
29+
panel.stats <- data$panel.stats
2730
page.stats <- data$page.stats
2831
volume.stats <- data$volume.stats
2932
scene.stats <- data$scene.stats
@@ -38,28 +41,47 @@ for(filtered in c(FALSE,TRUE))
3841
scene.chars=scene.chars, scene.stats=scene.stats,
3942
volume.stats=volume.stats,
4043
filtered=filtered,
41-
pub.order=FALSE
44+
pub.order=TRUE,
45+
narr.unit="scene"
4246
)
43-
cum.write.graph(gs=gg, filtered=filtered, pub.order=FALSE, char.det="implicit")
44-
gg <- cum.read.graph(filtered=filtered, remove.isolates=TRUE, pub.order=FALSE, char.det="implicit")
47+
cum.write.graph(gs=gg, filtered=filtered, pub.order=TRUE, char.det="implicit")
48+
gg <- cum.read.graph(filtered=filtered, remove.isolates=TRUE, pub.order=TRUE, char.det="implicit")
4549
}
4650

4751

52+
53+
54+
###############################################################################
4855
# extract dynamic networks using the novel publication order (slightly different from the comic's)
4956
tlog(2,"Extracting novel-ordered dynamic networks")
5057

5158
# read map file
5259
map.file <- file.path(DATA_FOLDER,"mapping.csv")
5360
map <- read.csv(map.file, header=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
54-
# compute page ranks
61+
# compute new page ranks
5562
parts <- sapply(1:nrow(page.stats), function(p) map[map[,COL_VOLUME]==page.stats[p,COL_VOLUME] & map[,COL_PAGE_START]<=page.stats[p,COL_PAGE] & map[,COL_PAGE_END]>=page.stats[p,COL_PAGE], COL_RANK])
5663
page.stats[,COL_RANK] <- rank(parts*(nrow(page.stats)+1) + page.stats[,COL_PAGE])
57-
# compute other ranks
64+
# compute other ranks based on new page ranks
5865
panel.stats[,COL_RANK] <- rank(page.stats[panel.stats[,COL_PAGE_ID],COL_RANK]*(nrow(panel.stats)+1) + panel.stats[,COL_PANEL])
59-
# TODO
60-
scene.stats[,COL_RANK] <- rank(volume.stats[scene.stats[,COL_VOLUME_ID],COL_RANK]*(nrow(scene.stats)+1) + scene.stats[,COL_SCENE_ID], ties.method="first")
61-
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")
66+
scene.stats[,COL_RANK] <- rank(page.stats[scene.stats[,COL_PAGE_START_ID],COL_RANK]*(nrow(scene.stats)+1) + scene.stats[,COL_SCENE_ID], ties.method="first")
67+
inter.df[,COL_RANK] <- rank(page.stats[inter.df[,COL_PAGE_START_ID],COL_RANK]*(nrow(inter.df)+1) + 1:nrow(inter.df), ties.method="first")
6268

69+
# extract dynamic networks using the novel chapter order
70+
tlog(2,"Extracting publication-ordered dynamic networks")
71+
for(filtered in c(FALSE,TRUE))
72+
{ tlog(4,"Dealing with ",if(filtered) "" else "un","filtered networks")
73+
gg <- cum.graph.extraction(
74+
inter.df=inter.df,
75+
char.stats=char.stats,
76+
scene.chars=scene.chars, scene.stats=scene.stats,
77+
volume.stats=volume.stats,
78+
filtered=filtered,
79+
pub.order=FALSE,
80+
narr.unit="scene"
81+
)
82+
cum.write.graph(gs=gg, filtered=filtered, pub.order=FALSE, char.det="implicit")
83+
gg <- cum.read.graph(filtered=filtered, remove.isolates=TRUE, pub.order=FALSE, char.det="implicit")
84+
}
6385

6486

6587

src/static/extract_graphs_scene.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
7070
# possibly init the list with empty graphs or isolates
7171
if(ret.seq)
7272
{ gg <- list()
73-
tlog(2,"Initializing the graph list")
73+
#tlog(2,"Initializing the graph list")
7474
for(s in 1:length(scenes.ord))
75-
{ tlog(4,"Processing s=",s," (scenes.ord[s]=",scenes.ord[s]," and inter.df[is[1],COL_SCENE_ID]=",inter.df[is[1],COL_SCENE_ID],") -- (length(scene.chars[[s]]=",length(scene.chars[[s]]),")")
75+
{ #tlog(4,"Processing s=",s," (scenes.ord[s]=",scenes.ord[s]," and inter.df[is[1],COL_SCENE_ID]=",inter.df[is[1],COL_SCENE_ID],") -- (length(scene.chars[[s]]=",length(scene.chars[[s]]),")")
7676
# init graph with all vertices (characters) and no edge
7777
g <- graph_from_data_frame(d=static.df, directed=FALSE, vertices=char.stats)
7878
g <- set_edge_attr(g, name=COL_OCCURRENCES, value=NA)
@@ -91,7 +91,7 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
9191
{ # get the current scene id
9292
cur.scene <- inter.df[i,COL_SCENE_ID]
9393
cur.scene.idx <- which(scene.stats[scenes.ord,COL_RANK]==cur.scene)
94-
tlog(4,"Processing interaction #",i,"/",length(is)," from scene ",cur.scene," (",cur.scene.idx,"/",length(scenes.ord),")")
94+
#tlog(4,"Processing interaction #",i,"/",length(is)," from scene ",cur.scene," (",cur.scene.idx,"/",length(scenes.ord),")")
9595

9696
# get the characters
9797
from.char <- inter.df[i,COL_CHAR_FROM]

0 commit comments

Comments
 (0)