-
Notifications
You must be signed in to change notification settings - Fork 0
/
Document.py
55 lines (37 loc) · 1.43 KB
/
Document.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
class TextFileDocument:
def __init__(self, mDocumentId:int, filePath:str, fileName:str):
self.__mDocumentId = mDocumentId
self.__mFilePath = filePath
self.__mFileName = fileName
def getFilePath(self):
return self.__mFilePath
def getId(self):
return self.__mDocumentId
def getContent(self):
content = ''
# read the file content
with open(self.__mFilePath) as file:
content = file.read()
return content
def getTitle(self):
return self.__mFileName.replace('.txt','')
def loadTextFileDocument(self, filePath:str, documentId:int, fileName:str):
return TextFileDocument(documentId, filePath, fileName)
class JsonFileDocument:
def __init__(self, mDocumentId:int, filePath:str, fileName:str):
self.__mDocumentId = mDocumentId
self.__mFilePath = filePath
self.__mFileName = fileName
def getFilePath(self):
return self.__mFilePath
def getId(self):
return self.__mDocumentId
def getContent(self):
with open(self.__mFilePath) as file:
content = json.load(file)
return content['content']
def getTitle(self):
return self.__mFileName.replace('.json','')
def loadJsonFileDocument(self,filePath:str, documentId:int):
return JsonFileDocument(documentId,filePath)