uiuifree_mecab/
lib.rs

1use mecab::Tagger;
2
3pub struct Mecab {
4    arg: String,
5}
6
7pub struct MecabResponse {
8    pub values: Vec<String>,
9}
10
11impl Mecab {
12    pub fn new(arg: &str) -> Mecab {
13        Mecab {
14            arg: arg.to_string(),
15        }
16    }
17    pub fn get(&self) -> &str {
18        self.arg.as_str()
19    }
20
21    pub fn get_worlds(&self, input: &str) -> Vec<String> {
22        let tagger = Tagger::new(self.arg.clone());
23
24        let result = tagger.parse_str(input);
25        let rows: Vec<&str> = result.split("\n").collect();
26
27        let mut node = Vec::new();
28        for row in rows {
29            if row.len() == 0 {
30                continue;
31            }
32            let line: Vec<&str> = row.trim().split("\t").collect();
33            let word = line[0];
34            if line.len() >= 2 {
35                let w: Vec<&str> = line[1].split(",").collect();
36                if w.len() >= 2 && w[1] == "数" {
37                    continue;
38                }
39                if w.len() >= 3 && w[2] == "地域" {
40                    continue;
41                }
42            }
43            if word == "EOS" {
44                continue;
45            }
46            if word.len() >= 2 {
47                node.push(line[0].to_string());
48            }
49        }
50        return node;
51    }
52
53    pub fn parse(&self, input: &str) -> MecabResponse {
54        let tagger = Tagger::new(self.arg.clone());
55
56        let result = tagger.parse_str(input);
57        let rows: Vec<&str> = result.split("\n").collect();
58
59        let mut response = MecabResponse { values: Vec::new() };
60        for row in rows {
61            let row: Vec<&str> = row.trim().split("\t").collect();
62            if row[0] == "EOS" {
63                break;
64            }
65            response.values.push(row[0].to_string());
66        }
67        response
68    }
69}
70
71pub fn echo() {
72    println!("uiuifree-mecab")
73}
74
75#[cfg(test)]
76mod tests {
77
78    use crate::Mecab;
79
80    #[test]
81    fn it_works() {
82        let  mecab = Mecab::new("-d /usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd -u /home/uiuifree/PycharmProjects/seo-site-crow/storage/output_dic.dic");
83
84        println!(
85            "{:?}",
86            mecab.get_worlds("ケアマネージャー(介護支援専門員)")
87        );
88        // println!("{:?}",mecab.get_worlds("【広島市東区】特別養護老人ホームにおける看護職(日勤のみの特別養護老人ホームの常勤看護職)"));
89        // println!("{:?}",mecab.get_worlds("サービス付き高齢者向け住宅"));
90
91        // println!("{:?}",mecab.get_worlds("社会保険完備"));
92        // println!("{:?}",mecab.get_worlds("週休2日制"));
93        // println!("{:?}",mecab.get_worlds("土日祝休み"));
94        // println!("{:?}",mecab.get_worlds("土日休み"));
95        // println!("{:?}",mecab.get_worlds("資格取得支援"));
96        // println!("{:?}",mecab.get_worlds("研修制度"));
97        // println!("{:?}",mecab.get_worlds("無資格OK"));
98        // println!("{:?}",mecab.get_worlds("在宅手当あり"));
99        // println!("{:?}",mecab.get_worlds("退職金あり"));
100        // println!("{:?}",mecab.get_worlds("寮あり"));
101        // println!("{:?}",mecab.get_worlds("福利厚生が充実!車通勤可能な事業所"));
102        // println!("{:?}",mecab.get_worlds("福利厚生が充実!車通勤可な事業所"));
103        // println!("{:?}",mecab.get_worlds("(仮称)特別養護老人ホーム上永谷町(令和4年7月 新規オープン)"));
104        // println!("{:?}",mecab.get_worlds("心や気持ちを大事にしながら働ける職場。就業システムが構築され残業なし。"));
105        // println!("{:?}",mecab.get_worlds("心や気持ちを大事にしながら働ける職場。就業システムが構築され残業なし。 地域の福祉センター!施設福祉と在宅福祉の両方から介護サービスを提供☆"));
106
107    }
108}