Skip to content

Commit

Permalink
Fix edge attributes of bipartite edges
Browse files Browse the repository at this point in the history
The breaking changes of igraph version 1.4.0 regarding the classes of edge
attributes revealed an actual bug in the edge attributes of bipartite edges in
coronet:

We need to make sure that we only add the edge attributes for the edges that are
really added to the network. As, for example, edges to the untracked artifact
are not added to our bipartite network, we also need to make sure to remove the
attributes of the corresponding edges (otherwise this could lead to wrong
attributes). Therefore, we add a (rather complex) check for which edges (i.e.,
vertex sequences) are present in the final bipartite network and extract the
corresponding information for the edge attributes accordingly.

This addresses #236.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom committed Apr 2, 2023
1 parent a953555 commit 820a763
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co
igraph::V(net)[d, vert] # get two vertices from source network: c(author, artifact)
})
return(new.edges)
}, names(net1.to.net2), net1.to.net2)
}, names(net1.to.net2), net1.to.net2, SIMPLIFY = FALSE)

## initialize edge attributes
allowed.edge.attributes = network.conf$get.value("edge.attributes")
Expand All @@ -1311,6 +1311,31 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co
extra.edge.attributes.df = parallel::mclapply(net1.to.net2, function(a.df) {
cols.which = allowed.edge.attributes %in% colnames(a.df)
return(a.df[, allowed.edge.attributes[cols.which], drop = FALSE])
extra.edge.attributes.df = parallel::mcmapply(vertex.sequence = vertex.sequence.for.edges, a.df = net1.to.net2,
SIMPLIFY = FALSE, function(vertex.sequence, a.df) {

## return empty data.frame if vertex sequence is empty
if (length(unlist(vertex.sequence)) == 0){
return(data.frame())
}

## get the artifacts from the vertex sequence (which are the even elements of the sequence vector)
vertex.names.in.sequence = names(unlist(vertex.sequence))
artifacts.in.sequence = vertex.names.in.sequence[seq(2, length(vertex.names.in.sequence), 2)]

## get the edges that will be constructed from the artifacts,
## to get only the edge attributes for edges that will be present in the final network
## (i.e., ignore edges to removed artifacts, such as the empty artifact that has been removed above)
constructed.edges = a.df[a.df[["data.vertices"]] %in% artifacts.in.sequence, , drop = FALSE]

## return empty data.frame if there will be no edges in the end
if (nrow(constructed.edges) < 1) {
return(data.frame())
}

## select the allowed attributes from the edge data.frame's columns
cols.which = allowed.edge.attributes %in% colnames(constructed.edges)
return(constructed.edges[ , allowed.edge.attributes[cols.which], drop = FALSE])
})
extra.edge.attributes.df = plyr::rbind.fill(extra.edge.attributes.df)
extra.edge.attributes = as.list(extra.edge.attributes.df)
Expand Down

0 comments on commit 820a763

Please sign in to comment.