Skip to content
Open
Changes from all commits
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
31 changes: 20 additions & 11 deletions src/data_structures/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Node<T> {
pub id: usize,
pub x: usize,
pub y: usize,
pub label: (Option<T>, Option<T>),
pub label: (Option<Vec<T>>, Option<Vec<T>>),
}

struct Task<'a> {
Expand All @@ -40,6 +40,7 @@ impl<T: Clone> Graph<T> {
}
}

/// Creates a Graph from a set of concepts and their context.
pub fn from_concepts(
concepts: &Vec<(BitSet, BitSet)>,
context: &FormalContext<T>,
Expand Down Expand Up @@ -139,15 +140,23 @@ impl<T: Clone> Graph<T> {
.iter()
.position(|node| node.id == concept_index)
.unwrap();
nodes[index].label.0 = Some(context.objects[obj].clone());
if let Some(ref mut obj_vec) = nodes[index].label.0 {
obj_vec.push(context.objects[obj].clone());
} else {
nodes[index].label.0 = Some(vec![context.objects[obj].clone()]);
}
}

for (concept_index, attr) in attr_labels {
let index = nodes
.iter()
.position(|node| node.id == concept_index)
.unwrap();
nodes[index].label.1 = Some(context.attributes[attr].clone());
if let Some(ref mut attr_vec) = nodes[index].label.1 {
attr_vec.push(context.attributes[attr].clone());
} else {
nodes[index].label.1 = Some(vec![context.attributes[attr].clone()]);
}
}

let graph = Graph {
Expand Down Expand Up @@ -191,49 +200,49 @@ mod tests {
id: 1,
x: 3,
y: 3,
label: (Some("3".to_string()), Some("0".to_string())),
label: (Some(vec!["3".to_string()]), Some(vec!["0".to_string()])),
});
nodes.push(Node {
id: 2,
x: 1,
y: 1,
label: (None, Some("1".to_string())),
label: (None, Some(vec!["1".to_string()])),
});
nodes.push(Node {
id: 3,
x: 3,
y: 1,
label: (Some("2".to_string()), Some("2".to_string())),
label: (Some(vec!["2".to_string()]), Some(vec!["2".to_string()])),
});
nodes.push(Node {
id: 4,
x: 0,
y: 1,
label: (Some("4".to_string()), Some("3".to_string())),
label: (Some(vec!["4".to_string()]), Some(vec!["3".to_string()])),
});
nodes.push(Node {
id: 5,
x: 2,
y: 1,
label: (Some("6".to_string()), Some("4".to_string())),
label: (Some(vec!["6".to_string()]), Some(vec!["4".to_string()])),
});
nodes.push(Node {
id: 6,
x: 3,
y: 2,
label: (Some("5".to_string()), None),
label: (Some(vec!["5".to_string()]), None),
});
nodes.push(Node {
id: 7,
x: 0,
y: 2,
label: (Some("0".to_string()), None),
label: (Some(vec!["0".to_string()]), None),
});
nodes.push(Node {
id: 8,
x: 1,
y: 2,
label: (Some("1".to_string()), None),
label: (Some(vec!["1".to_string()]), None),
});
nodes.push(Node {
id: 9,
Expand Down