Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on the simplification of multi-relation edges in networks #255

Merged
merged 14 commits into from
Mar 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions tests/test-networks.R
bockthom marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,153 @@ test_that("Simplify network with more than one relation", {

})

test_that("Simplify basic multi-relational network", {

##
## Simplify networks with vertices connected by multi-relational edges
##

## create network configuration
net.conf = NetworkConf$new()
bockthom marked this conversation as resolved.
Show resolved Hide resolved

## create artifact network with vertices connected by "cochange" and "mail edges"
network =
igraph::make_empty_graph(n = 0, directed = FALSE) +
igraph::vertices("A", "B", type = TYPE.ARTIFACT, kind = "feature")
for (i in 1:3) {
network = igraph::add.edges(network, c("A", "B"), type = TYPE.EDGES.INTRA, relation = "mail")
network = igraph::add.edges(network, c("A", "B"), type = TYPE.EDGES.INTRA, relation = "cochange")
}

network.expected = igraph::make_empty_graph(n = 0, directed = FALSE) +
igraph::vertices("A", "B", type = TYPE.ARTIFACT, kind = "feature") +
igraph::edges("A", "B", type = TYPE.EDGES.INTRA, relation = "mail") +
igraph::edges("A", "B", type = TYPE.EDGES.INTRA, relation = "cochange")

## simplify network without simplifying multiple relations into single edges
network.simplified = simplify.network(network, simplify.multiple.relations = FALSE)
assert.networks.equal(network.simplified, network.expected)

## simplify network with simplifying multiple relations into single edges
network.simplified = simplify.network(network, simplify.multiple.relations = TRUE)
network.simplified = simplify.network(network, simplify.multiple.relations = TRUE)
expect_identical(igraph::ecount(simplify.network(network.simplified)), 1)
bockthom marked this conversation as resolved.
Show resolved Hide resolved
expect_identical(igraph::E(network.simplified)$type[[1]], "Unipartite")
expect_identical(igraph::E(network.simplified)$relation[[1]], c("cochange", "mail"))
})

test_that("Simplify author-network with relation = c('cochange', 'mail') using both algorithms", {

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = c("cochange", "mail")))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## vertex attributes
authors = data.frame(name = c("Björn", "Olaf", "Karl", "Thomas", "udo", "Fritz [email protected]", "georg", "Hans"),
kind = TYPE.AUTHOR,
type = TYPE.AUTHOR)


## ---------------------- simplify.multiple.relations == FALSE -------------------------- ##

## edge attributes
data = data.frame(comb.1. = c("Björn", "Olaf", "Olaf", "Karl", # cochange
"Björn", "Olaf"), # mail
comb.2. = c("Olaf", "Karl", "Thomas", "Thomas", # cochange
"Olaf", "Thomas")) # mail
data$date = list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45")),
get.date.from.string(c("2016-07-12 16:05:41", "2016-07-12 16:06:10")),
get.date.from.string(c("2016-07-12 16:05:41", "2016-07-12 16:06:32")),
get.date.from.string(c("2016-07-12 16:06:10", "2016-07-12 16:06:32")), # cochange
get.date.from.string(c("2016-07-12 15:58:40", "2016-07-12 15:58:50")),
get.date.from.string(c("2016-07-12 16:04:40", "2016-07-12 16:05:37"))) # mail
data$artifact.type = list(c("Feature", "Feature"), c("Feature", "Feature"),
c("Feature", "Feature"), c("Feature", "Feature"), # cochange
c("Mail", "Mail"), c("Mail", "Mail")) # mail
data$hash = list(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338"),
c("3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61"),
c("3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526"),
c("1143db502761379c2bfcecc2007fc34282e7ee61", "0a1a5c523d835459c42f33e863623138555e2526"),
as.character(c(NA, NA)), as.character(c(NA, NA)))
data$file = list(c("test.c", "test.c"), c("test2.c", "test3.c"), c("test2.c", "test2.c"), c("test3.c", "test2.c"),
as.character(c(NA, NA)), as.character(c(NA, NA)))
data$artifact = list(c("A", "A"), c("Base_Feature", "Base_Feature"), c("Base_Feature", "Base_Feature"),
c("Base_Feature", "Base_Feature"), as.character(c(NA, NA)), as.character(c(NA, NA)))
data$weight = rep(2, 6)
data$type = rep(TYPE.EDGES.INTRA, 6)
data$relation = c(rep("cochange", 4), rep("mail", 2))
data$message.id = list(as.character(c(NA, NA)), as.character(c(NA, NA)), as.character(c(NA, NA)), as.character(c(NA, NA)),
c("<[email protected]>",
"<[email protected]>"),
c("<[email protected]>",
"<[email protected]>"))
data$thread = list(as.character(c(NA, NA)), as.character(c(NA, NA)), as.character(c(NA, NA)), as.character(c(NA, NA)),
c("<thread-13#8>", "<thread-13#8>"), c("<thread-13#9>", "<thread-13#9>"))

