|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#[doc = include_str!("../README.md")] |
|
|
|
|
pub mod wikipedia_infobox_analyzer { |
|
|
|
|
use ascii_table::{Align, AsciiTable}; |
|
|
|
|
use regex::Regex; |
|
|
|
|
|
|
|
|
|
/// Looks for a used template that does lists wikidata properties listing
|
|
|
|
@ -21,6 +22,19 @@ pub mod wikipedia_infobox_analyzer { |
|
|
|
|
|
|
|
|
|
return properties; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Creates an ascii infobox out of the properties
|
|
|
|
|
pub fn format_infobox_from_used_properties(name: String, properties: Vec<String>) -> String { |
|
|
|
|
let mut ascii_table = AsciiTable::default(); |
|
|
|
|
ascii_table.set_max_width(26); |
|
|
|
|
ascii_table |
|
|
|
|
.column(0) |
|
|
|
|
.set_header(name) |
|
|
|
|
.set_align(Align::Left); |
|
|
|
|
|
|
|
|
|
let data: Vec<Vec<&String>> = properties.iter().map(|v| vec![v]).collect(); |
|
|
|
|
return ascii_table.format(data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
@ -53,4 +67,23 @@ mod tests { |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_format_infobox_from_used_properties() { |
|
|
|
|
assert_eq!( |
|
|
|
|
format_infobox_from_used_properties( |
|
|
|
|
"Earth".to_string(), |
|
|
|
|
vec!["P31".to_string(), "P361".to_string(), "P571".to_string()] |
|
|
|
|
), |
|
|
|
|
concat![ |
|
|
|
|
"┌───────┐\n", |
|
|
|
|
"│ Earth │\n", // item identifier: Q2
|
|
|
|
|
"├───────┤\n", |
|
|
|
|
"│ P31 │\n", // property: instance of
|
|
|
|
|
"│ P361 │\n", // property: part of
|
|
|
|
|
"│ P571 │\n", // property: inception
|
|
|
|
|
"└───────┘\n" |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|