/ipymarkup

NER markup for Jupyter Notebook

Primary LanguageJupyter Notebook

ipymarkup Build Status Coverage Status

NER markup visualization for Jupyter Notebook.

Install

ipymarkup supports both Python 2.7+ / 3.4+, non Jupyter functionality should work on 2.7+ / 3.3+, PyPy.

$ pip install ipymarkup

Usage

Display simple nonoverlapping spans in Jupyter:

from ipymarkup import show_markup

text = 'South Korean President Moon Jae-in announced in a joint press conference on 23 July ...'
spans = [
    (0, 12),
    (13, 22),
    (23, 34),
    (76, 83)
]

show_markup(text, spans)

Add labels:

spans = [
    (0, 12, 'GEO'),
    (13, 22, 'POSITION'),
    (23, 34, 'NAME'),
    (76, 83, 'DATE')
]

show_markup(text, spans)

There is a number of visualizations (see docs for full list). By default, BoxLabelMarkup is used. In case spans overlap (PERSON overlaps NAME), switch to LineMarkup:

from ipymarkup import LineMarkup

spans = [
    (0, 12, 'GEO'),
    (13, 22, 'POSITION'),
    (23, 34, 'NAME'),
    (0, 34, 'PERSON'),
    (76, 83, 'DATE')
]

show_markup(text, spans, LineMarkup)

Finally to use ipymarkup outside of Jupyter, use AsciiMarkup:

from ipymarkup import markup, AsciiMarkup

for line in markup(text, spans, AsciiMarkup).as_ascii:
    print(line)
South Korean President Moon Jae-in announced in a joint press 
GEO--------- POSITION- NAME-------                            
PERSON----------------------------                            
conference on 23 July ...
              DATE---    

For more examples and explanation see ipymarkup documentation.

License

The source code of ipymarkup is distributed under MIT license (allows modification and commercial usage)

Support