1. 타이핑 분해 작성 (C++ 라이브러리 -> C# 코드)

2. 사일런트 모드에서 탭 진행 불가 (테스트 완료)
This commit is contained in:
2021-08-03 19:32:27 +09:00
parent 3a53a27240
commit 240e6c3b45
5 changed files with 770 additions and 393 deletions

View File

@@ -3,18 +3,30 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NaverSearcher", "NaverSearcher\NaverSearcher.csproj", "{54262938-66CB-4A5F-926B-48C3ACDCE9CF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NaverSearcher", "NaverSearcher\NaverSearcher.csproj", "{54262938-66CB-4A5F-926B-48C3ACDCE9CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|x64.ActiveCfg = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|x64.Build.0 = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|x86.ActiveCfg = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Debug|x86.Build.0 = Debug|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|Any CPU.Build.0 = Release|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|x64.ActiveCfg = Release|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|x64.Build.0 = Release|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|x86.ActiveCfg = Release|Any CPU
{54262938-66CB-4A5F-926B-48C3ACDCE9CF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -3,14 +3,8 @@ using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NaverSearcher
@@ -44,8 +38,8 @@ namespace NaverSearcher
ChromeDriverService _ChromeDriverService = ChromeDriverService.CreateDefaultService();
_ChromeDriverService.HideCommandPromptWindow = true;
_ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
//_ChromeDriver = new ChromeDriver();
//_ChromeDriver = new ChromeDriver(_ChromeDriverService, _ChromeOptions);
_ChromeDriver = new ChromeDriver();
//_ChromeOptions.add_argument("user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
@@ -54,11 +48,7 @@ namespace NaverSearcher
// 검색어 1페어
// 로그인 여부 확인
// 로그아웃 실행
// 네이버 메인
// 스크롤 내린다.
// 20 ~ 60초 대기
// 검색어 입력 (검색어 1)
// 검색어 확인
@@ -152,9 +142,64 @@ namespace NaverSearcher
_ChromeDriver.get('http://www.google.com/')
*/
_ChromeDriver.Navigate().GoToUrl(@"https://naver.com");
WebDriverWait _WebDriverWait = new WebDriverWait(_ChromeDriver, TimeSpan.FromSeconds(3));
var rand = new Random();
string[][] key_word =
{
new string[] {"바나나우유 라떼", "초코우유 라떼" },
new string[] { "민트초코바", "민트색" }
};
foreach (string[] key_pair in key_word)
{
// 로그인 여부 확인
// 로그아웃 실행
// 네이버 메인
// 스크롤 내린다.
// 20 ~ 60초 대기
foreach (string key in key_pair)
{
// 검색어 입력 (검색어 1)
// 검색어 확인
// 스크롤 내린다.
// 20 ~ 60초 대기
// 아무 게시글 클릭
// 이동된 페이지 작업
// 스크롤 내리기
// 20 ~ 60초 대기
// 새창 닫기
_ChromeDriver.Navigate().GoToUrl(@"https://naver.com");
string _search_xpath = "//*[@id=\"query\"]";
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_search_xpath)));
var _elment = _ChromeDriver.FindElement(By.XPath(_search_xpath));
foreach (var item in HangulString.CharacterMakeHistory(key))
{
_elment.Clear();
_elment.SendKeys(item);
Delay(rand.Next(500, 1000));
}
_elment.SendKeys(OpenQA.Selenium.Keys.Enter);
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Delay(rand.Next(2000, 6000));
ReadOnlyCollection<IWebElement> links = _ChromeDriver.FindElements(By.TagName("a"));
links[rand.Next(0, links.Count)].Click();
((IJavaScriptExecutor)_ChromeDriver).ExecuteScript("window.scrollBy(0, document.body.scrollHeight);");
Delay(rand.Next(2000, 6000));
}
}
return;
var elem = _ChromeDriver.FindElementByXPath("//*");
var source_code = elem.GetAttribute("outerHTML");
@@ -246,11 +291,11 @@ namespace NaverSearcher
{
}
string _search_xpath = "//*[@id=\"react-root\"]/section/nav/div[2]/div/div/div[2]/input";
//_search_xpath = "//*[@id=\"react-root\"]/section/nav/div[2]/div/div/div[2]/input";
_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_search_xpath)));
//_WebDriverWait.Until(ExpectedConditions.ElementIsVisible(By.XPath(_search_xpath)));
_ChromeDriver.FindElement(By.XPath(_search_xpath)).SendKeys(@"인플 검색");
//_ChromeDriver.FindElement(By.XPath(_search_xpath)).SendKeys(@"인플 검색");
}
catch (Exception ex)
@@ -261,25 +306,36 @@ namespace NaverSearcher
private void Form1_Load(object sender, EventArgs e)
{
#region
string kknd = HangulString.SplitToPhonemes("ㅄ");
MessageBox.Show(kknd);
char[] arr = kknd.ToCharArray();
foreach (var item in arr)
{
Trace.WriteLine(item);
}
#endregion
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_ChromeDriver.Quit();
}
private static DateTime Delay(int MS)
{
DateTime ThisMoment = DateTime.Now;
TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
DateTime AfterWards = ThisMoment.Add(duration);
while (AfterWards >= ThisMoment)
{
System.Windows.Forms.Application.DoEvents();
ThisMoment = DateTime.Now;
}
return DateTime.Now;
}
}
}

