-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
58 lines (43 loc) · 1.44 KB
/
main.m
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
%% Setup and data
setup()
[content, cat, link] = loadData('data/data.csv',1);
%% Input
%Input do utilizador [Descrição de uma noticia]
input = inputDialog();
%% Bloom
% Carregar o bloom filter
[BF, k] = loadBloom();
% Limpar filtro
input = erasePunctuation(lower(input));
% Filtrar palavras de menos relevância
words = split(input,' ');
words_filtered = {};
for w = 1:length(words)
word = words{w};
if pertenceBloom(word,BF,k)
words_filtered = [words_filtered word];
end
end
input_filtered = join(words_filtered,' ');
%% Naive Bayes
% Usar o texto filtrado para classificar usando o naive bayes
[PWORD, relevantWords, PCAT, UNIQCAT] = loadNB();
res = classifyNB(input_filtered, PWORD, PCAT, relevantWords);
[~, argmax] = max(res);
classificationNB = UNIQCAT{argmax};
%% Minhash
% Pegando no texto não filtrado encontramos as 5 noticias com
%descrições mais semelhantes
% Tem de ser iguais aos usados para gerar a matrix de assinaturas da base
%de dados (por isso carregamo-los da memória)
%nsig - numero hc por assinatura
%k - tamanho dos shingles
[SM, nsig, R, k] = loadSignatures();
shingles = textToKShingles(input{1},k);
sig = signature(shingles, nsig, R);
similarities = jaccardSimilaritiesTo(sig,SM);
%Ordenar decrescentemente
[similarities, idx] = sort(similarities, 'descend');
%Output dos links das noticias mais relevantes e da categorização
%usando o naive bayes
outputDialog(idx(1:5), link(idx(1:5)), classificationNB)