1use crate::data::example::Example;
2use csv::StringRecord;
3
4use regex::Regex;
5use std::sync::LazyLock;
6
7#[allow(dead_code)]
8static IS_URL_PAT: LazyLock<Regex> = LazyLock::new(|| {
9 Regex::new("((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)"
10).unwrap()
11});
12
13pub fn string_record_to_example(
14 record: StringRecord,
15 input_keys: Vec<String>,
16 output_keys: Vec<String>,
17) -> Example {
18 Example::new(
19 record
20 .iter()
21 .map(|cell| (cell.to_string(), cell.to_string().into()))
22 .collect(),
23 input_keys.clone(),
24 output_keys.clone(),
25 )
26}
27
28pub fn is_url(path: &str) -> bool {
29 IS_URL_PAT.is_match(path)
30}