-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bb066d
commit c0f3c81
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::PathBuf; | ||
|
||
use super::definition::Loader; | ||
use crate::config::Config; | ||
|
||
pub struct FileLoader { | ||
pub config: Config, | ||
} | ||
|
||
impl FileLoader { | ||
pub fn new(language: String, directory: String) -> Self { | ||
let config = Config { | ||
language, | ||
directory, | ||
max_sentences_per_text: std::usize::MAX, | ||
file_prefix: String::from(""), | ||
}; | ||
|
||
Self { config } | ||
} | ||
} | ||
|
||
impl Loader for FileLoader { | ||
fn get_config(&self) -> &Config { | ||
&self.config | ||
} | ||
|
||
fn load(&self, file_name: &PathBuf) -> Result<Vec<String>, String> { | ||
let mut file = File::open(file_name).map_err(|e| format!("{}", e))?; | ||
let mut all_sentences = String::new(); | ||
file.read_to_string(&mut all_sentences) | ||
.map_err(|e| format!("{}", e))?; | ||
Ok(all_sentences | ||
.lines() | ||
.map(|sentence| String::from(sentence)) | ||
.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub use wikipedia::Wikipedia; | ||
pub use file::FileLoader as File; | ||
pub use definition::Loader; | ||
|
||
pub mod wikipedia; | ||
pub mod file; | ||
mod definition; |