@@ -71,17 +71,10 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
7171 # possibly init the list with empty graphs or isolates
7272 if (ret.seq )
7373 { # tlog(2,"Initializing the graph list")
74- s <- 1
75- while (scene.stats [scenes.ord [s ],COL_SCENE_ID ]!= inter.df [is [1 ],COL_SCENE_ID ])
74+ for (s in 1 : length(scenes.ord ))
7675 { # 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]]),")")
77- # no character: empty graph
78- if (length(scene.chars [[scenes.ord [s ]]])== 0 )
79- g <- make_empty_graph(n = 0 , directed = FALSE )
80- # a single character: single vertex graph
81- else if (length(scene.chars [[scenes.ord [s ]]])== 1 )
82- { idx <- which(char.stats [,COL_NAME ]== scene.chars [[scenes.ord [s ]]])
83- g <- graph_from_data_frame(d = static.df , directed = FALSE , vertices = char.stats [idx ,])
84- }
76+ # init graph with all vertices (characters) and no edge
77+ g <- graph_from_data_frame(d = static.df , directed = FALSE , vertices = char.stats )
8578 g <- set_edge_attr(g , name = COL_OCCURRENCES , value = NA )
8679 g <- set_edge_attr(g , name = COL_DURATION , value = NA )
8780 res [[s ]] <- g
@@ -97,8 +90,8 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
9790 for (i in is )
9891 { # get the current scene id
9992 cur.scene <- inter.df [i ,COL_SCENE_ID ]
100- cur.scene.idx <- which(scenes.ord == cur.scene )
101- # tlog(4,"Processing scene ",cur.scene," (",cur.scene.idx,"/",length(scenes.ord),")")
93+ 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),")")
10295
10396 # get the characters
10497 from.char <- inter.df [i ,COL_CHAR_FROM ]
@@ -125,22 +118,11 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
125118
126119 # if graph sequence required
127120 if (ret.seq )
128- { # possibly copy previous graph
129- if (! is.na(prev.scene ) && cur.scene != prev.scene )
130- { # tlog(4,"prev.scene=",prev.scene," cur.scene=",cur.scene)
131- # possibly several times, to represent interaction-less scenes
132- for (s in (prev.scene.idx + 1 ): (cur.scene.idx - 1 ))
133- { tlog(6 ," s=" ,s ," scenes.ord[s-1]=" ,scenes.ord [s - 1 ]," length(res)=" ,length(res ))
134- g <- res [[s - 1 ]]
135- g <- set_graph_attr(graph = g , name = " SceneId" , value = scene.stats [scenes.ord [s ],COL_SCENE_ID ])
136- res [[s ]] <- g
137- }
138- }
139- # build and add current graph
140- static.df <- static.df [order(static.df [,COL_CHAR_FROM ],static.df [,COL_CHAR_TO ]),]
141- idx <- which(char.stats [,COL_NAME ] %in% c(cbind(static.df [,COL_CHAR_FROM ],static.df [,COL_CHAR_TO ])))
142- g <- graph_from_data_frame(d = static.df , directed = FALSE , vertices = char.stats [idx ,])
143- g $ SceneId <- cur.scene
121+ { # retrieve existing graph for the current scene
122+ g <- res [[cur.scene.idx ]]
123+ # update with current interaction
124+ g <- add_edges(graph = g , edges = c(from.char ,to.char ), attr = list (Occurrences = 1 , Duration = length ))
125+ # update result list
144126 res [[cur.scene.idx ]] <- g
145127 }
146128
0 commit comments