Ingest new json format
This commit is contained in:
parent
78a5aa5169
commit
0e0789cc4d
5 changed files with 137 additions and 162 deletions
|
|
@ -1,15 +1,14 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Page {
|
||||
pub link_idx: u32,
|
||||
pub ns: u16,
|
||||
pub id: u32,
|
||||
pub title: String,
|
||||
pub redirect: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Link {
|
||||
pub to: u32,
|
||||
pub start: u32,
|
||||
|
|
@ -21,49 +20,3 @@ pub struct AdjacencyList {
|
|||
pub pages: Vec<Page>,
|
||||
pub links: Vec<Link>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SlimAdjacencyList {
|
||||
pages: Vec<(u32, u32, u16, String, bool)>,
|
||||
links: Vec<(u32, u32, u32)>,
|
||||
}
|
||||
|
||||
impl SlimAdjacencyList {
|
||||
pub fn from_alist(alist: AdjacencyList) -> Self {
|
||||
let pages = alist
|
||||
.pages
|
||||
.into_iter()
|
||||
.map(|p| (p.link_idx, p.id, p.ns, p.title, p.redirect))
|
||||
.collect();
|
||||
|
||||
let links = alist
|
||||
.links
|
||||
.into_iter()
|
||||
.map(|l| (l.to, l.start, l.end))
|
||||
.collect();
|
||||
|
||||
Self { pages, links }
|
||||
}
|
||||
|
||||
pub fn to_alist(self) -> AdjacencyList {
|
||||
let pages = self
|
||||
.pages
|
||||
.into_iter()
|
||||
.map(|(link_idx, id, ns, title, redirect)| Page {
|
||||
link_idx,
|
||||
ns,
|
||||
id,
|
||||
title,
|
||||
redirect,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let links = self
|
||||
.links
|
||||
.into_iter()
|
||||
.map(|(to, start, end)| Link { to, start, end })
|
||||
.collect();
|
||||
|
||||
AdjacencyList { pages, links }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue