[그림 1. TF-IDF 가중치 행렬 공식]


추석 연휴가 시작하고, 재미삼아 제 블로그 글의 유사도를 분석해보았습니다.


(더 개선된 결과는 이 글의 2탄인 2017/10/03 - [노트정리/정보검색론 Information Retrieval] - 블로그 제목, 포스트의 TF-IDF 변환으로 유사한 글 검색한 결과2 참고 바랍니다)



이전 글에서 올린 HtmlUnit을 사용해서 블로그의 글을 크롤링했고, 이를 mysql 데이터베이스에 저장했습니다.


구현상 문제로 heap이 자꾸 터져서 애를 먹었습니다(추후 수정 해야 함).



데이터베이스에는 글의 아이디(ID), 제목, 글 내용 속성을 지정하여 저장했습니다.


이를 제목, 글 각각에 관해 TF-IDF로 벡터화 하였습니다.


제 블로그 글에는 소스 코드도 많이 올라와 있어서 특수 문자를 따로 처리하지 않고 오로지 띄어쓰기만을 구분자로 처리했습니다.


이 때, 구분자로 얻은 문자열의 길이가 3을 초과할 때, 3-gram으로 다시 쪼갰습니다.



데이버베이스에 제목, 글 각각의 테이블을 만들고, 여기에 앞서 구한 TF-IDF를 저장했습니다.



프로그램에는 어떤 글이 쿼리로 입력되고, 제목과 글에 각각 알파(<1), (1-알파) 만큼의 가중치로 쿼리를 제외한 모든 글에 대해 코사인 유사도 구합니다.


그리고 가장 높은 유사도 순으로 K개의 글을 나타냅니다.


아래는 이 프로그램으로 얻은 결과 예시입니다.



어떤 글에 대해서는 나름 비슷한 글을 관련 글이라고 반환하는데요.


어떤 것은 별로 그렇지 않아보이는 글도 결과로 나타냅니다.


제 블로그에 짧은 글이 워낙 많아서 그런게 아닌가 싶습니다.


매번 유사한 글을 계산해야 하기 때문에 유사도를 저장할 수 있는 테이블을 앞으로 추가하고자 합니다.


구현 소스 코드는 깃헙 참고 [링크]


구현 과정은 추후 강좌 형식으로 올리겠습니다.

===============================


[Your Query] 89

티스토리 초대장 배포합니다. http://woongheelee.com/entry/티스토리-초대장-배포합니다


[Related Articles]

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한

습관이란게 좋은거 같다. http://woongheelee.com/entry/습관이란게-좋은거-같다

매크로 조이스틱 만드는 간단한 아이디어 http://woongheelee.com/entry/매크로-조이스틱-만드는-간단한-아이디어


[Your Query] 25

특이값 분해 튜토리얼 Singular Value Decomposition Tutorial http://woongheelee.com/entry/특이값-분해-튜토리얼-Singular-Value-Decomposition-Tutorial


[Related Articles]

특이값 분해 따라하기. Singular value decomposition tutorial. http://woongheelee.com/entry/특이값-분해-따라하기-Singular-value-decomposition-tutorial

40+법칙. 일중독. http://woongheelee.com/entry/40-법칙-일중독

재무함수PMT() http://woongheelee.com/entry/재무함수PMT

스카이라인 오퍼레이터 의사코드 Skyline Operator Pseudo code http://woongheelee.com/entry/스카이라인-오퍼레이터-의사코드-Skyline-Operator-Pseudo-code

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지


[Your Query] 226

뉴욕취업(스무 살의 동경을 현실로 만드는 HOT 취업가이드) http://woongheelee.com/entry/뉴욕취업-스무-살의-동경을-현실로-만드는-HOT-취업가이드


[Related Articles]

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한

경리비법노트(개인사업자로 창업해서 기장 안맡기고 혼자하는) http://woongheelee.com/entry/경리비법노트-개인사업자로-창업해서-기장-안맡기고-혼자하는

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

기초중심의 어셈블리 언어/동일출판사 http://woongheelee.com/entry/기초중심의-어셈블리-언어-동일출판사

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지


[Your Query] 458

이웃집 백만장자 / 토마스 J. 스탠리, 윌리엄 D. 덴코 http://woongheelee.com/entry/이웃집-백만장자-토마스-J-스탠리-윌리엄-D-덴코


[Related Articles]

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한

경리비법노트(개인사업자로 창업해서 기장 안맡기고 혼자하는) http://woongheelee.com/entry/경리비법노트-개인사업자로-창업해서-기장-안맡기고-혼자하는

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

뉴욕취업(스무 살의 동경을 현실로 만드는 HOT 취업가이드) http://woongheelee.com/entry/뉴욕취업-스무-살의-동경을-현실로-만드는-HOT-취업가이드

기초중심의 어셈블리 언어/동일출판사 http://woongheelee.com/entry/기초중심의-어셈블리-언어-동일출판사


[Your Query] 473

TODAY(), NOW(), 값만 붙여넣기 예시 http://woongheelee.com/entry/TODAY-NOW-값만-붙여넣기-예시


[Related Articles]

매크로 조이스틱 관련하여 작업 중지 중 입니다. http://woongheelee.com/entry/매크로-조이스틱-관련하여-작업-중지-중-입니다

74HC595로 컨트롤러 모듈 http://woongheelee.com/entry/74HC595로-컨트롤러-모듈

Reversible 풀이중 http://woongheelee.com/entry/Reversible-풀이중

6.9.9가중확률 http://woongheelee.com/entry/6-9-9가중확률

전자 부품의 기초 강좌 http://woongheelee.com/entry/전자-부품의-기초-강좌


[Your Query] 261

Frame Components and Materials http://woongheelee.com/entry/Frame-Components-and-Materials


[Related Articles]

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한

습관이란게 좋은거 같다. http://woongheelee.com/entry/습관이란게-좋은거-같다

매크로 조이스틱 만드는 간단한 아이디어 http://woongheelee.com/entry/매크로-조이스틱-만드는-간단한-아이디어


[Your Query] 301

추가 재료 - 열수축 튜브 http://woongheelee.com/entry/추가-재료-열수축-튜브


[Related Articles]

Figure ; 44-Pin Demo Board http://woongheelee.com/entry/Figure-44-Pin-Demo-Board

PICKIT2 ICSP회로연결 http://woongheelee.com/entry/PICKIT2-ICSP회로연결

네모로직 알고리즘 - 중단점으로 박스 구분하기, punctuating http://woongheelee.com/entry/네모로직-알고리즘-중단점으로-박스-구분하기-punctuating

스카이라인 오퍼레이터 의사코드 Skyline Operator Pseudo code http://woongheelee.com/entry/스카이라인-오퍼레이터-의사코드-Skyline-Operator-Pseudo-code

Microchip계열 쇼핑몰 - PIC칩 http://woongheelee.com/entry/Microchip계열-쇼핑몰-PIC칩


[Your Query] 22

2014년 국립 중앙 박물관에서 오르셰 미술관전을 다녀온 감상 http://woongheelee.com/entry/2014년-국립-중앙-박물관에서-오르셰-미술관전을-다녀온-감상


[Related Articles]

매크로용 보드 기판이 왔습니다. http://woongheelee.com/entry/매크로용-보드-기판이-왔습니다

6.9.9가중확률 http://woongheelee.com/entry/6-9-9가중확률

74HC595로 컨트롤러 모듈 http://woongheelee.com/entry/74HC595로-컨트롤러-모듈

VS Rotate http://woongheelee.com/entry/VS-Rotate

SETUP_ADC_PORTS() http://woongheelee.com/entry/SETUP-ADC-PORTS


[Your Query] 23

점심먹고 잠시 집에 가서 고양이 얼굴보고 오기 http://woongheelee.com/entry/점심먹고-잠시-집에-가서-고양이-얼굴보고-오기


[Related Articles]

푸른 눈빛의 발리니즈 고양이 올라프. http://woongheelee.com/entry/푸른-눈빛의-발리니즈-고양이-올라프

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

경리비법노트(개인사업자로 창업해서 기장 안맡기고 혼자하는) http://woongheelee.com/entry/경리비법노트-개인사업자로-창업해서-기장-안맡기고-혼자하는

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한


[Your Query] 56

기대값 계산으로 폰게임 앵벌이왕초(The Beggar King)의 복권 긁을지 말지. http://woongheelee.com/entry/기대값-계산으로-폰게임-앵벌이왕초-The-Beggar-King-의-복권-긁을지-말지


[Related Articles]

어셈블리 피보나치 수열 5항까지 http://woongheelee.com/entry/어셈블리-피보나치-수열-5항까지

외로움에 대한 가르침의 말씀 http://woongheelee.com/entry/외로움에-대한-가르침의-말씀

경리비법노트(개인사업자로 창업해서 기장 안맡기고 혼자하는) http://woongheelee.com/entry/경리비법노트-개인사업자로-창업해서-기장-안맡기고-혼자하는

점장 리더십 http://woongheelee.com/entry/점장-리더십

어셈블리 언어(인텔 기반 컴퓨터를 위한) http://woongheelee.com/entry/어셈블리-언어-인텔-기반-컴퓨터를-위한




Posted by 공돌이pooh
,