-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
190 additions
and
113 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
pub mod download_dict; | ||
pub mod lyric_process; | ||
pub mod phoneme_lib; | ||
//pub mod lyric_process; | ||
pub mod tools; | ||
|
||
pub use crate::phoneme_lib::*; | ||
pub use crate::tools::WordList; |
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,45 @@ | ||
use super::tools::*; | ||
use lrc::Lyrics; | ||
use std::collections::BTreeSet; | ||
use std::fmt::Display; | ||
use std::fs::{self, File}; | ||
use std::io::{self, Write}; | ||
use std::path::{Path, PathBuf}; | ||
extern crate lrc; | ||
|
||
pub fn process_lrc<P>(file_name: P, write_to_file: Option<bool>) -> io::Result<WordList> | ||
where | ||
P: AsRef<Path> + Display, | ||
{ | ||
let to_file = write_to_file.unwrap_or(true); | ||
let raw_lyrc = fs::read_to_string(&file_name)?; | ||
let lyc = match Lyrics::from_str(&raw_lyrc) { | ||
Ok(data) => data, | ||
Err(err) => { | ||
println!("{:?}", err); | ||
return Err(io::Error::new( | ||
io::ErrorKind::NotFound, | ||
format!("{} not found", &file_name), | ||
)); | ||
} | ||
}; | ||
let mut set = Box::new(BTreeSet::new()); | ||
for line in lyc.get_lines() { | ||
for words in line.split(' ') { | ||
set.insert(words.to_string()); | ||
} | ||
} | ||
if to_file { | ||
let name = file_name.to_string(); | ||
let final_path_vec: Vec<&str> = name.split_whitespace().collect(); | ||
let final_path = final_path_vec[0].to_owned() + "_word_list.txt"; | ||
let mut word_list = File::create(&final_path)?; | ||
for mut word in *set { | ||
word.push('\n'); | ||
word_list.write_all(word.as_bytes())?; | ||
} | ||
Ok(WordList::Outer(Box::new(PathBuf::from(final_path)))) | ||
} else { | ||
Ok(WordList::Inner(set)) | ||
} | ||
} |
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
Oops, something went wrong.