Rewire Annotator

The RewireAnnotator is an annotator that uses the Rewire service to annotate documents.

import os
from gatenlp import Document
from gatenlp.processing.client.rewire import RewireAnnotator
from gatenlp.lib_spacy import AnnSpacy
apikey = os.environ["REWIRE_KEY"]   
docs = [
    Document("Barack Obama visited Microsoft in New York last May."),
    Document("""This is just some example text. 
      Has a sentence that talks about shit in general. 
      And another talking about 💩💩💩💩 in general. This guy is a moron."""),
    Document("What a stupid bitch she is."),
    Document("I am going to kill you, asshole!"),

# Just use the sentence annotations for annotating texts on a per-sentence level later
anntr = AnnSpacy(add_tokens=False, add_entities=False, add_sentences=True, add_nounchunks=False, add_deps=False)
for doc in docs:
    doc = anntr(doc)
# Annotator for annotating documents as a whole
rewire_doc = RewireAnnotator(auth_token=apikey)
# Annotator for annotating sentences
rewire_sent = RewireAnnotator(auth_token=apikey, ann_type="Sentence")

# run both annotators over all documents, show the document features assigned for each
for idx, doc in enumerate(docs):
    print("Document", idx, ":", doc.features)
Document 0 : Features({'abuse': 0.007695647422224283, 'hate': 0.01182339433580637, 'profanity': 0.0, 'violent': 0.00013819332525599748, 'sexually_explicit': 0.0007839425234124064, 'positive': 0.03010033629834652})
Document 1 : Features({'abuse': 0.9521309733390808, 'hate': 0.07565305382013321, 'profanity': 1.0, 'violent': 0.00013135180051904172, 'sexually_explicit': 0.0008426422718912363, 'positive': 0.03213106095790863})
Document 2 : Features({'abuse': 0.9487276077270508, 'hate': 0.07640768587589264, 'profanity': 1.0, 'violent': 0.00017197855049744248, 'sexually_explicit': 0.0007524627144448459, 'positive': 0.051224932074546814})
Document 3 : Features({'abuse': 0.9973989725112915, 'hate': 0.03146960213780403, 'profanity': 1.0, 'violent': 0.9915707111358643, 'sexually_explicit': 0.003027835162356496, 'positive': 0.05033063143491745})

Notebook last updated

import gatenlp
print("NB last updated with gatenlp version", gatenlp.__version__)
NB last updated with gatenlp version 1.0.8a1