about summary refs log tree commit diff
path: root/src/reader.rs
diff options
context:
space:
mode:
authorAlexander <alexanderkabua@gmail.com>2022-05-01 12:57:57 +0300
committerAlexander <alexanderkabua@gmail.com>2022-05-01 12:57:57 +0300
commit797d8202fde28168ce829198dc2d358001ed17ec (patch)
tree55237093972f277531165ffdbd166d0f22056135 /src/reader.rs
parentb042790150b0cf8bc794c262ea2c3caaae762477 (diff)
downloadcorrelation_rust-797d8202fde28168ce829198dc2d358001ed17ec.tar.gz
add row parsers
Diffstat (limited to 'src/reader.rs')
-rw-r--r--src/reader.rs56
1 files changed, 53 insertions, 3 deletions
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<BufReader<File>, Box<dyn std::error:
     Ok(buf_reader)
 }
 
+
+
 pub fn add_numbers_2(a:i32,b:i32) -> i32{
     a+b
 }
 
 
-
-
 #[cfg(test)]
 mod tests {
     use super::*;