-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_database.rs
More file actions
32 lines (30 loc) · 1.06 KB
/
load_database.rs
File metadata and controls
32 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::database::generate_database::WIKILINKS_SEPARATOR;
use crate::graph_utils::vec_graph_utils::VecGraph;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
pub fn load_name_from_id_and_id_from_name(path: &str) -> (Vec<String>, HashMap<String, usize>) {
let mut name_from_id = Vec::new();
let mut id_from_name = HashMap::new();
let file = BufReader::new(File::open(path).unwrap());
for (id, name) in file.lines().map(|l| l.unwrap()).enumerate() {
id_from_name.insert(name.clone(), id);
name_from_id.push(name);
}
(name_from_id, id_from_name)
}
pub fn load_graph(path: &str) -> VecGraph {
let mut graph = Vec::new();
let file = BufReader::new(File::open(path).unwrap());
for line in file.lines().map(|l| l.unwrap()) {
let parents = if line.is_empty() {
Vec::new()
} else {
line.split(WIKILINKS_SEPARATOR)
.map(|v| v.parse::<usize>().unwrap())
.collect::<Vec<_>>()
};
graph.push(parents);
}
graph
}