Skip to content

Commit fdf0f37

Browse files
committed
fixed minor bug in net extr fct
1 parent 0c670f3 commit fdf0f37

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/static/extract_graphs_scene.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
###############################################################################
3535
extract.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()
3837
vname <- 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
7271
if(ret.seq)
73-
{#tlog(2,"Initializing the graph list")
72+
{gg <- 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)
7979
g <- set_edge_attr(g, name=COL_DURATION, value=NA)
80-
res[[s]] <- g
8180
g$SceneId <- scene.stats[scenes.ord[s],COL_SCENE_ID]
81+
gg[[s]] <- g
8282
s <- 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
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]
@@ -119,11 +119,11 @@ extract.static.graph.scenes <- function(inter.df, char.stats, scene.stats, scene
119119
# if graph sequence required
120120
if(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
124124
g <- 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

129129
prev.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
134134
if(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
}
137138
else
138139
{static.df <- static.df[order(static.df[,COL_CHAR_FROM],static.df[,COL_CHAR_TO]),]

0 commit comments

Comments
 (0)