From 797d8202fde28168ce829198dc2d358001ed17ec Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 1 May 2022 12:57:57 +0300 Subject: add row parsers --- src/reader.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) (limited to 'src/reader.rs') diff --git a/src/reader.rs b/src/reader.rs index 3d02f77..197638a 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,3 +1,4 @@ +use core::panic; //file reads dataset file and also does the parsing //aim is to read this as a stream use std::fs::File; @@ -37,8 +38,57 @@ impl BufferReader{ }).transpose() - } + + pub fn fetch_keys <'a>(&self,row:& 'a str) -> (&str,[&str]){ + + + // parse the line and return (trait_name and trait_values) + + //parse the other body to float type + + let mut buf = String::new(); + // should be taken to own line + + + let sample_buffer = self.read_line(&mut buf); + + let sample_names = match sample_buffer{ + + Some(val)=> { + if let Ok(new_vak) = val{ + + new_vak + + } + + else { + panic!("error happened"); + } + }, + + None => panic!("no sample values found") + + }; + + + + + let string_vec : Vec<&str>= row.split(",").collect(); + + //issue is that spaces are included + + return [string_vec[0],string_vec[1..]]; + } +pub fn row_parser <'a>(&self,row :&'a mut String) ->(& 'a str,Vec<&'a str>){ + + let parsed_row:Vec<&str> = row.split(",").map(|s|s.trim()).collect(); + + let (trait_name,trait_vals) = (parsed_row[0],parsed_row[1..].to_vec()); + + (parsed_row[0],parsed_row[1..].to_vec()) + +} } @@ -50,13 +100,13 @@ pub fn file_reader(file_path:&str) ->Result, Box i32{ a+b } - - #[cfg(test)] mod tests { use super::*; -- cgit 1.4.1