In [1]:
from IPython.display import HTML
HTML("""<style>{}</style>""".format(open("assets/css/custom.css").read()))


Out[1]:

Introduction

This notebook assumes you installed py-processors with jupyter extras:

pip install py-processors[jupyter]==3.2.1

In [2]:
import processors
print("py-processors version:\t{}".format(processors.__version__))
print("processors-sever recommended version:\t{}".format(processors.__ps_rec__))


py-processors version:	3.2.1
processors-sever recommended version:	3.1.0

Documentation

You can find the documentation here, including a detailed walkthrough example.

Using the docker-based backend

# pull the official image
docker pull myedibleenso/processors-server:3.2.1
# run the container in the background and expose the service on port 8886
docker run -d -e _JAVA_OPTIONS="-Xmx3G" -p 127.0.0.1:8886:8888 --name procserv myedibleenso/processors-server:3.1.0

Uncomment and run the next block to establish the client connection with the docker container-based backend.


In [3]:
# from processors import *
# API = ProcessorsBaseAPI(port=8886)

Using the java-based backend


In [4]:
from processors import *
# using the jar-based backend
API = ProcessorsAPI(port=8881, keep_alive=False)


INFO - Starting processors-server (java -Xmx3G -cp /Users/gus/anaconda3/lib/python3.5/site-packages/processors/processors-server.jar NLPServer --port 8881 --host localhost) ...
Waiting for server...
[============                                                ]

Connection with processors-server established (http://localhost:8881)

In [5]:
doc = API.annotate("To be loved by unicorns is the greatest gift of all.")

s = doc.sentences[0]

Visualizing the parse


In [6]:
from processors.visualization import JupyterVisualizer as viz

viz.display_graph(s,graph_name="stanford-collapsed")


Let's see what the parse looks like for stanford basic dependencies ("stanford-basic")...


In [7]:
viz.display_graph(s, distance=150, graph_name="stanford-basic")


Styling the graph

You can apply css to the graph via the css parameter. JupyterVisualizer.parse_css is configured to draw attention to tokens that are nouns ([tag=/^NN/]), verbs ([tag=/^VB/]), or have an entity label of some kind ([!entity=/^O/]).


In [8]:
viz.display_graph(doc.sentences[0], css=viz.parse_css)

print("Corresponding CSS:\n{}".format(viz.parse_css))


Corresponding CSS:
.displacy-tag[data-tag^="NN"]{
  color: green;
  font-weight: bold;
}

.displacy-tag[data-tag^="VB"]{
  color: blue;
  font-weight: bold;
}

.displacy-entity:not([data-tag="O"]){
  color: green;
  font-weight: bold;
}

.displacy-arrow[data-label^="nsubj"], [data-label^="dobj"], [data-label^="prep_of"], [data-label^="nn"]{
  color: green;
  font-weight: bold;
}