-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbooknlp.py
52 lines (37 loc) · 1.41 KB
/
booknlp.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
import sys
import argparse
from transformers import logging
#logging.set_verbosity_error()
from pathlib import Path
import os
from booknlp.english.english_booknlp import EnglishBookNLP
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
class BookNLP():
def __init__(self, language, model_params):
if language == "en":
self.booknlp=EnglishBookNLP(model_params)
def process(self, inputFile, outputFolder, idd):
self.booknlp.process(inputFile, outputFolder, idd)
def proc():
parser = argparse.ArgumentParser()
parser.add_argument('-l','--language', help='Currently on {en}', required=True)
parser.add_argument('-i','--inputFile', help='Filename to run BookNLP on', required=True)
parser.add_argument('-o','--outputFolder', help='Folder to write results to', required=True)
parser.add_argument('--id', help='ID of text (for creating filenames within output folder)', required=True)
args = vars(parser.parse_args())
language=args["language"]
inputFile=args["inputFile"]
outputFolder=args["outputFolder"]
idd=args["id"]
print("tagging %s" % inputFile)
valid_languages=set(["en"])
if language not in valid_languages:
print("%s not recognized; supported languages: %s" % (language, valid_languages))
sys.exit(1)
model_params={
"pipeline":"entity,quote,supersense,event,coref", "model":"big",
}
booknlp=BookNLP(language, model_params)
booknlp.process(inputFile, outputFolder, idd)
if __name__ == "__main__":
proc()