View File

@@ -10,6 +10,77 @@ namespace NaverSearcher
/// </summary>
public class HangulString
{
private static readonly Dictionary<char, string> Nucleus_Sub = new Dictionary<char, string>()
{
{'ㅘ', "ㅗㅏ"}, {'ㅙ', "ㅗㅐ"}, {'ㅚ', "ㅗㅣ"}, {'ㅝ', "ㅜㅓ"}, {'ㅟ', "ㅜㅣ"}, {'ㅞ', "ㅜㅔ"}
};
private static readonly Dictionary<char, string> Coda_Sub = new Dictionary<char, string>()
{
{'ㄳ', "ㄱㅅ"}, {'ㄵ', "ㄴㅈ"}, {'ㄶ', "ㄴㅎ"}, {'ㄺ', "ㄹㄱ"}, {'ㄻ', "ㄹㅁ"}, {'ㄼ', "ㄹㅂ"}, {'ㄽ', "ㄹㅅ"},
{'ㄾ', "ㄹㅌ"}, {'ㄿ', "ㄹㅍ"}, {'ㅀ', "ㄹㅎ"}, {'ㅄ', "ㅂㅅ"}
};
///< 초성 테이블
private static readonly char[] wcHead =
{
'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ',
'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ',
'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ',
'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ',
'ㅌ', 'ㅍ', 'ㅎ'
};
///< 중성 테이블
private static readonly char[] wcMid =
{
'ㅏ', 'ㅐ', 'ㅑ', 'ㅒ',
'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ',
'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ',
'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ',
'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'
};
///< 중성 합성 테이블
private static readonly char[,] wcMidMix =
{
{'ㅗ', 'ㅏ', 'ㅘ'},
{'ㅗ', 'ㅐ', 'ㅙ'},
{ 'ㅗ', 'ㅑ', 'ㅚ'},
{ 'ㅜ', 'ㅓ', 'ㅝ'},
{ 'ㅜ', 'ㅔ', 'ㅞ'},
{ 'ㅜ', 'ㅣ', 'ㅟ'},
{ 'ㅡ', 'ㅣ', 'ㅢ'},
};
///< 종성 테이블
private static readonly char[] wcTail =
{
' ', 'ㄱ', 'ㄲ', 'ㄳ',
'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ',
'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ',
'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ',
'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ',
'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ',
'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'
};
///< 중성 합성 테이블
private static readonly char[,] wcTailMix =
{
{ 'ㄱ', 'ㅅ', 'ㄳ'},
{ 'ㄴ', 'ㅈ', 'ㄵ'},
{ 'ㄴ', 'ㅎ', 'ㄶ'},
{ 'ㄹ', 'ㄱ', 'ㄺ'},
{ 'ㄹ', 'ㅁ', 'ㄻ'},
{ 'ㄹ', 'ㅂ', 'ㄼ'},
{ 'ㄹ', 'ㅅ', 'ㄽ'},
{ 'ㄹ', 'ㅌ', 'ㄾ'},
{ 'ㄹ', 'ㅍ', 'ㄿ'},
{ 'ㄹ', 'ㅎ', 'ㅀ'},
{ 'ㅂ', 'ㅅ', 'ㅄ'},
};
/// <summary>
/// 문자열로부터 한글 문자열 클래스의 인스턴스를 생성합니다.
/// </summary>
@@ -149,43 +220,55 @@ namespace NaverSearcher
{
// 초성-중성으로만 이루어져 있는 경우 종성은 반환 문자열에 포함하지 않음
if (pc != (char)0x00)
{
// 추가 분리 가능할때
if (Nucleus_Sub.ContainsKey(pc))
{
foreach (char item in Nucleus_Sub[pc].ToCharArray())
{
sb.Append(item);
}
}
else if (Coda_Sub.ContainsKey(pc))
{
foreach (char item in Coda_Sub[pc].ToCharArray())
{
sb.Append(item);
}
}
else
{
sb.Append(pc);
}
}
}
}
// 한글 음절이 아닌 경우
else
{
sb.Append(c);
}
}
// 여기에서 한번더 수행한다.
StringBuilder sb2 = new StringBuilder();
foreach (char c in sb.ToString())
// 추가 분리 가능할때
if (Nucleus_Sub.ContainsKey(c))
{
HangulChar hc = new HangulChar(c);
// 한글 음절로 판명되어 분리가 가능한 경우
if (hc.TrySplitSyllable(out char[] phonemes))
foreach (char item in Nucleus_Sub[c].ToCharArray())
{
foreach (char pc in phonemes)
{
// 초성-중성으로만 이루어져 있는 경우 종성은 반환 문자열에 포함하지 않음
if (pc != (char)0x00)
{
sb.Append(pc);
sb.Append(item);
}
}
else if (Coda_Sub.ContainsKey(c))
{
foreach (char item in Coda_Sub[c].ToCharArray())
{
sb.Append(item);
}
}
// 한글 음절이 아닌 경우
else
{
sb.Append(c);
}
}
}
return sb2.ToString();
return sb.ToString();
}
/// <summary>
@@ -386,5 +469,234 @@ namespace NaverSearcher
/// <returns></returns>
private static string RemoveWhiteSpaces(string aString) =>
new string(aString.Where(c => !char.IsWhiteSpace(c)).Select(c => c).ToArray());
// c++ -> C#
private static bool IsMidMix(char wc, ref char pFirst, ref char pSeconde)
{
for (int i = 0; i < wcMidMix.GetLength(0); i++)
{
if (wcMidMix[i, 2] == wc)
{
pFirst = wcMidMix[i, 0];
pSeconde = wcMidMix[i, 1];
return true;
}
}
return false;
}
// C++ -> C#
private static bool IsTailMix(char wc, ref char pFirst, ref char pSeconde)
{
for (int i = 0; i < wcTailMix.GetLength(0); i++)
{
if (wcTailMix[i, 2] == wc)
{
pFirst = wcTailMix[i, 0];
pSeconde = wcTailMix[i, 1];
return true;
}
}
return false;
}
// C++ -> C#
private static bool IsFusionTailMix(char wcFirst, char wcSeconde, ref char pResult)
{
int dIndex = -1;
for (int i = 0; i < wcTailMix.GetLength(0); i++)
{
if (wcTailMix[i, 0] == wcFirst && wcTailMix[i, 1] == wcSeconde)
{
dIndex = i;
break;
}
}
if (dIndex == -1)
return false;
pResult = wcTailMix[dIndex, 2];
return true;
}
// C++ -> C#
private static int Get_T_Index(char ch)
{
for (int i = 0; i < wcTail.GetLength(0); i++)
{
if (wcTail[i] == ch)
return i;
}
return -1;
}
// C++ -> C#
private static int Get_M_Index(char ch)
{
for (int i = 0; i < wcMid.GetLength(0); i++)
{
if (wcMid[i] == ch)
return i;
}
return -1;
}
// C++ -> C#
public static List<string> CharacterMakeHistory(string wstr)
{
List<string> m_buffer = new List<string>();
string strMakeString = string.Empty;
string strIngInput = string.Empty;
char wcFirst = '\0';
char wcSeconde = '\0';
int dPos = 0;
char[] str = wstr.ToCharArray();
while (dPos < str.Length)
{
// KR 조합형
if (str[dPos] >= 'ㄱ' && str[dPos] <= 'ㅣ')
{
if (IsMidMix(str[dPos], ref wcFirst, ref wcSeconde))
{
strIngInput = strMakeString;
strIngInput += String.Format("{0}", wcFirst);
m_buffer.Add(strIngInput);
}
else if (IsTailMix(str[dPos], ref wcFirst, ref wcSeconde))
{
strIngInput = strMakeString;
strIngInput += String.Format("{0}", wcFirst);
m_buffer.Add(strIngInput);
}
strIngInput = strMakeString;
strIngInput += String.Format("{0}", wcFirst);
m_buffer.Add(strIngInput);
}
// KR 완성형
else if (str[dPos] >= '가' && str[dPos] <= '힣')
{
// 초성
int dHeadPos = Math.Abs(str[dPos] - 0xAC00) / (21 * 28);
char wcTemp = '\0';
// 앞 글자에 초성 합성이 가능할 경우 체크하여 합성
if ((strIngInput.Length >= 1))
{
wcTemp = strIngInput[strIngInput.Length - 1];
// 이전 글자 종성과 현재 글자 초성으로 혼합된 종성을 얻는다.
char wcMixTail = ' ';
// 합성에 성공한 경우
if (IsFusionTailMix(wcTail[Math.Abs(wcTemp - 0xAC00) % 28], wcHead[dHeadPos], ref wcMixTail))
{
// 이전 글자 종성 제거
wcTemp = (char)(wcTemp - Get_T_Index(wcTail[(Math.Abs(wcTemp - 0xAC00)) % 28]));
// 이전 글자 새로운 종성 삽입
wcTemp = (char)(wcTemp + Get_T_Index(wcMixTail));
}
// 이전 글자에 종성이 없고 현재 글자의 초성이 정상일 경우
else if (Get_T_Index(wcTail[Math.Abs(wcTemp - 0xAC00) % 28]) == 0 && Get_T_Index(wcHead[dHeadPos]) != -1)
{
wcTemp = (char)(wcTemp + Get_T_Index(wcHead[dHeadPos]));
}
else
{
wcTemp = '\0';
}
}
strIngInput = strMakeString;
if (wcTemp != '\0')
{
strIngInput = strIngInput.Substring(0, strIngInput.Length - 1);
strIngInput += String.Format("{0}", wcTemp);
}
else
{
strIngInput += String.Format("{0}", wcHead[dHeadPos]);
}
m_buffer.Add(strIngInput);
// 중성
int dMidPos = Math.Abs(str[dPos] - 0xAC00) % (21 * 28) / 28;
if (IsMidMix(wcMid[dMidPos], ref wcFirst, ref wcSeconde))
{
int szMindex2 = Get_M_Index(wcFirst);
char TszM_0 = (char)(0xAC00 + (dHeadPos * 588) + (szMindex2 * 28));
strIngInput = strMakeString;
strIngInput += String.Format("{0}", TszM_0);
m_buffer.Add(strIngInput);
}
char TszM = (char)(0xAC00 + (dHeadPos * 588) + (dMidPos * 28));
strIngInput = strMakeString;
strIngInput += String.Format("{0}", TszM);
m_buffer.Add(strIngInput);
// 종성
int dTailPos = Math.Abs(str[dPos] - 0xAC00) % 28;
if (wcTail[dTailPos] != ' ')
{
if (IsTailMix(wcTail[dTailPos], ref wcFirst, ref wcSeconde))
{
int szTindex2 = Get_T_Index(wcFirst);
char TszT_0 = (char)(0xAC00 + (dHeadPos * 588) + (dMidPos * 28) + szTindex2);
strIngInput = strMakeString;
strIngInput += String.Format("{0}", TszT_0);
m_buffer.Add(strIngInput);
}
char TszT = (char)(0xAC00 + (dHeadPos * 588) + (dMidPos * 28) + dTailPos);
strIngInput = strMakeString;
strIngInput += String.Format("{0}", TszT);
m_buffer.Add(strIngInput);
}
}
else
{
strIngInput = strMakeString;
strIngInput += String.Format("{0}", str[dPos]);
m_buffer.Add(strIngInput);
}
strMakeString = strIngInput;
dPos++;
}
return m_buffer;
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NaverSearcher