hhsecond / corenlp_pywrap

Powerfull python wrapper for Stanford CoreNLP project
MIT License
31 stars 4 forks source link

corenlp_pywrap 1.0.5

Powerfull python wrapper for Stanford CoreNLP project

GitHub release license PyPI

CoreNLP v3.6.0

Pywrap Doc

Install

pip install corenlp_pywrap

or

pip3 install corenlp_pywrap

Usage

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)

Custom Function

custom function

token_dict = cn.arrange(data)

example out: token_dict['index'] would give you something like this - [1,2,3,4]


#### 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

Run the server using all jars in the current directory (e.g., the CoreNLP home directory)

port and timeout are optional

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)