Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
E
exa_news_classificator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vasyl Bodnaruk
exa_news_classificator
Commits
4b39d48e
Commit
4b39d48e
authored
Jul 28, 2017
by
Tags
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change model from 'frequency matrix model' into 'Direct model'
parent
1b3a12f2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
23 deletions
+24
-23
news_classify_tag.py
news_classify_tag.py
+24
-23
No files found.
news_classify_tag.py
View file @
4b39d48e
...
...
@@ -27,11 +27,11 @@ class Classifier:
self
.
db
=
_mysql
.
connect
(
host
=
host
,
port
=
port
,
user
=
user
,
passwd
=
password
,
db
=
db
)
# geting tags
self
.
db
.
query
(
"SELECT id, name FROM wp_esi_tag"
)
rez
=
self
.
db
.
store_result
()
self
.
db
.
query
(
"SELECT id, name FROM wp_esi_tag"
)
rez
=
self
.
db
.
store_result
()
# result =
tags
=
list
()
for
id
,
description
in
rez
.
fetch_row
(
maxrows
=
0
):
for
id
,
description
in
rez
.
fetch_row
(
maxrows
=
0
):
tags
.
append
((
id
,
description
))
self
.
tags
=
tags
# print (len(tags), tags)
...
...
@@ -43,9 +43,9 @@ class Classifier:
FROM wp_esi_news, wp_esi_tag_news WHERE wp_esi_tag_news.news_id=wp_esi_news.id
ORDER BY wp_esi_tag_news.tag_id LIMIT 1000 '''
self
.
db
.
query
(
sql1
)
result
=
self
.
db
.
store_result
()
result
=
self
.
db
.
store_result
()
data
=
list
()
for
tag_id
,
title
,
description
in
result
.
fetch_row
(
maxrows
=
0
):
for
tag_id
,
title
,
description
in
result
.
fetch_row
(
maxrows
=
0
):
data
.
append
((
tag_id
,
title
,
description
))
for
tag_id
,
_
in
self
.
tags
:
...
...
@@ -93,7 +93,7 @@ class Classifier:
for
i
in
range
(
columns
):
for
j
in
range
(
rows
):
if
trained_matrix
[
i
,
j
]
!=
0
:
frequency_matrix
[
i
,
j
]
=
1
/
trained_matrix
[
i
,
j
]
frequency_matrix
[
i
,
j
]
=
trained_matrix
[
i
,
j
]
# normalise rowsfrequency matrix
for
j
in
range
(
columns
):
...
...
@@ -128,7 +128,7 @@ class Classifier:
temp_matrix
=
self
.
tag_frequency_matrix
[
row
]
rez_summ
=
temp_matrix
[
self
.
matrix_test_data
.
toarray
()[
0
]
>
0
]
.
sum
()
if
rez_summ
>
(
persantage
/
100
):
vector_accordance
.
append
((
row
,
int
(
rez_summ
*
1000
)
/
10
,
self
.
tags
[
row
][
1
]))
vector_accordance
.
append
((
int
(
self
.
tags
[
row
][
0
])
,
int
(
rez_summ
*
1000
)
/
10
,
self
.
tags
[
row
][
1
]))
vector_accordance
.
sort
(
key
=
lambda
tup
:
tup
[
1
],
reverse
=
True
)
return
vector_accordance
...
...
@@ -223,35 +223,36 @@ if __name__ == "__main__":
FROM (
SELECT wp_esi_tag_news.news_id, wp_esi_news.title, wp_esi_news.description
FROM wp_esi_news, wp_esi_tag_news WHERE wp_esi_tag_news.news_id=wp_esi_news.id
ORDER BY wp_esi_tag_news.tag_id )
as
rez
ORDER BY wp_esi_tag_news.tag_id )
AS
rez
ORDER BY rand() LIMIT 15'''
tags_classif
.
db
.
query
(
sql1
)
news_results
=
tags_classif
.
db
.
store_result
()
news_results
=
news_results
.
fetch_row
(
maxrows
=
0
)
tags_classif
.
db
.
query
(
sql1
)
news_results
=
tags_classif
.
db
.
store_result
()
news_results
=
news_results
.
fetch_row
(
maxrows
=
0
)
data
=
list
()
for
i
,
(
id_news
,
title
,
description
)
in
enumerate
(
news_results
):
text_for_analis
=
title
.
decode
(
'ascii'
,
'ignore'
)
+
'
\n
'
+
description
.
decode
(
'ascii'
,
'ignore'
)
text_for_analis
=
title
.
decode
(
'ascii'
,
'ignore'
)
+
'
\n
'
+
description
.
decode
(
'ascii'
,
'ignore'
)
# print ("\n#", str (i))
print
(
"
\n
News title: "
+
title
.
decode
(
'ascii'
,
'ignore'
))
print
(
"
\n
News title: "
+
title
.
decode
(
'ascii'
,
'ignore'
))
tags_classif
.
classify
(
text_for_analis
)
print
(
"Model calculated Accordance (#tag,
%-
accordance, tag_description): "
,
end
=
" "
)
print
(
tags_classif
.
teg_accordance
)
sql
=
"
select tag_id from wp_esi_tag_news where news_id ="
+
str
(
id_news
)
sql
=
"
SELECT tag_id FROM wp_esi_tag_news WHERE news_id ="
+
str
(
id_news
)
# print(sql)
results
=
tags_classif
.
db
.
query
(
sql
)
tags
=
tags_classif
.
db
.
store_result
()
tags
=
tags
.
fetch_row
(
maxrows
=
0
)
results
=
tags_classif
.
db
.
query
(
sql
)
tags
=
tags_classif
.
db
.
store_result
()
tags
=
tags
.
fetch_row
(
maxrows
=
0
)
# print(tags)
# print(tags_classif.tags)
print
(
"User classified tags for present news:"
)
for
(
tag
,
)
in
tags
:
tag
=
int
(
tag
)
for
(
tag
,)
in
tags
:
tag
=
int
(
tag
)
# print(tag)
print
(
str
(
tag
-
1
)
+
" "
+
tags_classif
.
tags
[
tag
-
1
][
1
]
.
decode
(
'ascii'
,
'ignore'
))
print
(
str
(
tag
)
+
" "
+
tags_classif
.
tags
[
tag
-
1
][
1
]
.
decode
(
'ascii'
,
'ignore'
))
exit
(
0
)
tags_classif
.
db
.
query
(
"SELECT title, description FROM wp_esi_news ORDER BY RAND() LIMIT 25"
)
result
=
tags_classif
.
db
.
store_result
()
tags_classif
.
db
.
query
(
"SELECT title, description FROM wp_esi_news ORDER BY RAND() LIMIT 25"
)
result
=
tags_classif
.
db
.
store_result
()
for
i
,
(
title
,
description
)
in
enumerate
(
result
.
fetch_row
(
maxrows
=
0
)):
text_for_analis
=
title
+
'
\n
'
+
description
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment