Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
Farse news IR project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9831029
Farse news IR project
Commits
51d4a6fd
Commit
51d4a6fd
authored
May 23, 2022
by
Haj Rezvan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized the functions.
parent
88bb2e3d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
33 deletions
+40
-33
index_maker.py
index_maker.py
+27
-23
split_document.py
split_document.py
+13
-10
No files found.
index_maker.py
View file @
51d4a6fd
import
json
import
os
import
threading
def
logs
(
cnt
,
i
):
...
...
@@ -14,15 +13,15 @@ def index():
index_file
=
open
(
f
"./index/ii.json"
,
"w"
,
encoding
=
"utf-8"
)
invert_index
=
dict
()
os
.
chdir
(
"./document tokens"
)
for
tk
in
os
.
listdir
():
print
(
tk
)
files
=
os
.
listdir
()
counter
=
0
pre_percent
=
0
print
(
"0
%
is Index made!"
)
for
tk
in
files
:
token_file
=
open
(
f
"./{tk}"
,
"r"
,
encoding
=
"utf-8"
)
backup
=
token_file
.
readline
()
try
:
tkn
=
json
.
load
(
token_file
)
except
(
json
.
decoder
.
JSONDecodeError
,
Exception
)
as
e
:
thread
=
threading
.
Thread
(
target
=
logs
,
args
=
(
backup
,
tk
,))
thread
.
start
()
# backup = token_file.readline()
tkn
=
dict
(
tkn
)
tk
=
tk
.
replace
(
".json"
,
""
)
tk
=
int
(
tk
)
...
...
@@ -36,8 +35,13 @@ def index():
indexes
.
sort
()
token_file
.
close
()
# str_out = str(invert_index)
# str_out = str_out.replace("\'", "\"")
# str_out = dict(str_out)
new_percent
=
int
((
counter
/
len
(
files
))
*
100
)
if
new_percent
!=
pre_percent
:
print
(
f
"{new_percent}
%
is Index made!"
)
pre_percent
=
new_percent
counter
=
counter
+
1
except
Exception
as
e
:
print
(
f
"Exception in file {tk}
\n
{e.args}
\n
"
)
json
.
dump
(
invert_index
,
index_file
)
print
(
"Invert index made!"
)
split_document.py
View file @
51d4a6fd
...
...
@@ -38,17 +38,20 @@ def __retrieval(data, i, tag):
return
obj_cnt
except
Exception
as
ignore
:
print
(
f
"We have a Exception!! {ignore.with_traceback}"
)
pass
def
__processor
(
file
):
data
=
json
.
load
(
file
)
for
i
in
tqdm
(
range
(
14000
),
desc
=
"Splatted: "
):
title
=
__retrieval
(
data
,
i
,
"title"
)
content
=
__retrieval
(
data
,
i
,
"content"
)
url
=
__retrieval
(
data
,
i
,
"url"
)
tags
=
__retrieval
(
data
,
i
,
"tags"
)
date
=
__retrieval
(
data
,
i
,
"date"
)
category
=
__retrieval
(
data
,
i
,
"category"
)
__writer
(
i
,
title
,
content
,
url
,
tags
,
date
,
category
)
length
=
len
(
data
)
doc_ids
=
list
(
data
.
keys
())
for
i
in
tqdm
(
range
(
length
),
desc
=
"Splatted: "
):
doc_id
=
doc_ids
[
i
]
title
=
__retrieval
(
data
,
doc_id
,
"title"
)
content
=
__retrieval
(
data
,
doc_id
,
"content"
)
url
=
__retrieval
(
data
,
doc_id
,
"url"
)
tags
=
__retrieval
(
data
,
doc_id
,
"tags"
)
date
=
__retrieval
(
data
,
doc_id
,
"date"
)
category
=
__retrieval
(
data
,
doc_id
,
"category"
)
__writer
(
doc_id
,
title
,
content
,
url
,
tags
,
date
,
category
)
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