This commit is contained in:
夜坂雅 2023-02-15 08:56:06 +08:00
parent 629a253210
commit d63ae5aac4
2 changed files with 9 additions and 13 deletions

View file

@ -57,17 +57,13 @@ fn main() -> Result<()> {
}
fn load_dict(jieba: &mut Jieba) -> Result<()> {
let file = BufReader::new(File::open("userdict.txt")?);
for line in file.lines() {
match line {
Ok(line) => {
let mut it = line.split_whitespace();
let word = it.next().ok_or_else(|| anyhow!("Bad line: {}", line))?;
let tag = Some(it.next().ok_or_else(|| anyhow!("Bad line: {}", line))?);
jieba.add_word(word, None, tag);
}
Err(_) => break,
}
let mut file = BufReader::new(File::open("userdict.txt")?);
let mut line = String::new();
while file.read_line(&mut line)? > 0 {
let mut it = line.trim().split_whitespace();
let word = it.next().ok_or_else(|| anyhow!("Bad line: {}", line))?;
let tag = Some(it.next().ok_or_else(|| anyhow!("Bad line: {}", line))?);
jieba.add_word(word, None, tag);
}
Ok(())
}

View file

@ -15,7 +15,7 @@ from wordcloud import WordCloud
import nyx_bot
from nyx_bot.chat_functions import send_text_to_room
from nyx_bot.storage import MatrixMessage
from nyx_bot.utils import strip_tags, strip_urls
from nyx_bot.utils import strip_tags
CUTWORDS_EXE = "nyx_bot-cutword"
FONT = os.path.join(nyx_bot.__path__[0], "wordcloud_font.ttf")
@ -191,4 +191,4 @@ def gather_messages(
users.add(msg_item.sender)
ret = stringio.getvalue()
return (strip_urls(ret), count, users)
return (ret, count, users)