-
Notifications
You must be signed in to change notification settings - Fork 0
/
Corpus.py
37 lines (26 loc) · 1.05 KB
/
Corpus.py
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
'''
Corpus Index:
* contain list of file corresponds with its id and fileName
* currently supports text and JSON files
'''
import os
from Document import TextFileDocument, JsonFileDocument
class Corpus:
def __init__(self):
self.__corpus = {}
self.__counter = 1
def buildCorpus(self, directory):
for filename in os.listdir(directory):
title = filename
filePath = os.path.join(directory,filename)
if filename.endswith(".txt"):
textFile = TextFileDocument(self.__counter, filePath, filename)
self.__corpus[self.__counter] = textFile
self.__counter +=1
elif filename.endswith('.json'):
jsonFile = JsonFileDocument(self.__counter, filePath, filename)
self.__corpus[self.__counter] = jsonFile
self.__counter +=1
else:
print("the document format is not supported!")
return self.__corpus