-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
executable file
·78 lines (71 loc) · 1.67 KB
/
web.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
""" Service to extract text from a file using Tika
` Author: Bontenakel Lenny - [email protected]
Created: 23 September 2022
"""
import os
from flask import request
import service
import logging
logging.basicConfig(level = os.environ.get("LOGLEVEL", "INFO"))
""" Extract text and save it in the triplestore
@filepath: path to the file relative from FILE_DIR
"""
@app.route("/index", methods=['POST'])
def indexFile():
body = request.get_json()
uri = body.get('uri')
try:
result = service.indexFile(uri)
return {
"result": result
}
except RuntimeError:
logging.exception(e)
return {
"message": "Unable to start tika server. Please retry"
}
except Exception as e:
return {
"message": e.message
}
""" Extract content and save it for all files
"""
@app.route("/index-all", methods=['POST'])
def indexAll():
try:
result = service.indexAll()
except RuntimeError:
return {
"message": e.message
}
except Exception as e:
return {
"message": e.message
}
return {
"result": result
}
""" receive a delta signal from the delta notifier service and save the extracted text into the triplestore
The extracted text will be saved as a predicate of the uploaded file.
"""
@app.route("/delta", methods=['POST'])
def delta():
try:
body = request.get_json()
target_uri = 'share://'
uri = ''
for i in body[0]['inserts']:
if target_uri in i['subject']['value']:
uri = i['subject']['value']
if uri == '':
return {
"result": "No uri for physical files found. Can not extract content without physical file."
}
result = service.indexFile(uri)
return {
"result": result
}
except Exception as e:
return {
"message": e.message
}