이제 예광탄에서 만든 EHDbmForAll 클래스로 DBM ForAll 라이브러리를 만듭시다. 만드는 방법은 클라스 라이브러리 템플릿으로 프로젝트 추가합니다. 그리고 제공하는 cs 파일의 이름을 EHDbmForAll로 변경한 후에 앞에서 작성한 EHDbmForAll 소스를 복사해서 붙여 넣습니다.
EHDbmForAll에서는 WSE Core 라이브러리를 사용하므로 참조 추가하는 것을 잊지 마세요. 그리고 프로젝트 속성의 빌드 탭에서 XML 문서 파일 체크 박스를 체크하여 세 줄 주석 작성하는 것도 잊지 마시기 바랍니다.
DBM ForAll 라이브러리는 예광탄으로 정상적으로 수행하는 것을 확인한 EHDbmForAll클래스로 만드는 것이라 별다른 추가 작업이 필요한 것은 아닙니다. 다시 한 번 라이브러리가 정상적인지 확인하기 위해 DBM ForAll 예광탄 프로그램의 EHDbmForAll.cs 파일 내용은 모두 주석 처리한 후에 DBM ForAll 라이브러리를 추가한 후에 다시 한 번 테스트를 하는 것도 좋은 방법입니다.
다음은 EHDbmForAll.cs 파일의 내용입니다.
▷ EHDbmForAll.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
using System.Data.SqlClient; using System.Data; using WSE_Core; using System.Collections.Generic; namespace DBM_ForAll { /// <summary> /// DBMForAll 라이브러리의 모든 기능을 수행하는 정적 클래스 /// </summary> public static class EHDbmForAll { static string constr = @"Data Source=[DBMS 인스턴스 명];Initial Catalog=[DB 명];Persist Security Info=True;User ID=[계정];Password=[비밀번호];Pooling=False;"; /// <summary> /// Seed 사이트를 추가하는 메서드 /// </summary> /// <param name="url">Seed 사이트 주소</param> public static void AddSeedSite(string url) { AddCandidate(url, 0); } /// <summary> /// 수집 대상 사이트를 추가하는 메서드 /// </summary> /// <param name="url">사이트 주소</param> /// <param name="depth">상대적 깊이</param> public static void AddCandidate(string url, int depth) { SqlCommand scom = MakeSPCommand("AddCandidate", CommandType.StoredProcedure); SqlParameter sp_url = new SqlParameter("@Url", url); SqlParameter sp_depth = new SqlParameter("@Depth", depth); scom.Parameters.Add(sp_url); scom.Parameters.Add(sp_depth); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); } static SqlCommand MakeSPCommand(string cmdtext,CommandType cmdtype) { SqlConnection scon = new SqlConnection(constr); SqlCommand scom = new SqlCommand(cmdtext, scon); scom.CommandType = cmdtype; return scom; } /// <summary> /// 수집 대상 사이트 항목 중 맨 앞의 항목 가져오기 /// </summary> /// <returns>수집 대상 사이트</returns> public static Candidate GetFrontCandidate() { SqlCommand scom = MakeSPCommand("GetFrontCandidate", CommandType.StoredProcedure); SqlParameter sp_url = new SqlParameter("@Url", SqlDbType.VarChar, 200); sp_url.Direction = ParameterDirection.Output; SqlParameter sp_depth = new SqlParameter("@Depth", SqlDbType.Int); sp_depth.Direction = ParameterDirection.Output; SqlParameter sp_getted = new SqlParameter("@Getted", SqlDbType.Int); sp_getted.Direction = ParameterDirection.Output; scom.Parameters.Add(sp_url); scom.Parameters.Add(sp_depth); scom.Parameters.Add(sp_getted); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); if ((int)sp_getted.Value == 1) { string url = sp_url.Value as string; int depth = (int)sp_depth.Value; return new Candidate(url, depth); } return null; } /// <summary> /// 수집 대상 사이트 목록 가져오기 /// </summary> /// <returns>수집 대상 사이트 목록</returns> public static List<Candidate> GetCandidates() { List<Candidate> list = new List<Candidate>(); SqlCommand scom = MakeSPCommand( "SELECT Url, Depth From CandidateTable",CommandType.Text); scom.Connection.Open(); SqlDataReader sdr = scom.ExecuteReader(); Candidate candidate = null; while (sdr.Read()) { candidate = new Candidate(); candidate.Url = sdr["Url"] as string; candidate.Depth = (int)sdr["Depth"]; list.Add(candidate); } sdr.Close(); scom.Connection.Close(); return list; } /// <summary> /// 수집한 페이지 정보 보관하기 /// </summary> /// <param name="purl">수집한 페이지 정보 개체</param> public static void StorePostedUrl(PostedUrl purl) { SqlCommand scom = MakeSPCommand("AddPostedUrl", CommandType.StoredProcedure); SqlParameter sp_url = new SqlParameter("@Url", purl.Url); SqlParameter sp_ourl = new SqlParameter("@OriginUrl", purl.OriginUrl); SqlParameter sp_depth = new SqlParameter("@Depth", purl.Depth); SqlParameter sp_ptime=new SqlParameter("@PostedTime",purl.PostedTime); SqlParameter sp_content = new SqlParameter("@PostedContent", purl.Content); SqlParameter sp_title = new SqlParameter("@Title", purl.Title); scom.Parameters.Add(sp_url); scom.Parameters.Add(sp_ourl); scom.Parameters.Add(sp_depth); scom.Parameters.Add(sp_ptime); scom.Parameters.Add(sp_content); scom.Parameters.Add(sp_title); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); } /// <summary> /// 형태소 정보 추가하기 /// </summary> /// <param name="purl">페이지 주소</param> /// <param name="morpheme">형태소 정보 개체</param> /// <returns>추가 여부</returns> public static bool AddMorphemeInfo(string purl, Morpheme morpheme) { bool re = AddMorphemeInfo(morpheme.Name); AddInvertedItem(morpheme.Name, purl, morpheme.Count); return re; } private static void AddInvertedItem(string mname, string purl, int count) { SqlCommand scom = MakeSPCommand("AddInvertedItem", CommandType.StoredProcedure); SqlParameter sp_mor = new SqlParameter("@Morpheme", mname); SqlParameter sp_url = new SqlParameter("@Url", purl); SqlParameter sp_rcnt = new SqlParameter("@Refcnt", count); scom.Parameters.Add(sp_mor); scom.Parameters.Add(sp_url); scom.Parameters.Add(sp_rcnt); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); } private static bool AddMorphemeInfo(string mname) { SqlCommand scom = MakeSPCommand("AddMorphemeInfo", CommandType.StoredProcedure); SqlParameter sp_mor = new SqlParameter("@Morpheme", mname); SqlParameter sp_existed = new SqlParameter("@Existed", SqlDbType.Int); sp_existed.Direction = ParameterDirection.Output; scom.Parameters.Add(sp_mor); scom.Parameters.Add(sp_existed); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); return (int)sp_existed.Value == 0; } /// <summary> /// 형태소 목록 가져오기 /// </summary> /// <returns>형태소 목록</returns> public static List<string> GetMorphemes() { List<string> list = new List<string>(); SqlCommand scom = MakeSPCommand( "SELECT Morpheme FROM IndexInvFileTable",CommandType.Text); scom.Connection.Open(); SqlDataReader sdr = scom.ExecuteReader(); while (sdr.Read()) { list.Add(sdr["Morpheme"] as string); } sdr.Close(); scom.Connection.Close(); return list; } /// <summary> /// 수집한 페이지의 전체 형태소 개수 정보 추가하기 /// </summary> /// <param name="url">페이지 주소</param> /// <param name="tcnt">전체 형태소 개수</param> public static void AddMCPostedInfo(string url, int tcnt) { SqlCommand scom = MakeSPCommand("AddMCPostedUrlInfo", CommandType.StoredProcedure); SqlParameter sp_url = new SqlParameter("@Url", url); SqlParameter sp_tcnt = new SqlParameter("@TotalCount", tcnt); scom.Parameters.Add(sp_url); scom.Parameters.Add(sp_tcnt); scom.Connection.Open(); scom.ExecuteNonQuery(); scom.Connection.Close(); } } } |