|  | 
| 한글 형태소 분석기 | 작성자 | 송준영 | 
| 작성일 | 2011.12.19 | 
조사사전과 단어사전
| private List<Josa> listJosa = new List<Josa>(); private List<Dictionary> listDictionary = new List<Dictionary>(); 
 private void SettingDictionary() { for (int i = 1; i < 6; i++) { StreamReader sr = new StreamReader(@"C:\Users\Eod\Desktop\ASP.NET\ EodMorphemeAnalysis\EodMorphemeAnalysis\사전\" + i + ".txt", Encoding.Default); string word = string.Empty; while ((word = sr.ReadLine()) != null) { listDictionary.Add(new Dictionary(word)); } } } 
 private void SettingJosa() { StreamReader sr = new StreamReader(@"C:\Users\Eod\Desktop\ASP.NET\ EodMorphemeAnalysis\EodMorphemeAnalysis\사전\JOSA.TXT", Encoding.Default); string josa = string.Empty; while ((josa = sr.ReadLine()) != null) { listJosa.Add(new Josa(josa.Length, josa)); } } 
 | 
분석할 txt파일 불러오기
| FileStream fs = new FileStream(@"C:\Users\Eod\Desktop\테스트.txt", FileMode.OpenOrCreate); 
 int size = (int)fs.Length; byte[] buffers = new byte[size]; fs.Read(buffers, 0, size); 
 string str = Encoding.Default.GetString(buffers, 0, size); | 
문자열 자르기
| string[] word = str.Split(' ', '\r', '\n', '\"', '.', ',', '?', '!', ':', '\'', '+', '-', '*', '/', '[', ']', ';', '<', '>', '{', '}', '(', ')', '_', '^'); foreach (string w in word) { if (w != "") { p.MorphemeAnalysis(w); } } | 
문자열에서 조사를 자르기
| private void MorphemeAnalysis(string word) { int maxLength = 0; foreach (Josa j in listJosa) { if (word.Contains(j.Word.ToString())) { if (maxLength < j.Length) { maxLength = j.Length; } } } string morpheme = word.Substring(0, word.Length - maxLength); DictionaryAnalysis(morpheme); } | 
사전과 비교하여 형태소 확인하기
| private void DictionaryAnalysis(string morpheme) { 
 foreach (Dictionary dic in listDictionary) { if (morpheme == dic.Word.ToString()) { SumMorpheme(morpheme); } } } | 
빈도수 측정하기
| private void SumMorpheme(string morpheme) { if (dicMorphemeTotal.ContainsKey(morpheme)) { dicMorphemeTotal[morpheme]++; } else { dicMorphemeTotal.Add(morpheme, 1); } 
 } | 
결과
|  | 
