Skip to content

Commit

Permalink
Remove 'artifact' attribute from edges of artifact networks
Browse files Browse the repository at this point in the history
In artifact networks, artifacts should not be able to create edges,
but authors should. Remove 'artifact' attribute from edges of artifact
networks and append 'author.name' instead. This solves the issue of
duplicate edges between two artifacts that are only differentiable by the
'artifact' attribute.

This fixes #232.

Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
  • Loading branch information
maxloeffler committed Apr 13, 2023
1 parent a81a7f1 commit e2c9d6c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
artifacts.net.data = construct.edge.list.from.key.value.list(
artifacts.net.data.raw,
network.conf = private$network.conf,
directed = FALSE
directed = FALSE,
respect.temporal.order = TRUE,
artifact.edges = TRUE
)

## construct network from obtained data
Expand Down Expand Up @@ -970,11 +972,14 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
#' i.e., whether to only add edges from the later event to the previous one.
#' If \code{NA} is passed, the default value is taken.
#' [default: directed]
#' @param artifact.edges whether the key value data represents edges in an artifact network based
#' on the cochange relation
#' [default: \code{FALSE}]
#'
#' @return a list of two data.frames named 'vertices' and 'edges' (compatible with return value
#' of \code{igraph::as.data.frame})
construct.edge.list.from.key.value.list = function(list, network.conf, directed = FALSE,
respect.temporal.order = directed) {
respect.temporal.order = directed, artifact.edges = FALSE) {
logging::loginfo("Create edges.")
logging::logdebug("construct.edge.list.from.key.value.list: starting.")

Expand All @@ -991,7 +996,7 @@ construct.edge.list.from.key.value.list = function(list, network.conf, directed
keys = names(list)
keys.number = length(list)

if (respect.temporal.order) {
if (respect.temporal.order || artifact.edges) {

## for all subsets (sets), connect all items in there with the previous ones
edge.list.data = parallel::mclapply(list, function(set) {
Expand All @@ -1018,9 +1023,21 @@ construct.edge.list.from.key.value.list = function(list, network.conf, directed
## get vertex data
item.vertex = item[["data.vertices"]]

## if edges in an artifact network contain the \code{artifact} attribute
## replace it with the \code{author.name} attribute as artifacts cannot cause
## edges in artifact networks, authors can
edge.attributes = network.conf$get.value("edge.attributes")
if (artifact.edges) {
artifact.index = match("artifact", edge.attributes, nomatch = NA)
if (!is.na(artifact.index)) {
edge.attributes = edge.attributes[-artifact.index]
edge.attributes = c(edge.attributes, c("author.name"))
}
}

## get edge attributes
cols.which = network.conf$get.value("edge.attributes") %in% colnames(item)
item.edge.attrs = item[ , network.conf$get.value("edge.attributes")[cols.which], drop = FALSE]
cols.which = edge.attributes %in% colnames(item)
item.edge.attrs = item[ , edge.attributes[cols.which], drop = FALSE]

## construct edges
combinations = expand.grid(item.vertex, vertices.processed.set, stringsAsFactors = FALSE)
Expand Down Expand Up @@ -1367,9 +1384,7 @@ create.empty.network = function(directed = TRUE, add.attributes = FALSE) {
date = c("POSIXct", "POSIXt"), artifact.type = "character", weight = "numeric",
type = "character", relation = "character"
)
mandatory.edge.attributes = names(mandatory.edge.attributes.classes)
mandatory.vertex.attributes.classes = list(name = "character", kind = "character", type = "character")
mandatory.vertex.attributes = names(mandatory.vertex.attributes.classes)

net = add.attributes.to.network(net, "vertex", mandatory.vertex.attributes.classes)
net = add.attributes.to.network(net, "edge", mandatory.edge.attributes.classes)
Expand Down

0 comments on commit e2c9d6c

Please sign in to comment.