pip install corenlp_pywrap
or
pip3 install corenlp_pywrap
from corenlp_pywrap import pywrap
cn = pywrap.CoreNLP(url='http://localhost:9000', annotator_list=full_annotator_list)
#full_annotator_list = ["tokenize", "cleanxml", "ssplit", "pos", "lemma", "ner", "regexner", "truecase", "parse", "depparse", "dcoref", "relation", "natlog", "quote"]
#Calling basic function which would return a 'requests' object
out = cn.basic(data, out_format='json')
Remember 'out' would be 'requests' object, you can get information by using out.text or out.json()
Pywrap does not inherently support 'Sentiment' now as the downloadable server version of CoreNLP doesn't have 'Sentiment' support. But there is a hack for you to use (if you are sure that your server version is the newest one and has the support)
annotator_list = CoreNLP.full_annotator_list + ['sentiment']
token_dict = {
'index':[],
'truecaseText':[],
'ner':[],
'before':[],
'originalText':[],
'characterOffsetBegin':[],
'lemma':[],
'truecase':[],
'pos':[],
'characterOffsetEnd':[],
'speaker':[],
'word':[],
'after':[]
}
from corenlp_pywrap import pywrap
cn = pywrap.CoreNLP(url='http://localhost:9000', annotator_list=full_annotator_list)
#full_annotator_list = ["tokenize", "cleanxml", "ssplit", "pos", "lemma", "ner", "regexner", "truecase", "parse", "depparse", "dcoref", "relation", "natlog", "quote"]
token_dict = cn.arrange(data)
#### Server Instantiation Error
- If you don't have the CoreNLP server downloaded, please download the server [here](http://stanfordnlp.github.io/CoreNLP/download.html)
- Make sure you have Jave 8+ version installed
- CD to the downloaded folder
- Follow below commands
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer [port] [timeout]
- Verify the server instance in the browser
> http://localhost:port/
replace 'port' with the port number you have given. if you didn't give any port number, port would be 9000
> http://localhost:9000/
#### Debugging & Logging
- Pywrap using logging module for logging and debugging.
- Default logging level is set to 'warning'
- If you need more verbose logs for debugging or logging purpose make changes to the logging values
- Default log facilities
```python
root = logging.getLogger('Root')
root.setLevel(logging.WARNING)
lhandler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'%(asctime)s [%(name)s]:%(levelname)s - %(message)s',
'%Y-%m-%d %H:%M:%S')
lhandler.setFormatter(formatter)
root.addHandler(lhandler)
import corenlp_pywrap as cp
import logging
cp.pywrap.root.setLevel(logging.DEBUG)