3434# ##############################################################################
3535extract.static.graph.scenes <- function (inter.df , char.stats , scene.stats , scene.chars , volume.stats , vol = NA , arc = NA , ret.seq = FALSE , pub.order = TRUE )
3636{ tlog(2 ," Extracting the scene-based static graph" )
37- res <- list ()
3837vname <- NA
3938
4039# init the dataframe
@@ -70,15 +69,16 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
7069
7170# possibly init the list with empty graphs or isolates
7271if (ret.seq )
73- {# tlog(2,"Initializing the graph list")
72+ {gg <- list ()
73+ tlog(2 ," Initializing the graph list" )
7474for (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
7777g <- graph_from_data_frame(d = static.df , directed = FALSE , vertices = char.stats )
7878g <- set_edge_attr(g , name = COL_OCCURRENCES , value = NA )
7979g <- set_edge_attr(g , name = COL_DURATION , value = NA )
80- res [[s ]] <- g
8180g $ SceneId <- scene.stats [scenes.ord [s ],COL_SCENE_ID ]
81+ gg [[s ]] <- g
8282s <- s + 1
8383}
8484}
@@ -91,7 +91,7 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
9191{# get the current scene id
9292cur.scene <- inter.df [i ,COL_SCENE_ID ]
9393cur.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
9797from.char <- inter.df [i ,COL_CHAR_FROM ]
@@ -119,11 +119,11 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
119119# if graph sequence required
120120if (ret.seq )
121121{# retrieve existing graph for the current scene
122- g <- res [[cur.scene.idx ]]
122+ g <- gg [[cur.scene.idx ]]
123123# update with current interaction
124124g <- add_edges(graph = g , edges = c(from.char ,to.char ), attr = list (Occurrences = 1 , Duration = length ))
125125# update result list
126- res [[cur.scene.idx ]] <- g
126+ gg [[cur.scene.idx ]] <- g
127127}
128128
129129prev.scene <- cur.scene
@@ -132,7 +132,8 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
132132
133133# set up result variable
134134if (ret.seq )
135- {msg <- paste0(" returning a series of " ,length(res )," graphs" )
135+ {msg <- paste0(" returning a series of " ,length(gg )," graphs" )
136+ res <- gg
136137}
137138else
138139{static.df <- static.df [order(static.df [,COL_CHAR_FROM ],static.df [,COL_CHAR_TO ]),]
0 commit comments