From 6476a0f2f8c9ea416a14d8ece5fbeb158499ba9b Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 9 Jan 2024 18:02:55 -0600 Subject: [PATCH] clean up wikipedia extract more --- src/engines/answer/wikipedia.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/engines/answer/wikipedia.rs b/src/engines/answer/wikipedia.rs index 6180157..22900a6 100644 --- a/src/engines/answer/wikipedia.rs +++ b/src/engines/answer/wikipedia.rs @@ -74,11 +74,17 @@ pub fn parse_response(body: &str) -> eyre::Result { return Ok(EngineResponse::new()); } - let extract = extract - .replace("(; ", "(") - .replace("( ; ", "(") - .replace("( )", "") - .replace("()", ""); + let mut previous_extract = "".to_string(); + let mut extract = extract.clone(); + while previous_extract != extract { + previous_extract = extract.clone(); + extract = extract + .replace("(, ", "(") + .replace("(; ", "(") + .replace("( ; ", "(") + .replace("( )", "") + .replace("()", ""); + } let page_title = title.replace(' ', "_"); let page_url = format!("https://en.wikipedia.org/wiki/{page_title}");