Skip to content

Commit

Permalink
Move 'simplify.networks' to the end of public network-creation functions
Browse files Browse the repository at this point in the history
* Enable 'simplify.multiple.relations' config parameter to work properly.
Previously, networks would be simplified before merging datasources, i.e.,
before edges could even have multiple relations
* Circumvent undocumented behavior in 'plyr::rbind.fill' that occurs when
merging already simplified networks (see PR#255)

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Mar 18, 2024
1 parent 1f272e1 commit d310fdc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,12 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
igraph::V(net)$kind = TYPE.AUTHOR
igraph::V(net)$type = TYPE.AUTHOR

## simplify network if wanted
if (private$network.conf$get.value("simplify")) {
net = simplify.network(net, simplify.multiple.relations =
private$network.conf$get.value("simplify.multiple.relations"))
}

## add range attribute for later analysis (if available)
if ("RangeData" %in% class(private$proj.data)) {
attr(net, "range") = private$proj.data$get.range()
Expand Down Expand Up @@ -822,6 +828,12 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
## set vertex and edge attributes for identifaction
igraph::V(net)$type = TYPE.ARTIFACT

## simplify network if wanted
if (private$network.conf$get.value("simplify")) {
net = simplify.network(net, simplify.multiple.relations =
private$network.conf$get.value("simplify.multiple.relations"))
}

## add range attribute for later analysis (if available)
if ("RangeData" %in% class(private$proj.data)) {
attr(net, "range") = private$proj.data$get.range()
Expand Down Expand Up @@ -922,6 +934,12 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
network = igraph::delete.vertices(network, authors.to.remove)
}

## simplify network if wanted
if (private$network.conf$get.value("simplify")) {
network = simplify.network(network, simplify.multiple.relations =
private$network.conf$get.value("simplify.multiple.relations"))
}

## add range attribute for later analysis (if available)
if ("RangeData" %in% class(private$proj.data)) {
attr(network, "range") = private$proj.data$get.range()
Expand Down Expand Up @@ -1306,12 +1324,6 @@ construct.network.from.edge.list = function(vertices, edge.list, network.conf, d
## initialize edge weights
net = igraph::set.edge.attribute(net, "weight", value = 1)

## transform multiple edges to edge weights
if (network.conf$get.value("simplify")) {
net = simplify.network(net,
simplify.multiple.relations = network.conf$get.value("simplify.multiple.relations"))
}

logging::logdebug("construct.network.from.edge.list: finished.")

return(net)
Expand Down

0 comments on commit d310fdc

Please sign in to comment.