## build expected network
network.expected = igraph::graph.data.frame(data, vertices = authors,
directed = net.conf$get.value("author.directed"))

## build network and simplify it
network.built = simplify.network(network.builder$get.author.network())

assert.networks.equal(network.built, network.expected)


## ---------------------- simplify.multiple.relations == TRUE --------------------------- ##

data = data.frame(comb.1. = c("Björn", "Olaf", "Olaf", "Karl"),
comb.2. = c("Olaf", "Karl", "Thomas", "Thomas"))
bockthom marked this conversation as resolved.
Show resolved Hide resolved

data$date = list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", # cochange
"2016-07-12 15:58:40", "2016-07-12 15:58:50")), # mail
get.date.from.string(c("2016-07-12 16:05:41", "2016-07-12 16:06:10")), # cochange
get.date.from.string(c("2016-07-12 16:05:41", "2016-07-12 16:06:32", # cochange
"2016-07-12 16:04:40", "2016-07-12 16:05:37")), # mail
get.date.from.string(c("2016-07-12 16:06:10", "2016-07-12 16:06:32"))) # cochange
data$artifact.type = list(c("Feature", "Feature", "Mail", "Mail"),
c("Feature", "Feature"),
c("Feature", "Feature", "Mail", "Mail"),
c("Feature", "Feature"))
data$hash = list(as.character(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338", NA, NA)),
c("3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61"),
as.character(c("3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", NA, NA)),
c("1143db502761379c2bfcecc2007fc34282e7ee61", "0a1a5c523d835459c42f33e863623138555e2526"))
data$file = list(as.character(c("test.c", "test.c", NA, NA)), c("test2.c", "test3.c"),
as.character(c("test2.c", "test2.c", NA, NA)), c("test3.c", "test2.c"))
data$artifact = list(as.character(c("A", "A", NA, NA)), c("Base_Feature", "Base_Feature"),
as.character(c("Base_Feature", "Base_Feature", NA, NA)), c("Base_Feature", "Base_Feature"))
data$weight = c(4, 2, 4, 2)
data$type = rep(TYPE.EDGES.INTRA, 4)
data$relation = list(c("cochange", "mail"), c("cochange"), c("cochange", "mail"), c("cochange"))
data$message.id = list(as.character(c(NA, NA, "<[email protected]>",
"<[email protected]>")),
as.character(c(NA, NA)),
as.character(c(NA, NA, "<[email protected]>",
"<[email protected]>")),
as.character(c(NA, NA)))
data$thread = list(as.character(c(NA, NA, "<thread-13#8>", "<thread-13#8>")),
as.character(c(NA, NA)),
as.character(c(NA, NA, "<thread-13#9>", "<thread-13#9>")),
as.character(c(NA, NA)))

## build expected network
network.expected = igraph::graph.data.frame(data, vertices = authors,
directed = net.conf$get.value("author.directed"))

## build network and simplify it
network.built = simplify.network(network.builder$get.author.network(), simplify.multiple.relations = TRUE)

assert.networks.equal(network.built, network.expected)

})


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Merge -------------------------------------------------------------------
Expand Down
Loading