I am trying to create a python script file with multiple functions and pass 3 arguments to the main functions. These parameters are also passed onto other functions with the script. My code looks somewhat like this:
import benepar
import spacy
import json
import gc
import typer
from spacy.tokens import Doc,DocBin
from typing import Tuple, List
from pathlib import Path
def main(nlp_dir: Path,inp_File:Path,out_File:Path):
try:
seg_obj=load_nlp_object(nlp_dir)
print('Loaded nlp obj')
doc_train=DocBin().from_disk(inp_File)
docs=get_list_of_docs(doc_train,nlp_dir)
data=[]
except Exception as e:
print(e)
chunk_count=0
for d in docs:
try:
temp=seg_obj(d)
chunk_count=chunk_count+1
if chunk_count%5 == 0:
seg_obj=load_nlp_object(nlp_dir)
gc.collect()
#Other code
except Exception as e:
print(e)
#Saving linker data
for val in data:
with open(out_File,'a',encoding='utf8') as f:
json.dump(val,f)
f.write(",\n")
print('Data created successfully.')
def load_nlp_object(nlp_dir):
#Code
return nlp
def get_list_of_docs(bin_obj,nl):
n=load_nlp_object(nl)
dcs=list(bin_obj.get_docs(n.vocab))
return dcs
def benepar_split(doc: Doc) -> List[Tuple]:
#Code
return split_indices
if __name__=='__main__':
typer.run(main)
While running I get the following error:
Traceback (most recent call last):
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\Project\create_linker_data.py", line 96, in <module>
typer.run(main)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\typer\main.py", line 864, in run
app()
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\typer\main.py", line 214, in __call__
return get_command(self)(*args, **kwargs)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\click\core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\click\core.py", line 1053, in main
rv = self.invoke(ctx)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\click\core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\click\core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "C:\Users\Shrinidhi\Desktop\Sentiment Analysis\sentiment\lib\site-packages\typer\main.py", line 500, in wrapper
return callback(**use_params) # type: ignore
TypeError: main() got an unexpected keyword argument 'inp_file'
I have debugged by code but I am unable to find the root cause. My command line command is python create_linker_data.py "Entity Linker\\ner_obj\\" "Named Entity Recognition\\sentiment_data\\3\\3.spacy" "Entity Linker\\data\\entity_linker_3.txt"