use crate::content::Image;
use crate::reference::Citation;
use crate::Link;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Infobox {
pub name: Option<String>,
#[serde(rename = "type")]
pub infobox_type: InfoboxType,
pub value: Option<String>,
pub has_parts: Option<Vec<InfoboxPart>>,
pub links: Option<Vec<Link>>,
pub images: Option<Vec<Image>>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum InfoboxType {
#[serde(rename = "infobox")]
Infobox,
#[serde(rename = "field")]
Field,
#[serde(rename = "section")]
Section,
#[serde(rename = "image")]
Image,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct InfoboxPart {
pub name: Option<String>,
#[serde(rename = "type")]
pub part_type: InfoboxPartType,
pub value: Option<String>,
pub values: Option<Vec<String>>,
pub has_parts: Option<Vec<InfoboxPart>>,
pub links: Option<Vec<Link>>,
pub images: Option<Vec<Image>>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum InfoboxPartType {
#[serde(rename = "infobox")]
Infobox,
#[serde(rename = "field")]
Field,
#[serde(rename = "section")]
Section,
#[serde(rename = "image")]
Image,
#[serde(rename = "list")]
List,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Section {
pub name: Option<String>,
#[serde(rename = "type")]
pub section_type: SectionType,
pub value: Option<String>,
pub links: Option<Vec<Link>>,
pub citations: Option<Vec<Citation>>,
pub has_parts: Option<Vec<Section>>,
pub table_references: Option<Vec<TableReference>>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SectionType {
#[serde(rename = "section")]
Section,
#[serde(rename = "paragraph")]
Paragraph,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct TableReference {
pub identifier: String,
pub confidence_score: f64,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Table {
pub identifier: String,
pub headers: Vec<Vec<TableCell>>,
pub rows: Vec<Vec<TableCell>>,
pub confidence_score: f64,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct TableCell {
pub value: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_infobox_creation() {
let infobox = Infobox {
name: Some("Automatic taxobox".to_string()),
infobox_type: InfoboxType::Infobox,
value: None,
has_parts: Some(vec![InfoboxPart {
name: Some("Kingdom:".to_string()),
part_type: InfoboxPartType::Field,
value: Some("Animalia".to_string()),
values: None,
has_parts: None,
links: None,
images: None,
}]),
links: None,
images: None,
};
assert_eq!(infobox.name, Some("Automatic taxobox".to_string()));
assert!(!infobox.has_parts.as_ref().unwrap().is_empty());
}
#[test]
fn test_section_creation() {
let section = Section {
name: Some("Personal life".to_string()),
section_type: SectionType::Section,
value: None,
links: None,
citations: None,
has_parts: Some(vec![Section {
name: Some("Relationships".to_string()),
section_type: SectionType::Section,
value: Some("Baker's first marriage...".to_string()),
links: None,
citations: None,
has_parts: None,
table_references: None,
}]),
table_references: None,
};
assert_eq!(section.name, Some("Personal life".to_string()));
}
#[test]
fn test_table_creation() {
let table = Table {
identifier: "demographics_table1".to_string(),
headers: vec![vec![
TableCell {
value: "Year".to_string(),
},
TableCell {
value: "Pop.".to_string(),
},
]],
rows: vec![vec![
TableCell {
value: "1666".to_string(),
},
TableCell {
value: "625".to_string(),
},
]],
confidence_score: 0.9,
};
assert_eq!(table.identifier, "demographics_table1");
assert_eq!(table.rows.len(), 1);
}
#[test]
fn test_table_cell() {
let cell = TableCell {
value: "Test value".to_string(),
};
assert_eq!(cell.value, "Test value");
}
}