This question is an exact duplicate of:
(S
(PERSON Rami/NNP Eid/NNP)
is/VBZ
studying/VBG
at/IN
(ORGANIZATION Stony/NNP Brook/NNP University/NNP)
in/IN
(LOCATION NY/NNP))
This is output of NLTK code now i want to store it in json file like
import json
data = {
'Rami Eid':{'ORGANIZATION': 'Stony Brook University', 'location':'NY'},
'GuruRaj Bagali':{'job': 'professor', 'location': 'NY'}
}
I want store chunk tree into json file like above format how to do?
This should do it.
This will give you nicely formatted json file.
This will create a file
your_json_file.json
in inyour/
directory with.The indentation and sort_keys arguments are optional. Depending on how you're using it they may be nice to have.
You could also put the same data on one line and wouldn't need to import json.
Will create
{'Rami Eid': {'ORGANIZATION': 'Stony Brook University', 'location': 'NY'}, 'GuruRaj Bagali': {'job': 'professor', 'location': 'NY'}}
prints