diff --git a/src/lib.rs b/src/lib.rs index c3f6c61..a7b082b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,22 +6,18 @@ pub mod wikipedia_infobox_analyzer { /// Looks for a used template that does lists wikidata properties listing pub fn extract_used_properties_from_template(template: String) -> Vec { - let lines = template.lines(); + let mut lines = template.lines(); let used = lines - .filter(|line| line.starts_with("{{Gebruikt Wikidata")) - .nth(0) + .find(|line| line.starts_with("{{Gebruikt Wikidata")) .expect("Template should have a line declaring which properties are used"); // The properties are listed inside the template with their number: P1|P2|P... let re = Regex::new(r"P\d+").unwrap(); - // Find all matches and collect into vector - let properties = re - .find_iter(used) - .map(|m| m.as_str().to_owned()) - .collect::>(); - - return properties; + // Find all matches and collect the properties into vector + re.find_iter(used) + .map(|m| m.as_str().to_owned()) + .collect() } /// Creates an ascii infobox out of the properties @@ -34,23 +30,20 @@ pub mod wikipedia_infobox_analyzer { .set_align(Align::Left); let data: Vec> = properties.iter().map(|v| vec![v]).collect(); - return ascii_table.format(data); + ascii_table.format(data) } /// Fetches the wikidata label for the wiki property pub async fn fetch_name_for_wiki_property(pid: u64) -> String { - let query = format!( - " + let query = format!(" SELECT ?label WHERE {{ - wd:P{} rdfs:label ?label. + wd:P{pid} rdfs:label ?label. FILTER(lang(?label) = \"en\") SERVICE wikibase:label {{ bd:serviceParam wikibase:language 'en'.}} }} - ", - pid - ); + "); let api = mediawiki::api::Api::new("https://www.wikidata.org/w/api.php") .await @@ -63,7 +56,7 @@ pub mod wikipedia_infobox_analyzer { let re = Regex::new("\"value\": \"(.+)\"").unwrap(); let Some(label) = re.captures(&res_s) else { return "".to_string() }; - return label[1].to_string(); + label[1].to_string() } /// Fetches the properties which have claims for the given wiki item inside of wikidata