Skip to content Skip to sidebar Skip to footer

Get Stanford Ner Result Through Nltk With Iob Format

i'm using nltk as interface for Stanford NER Tagger. I have question that are there any options to get NER result as IOB format using NLTK? I've read this question but it's for jav

Solution 1:

TL;DR

First see Stanford Parser and NLTK

Write a simple loop and iterate through the NER outputs:

def stanford_to_bio(tagged_sent):
    prev_tag = "O"
    bio_tagged_output = []
    current_ner = []
    for word, tag in tagged_sent:
        iftag== 'O':
            bio_tagged_output += current_ner
            bio_tagged_output.append((word, tag))
            current_ner = []
            prev_tag = 'O'else:
            ifprev_tag== 'O':
                current_ner.append((word, 'B-'+tag))
                prev_tag = 'B'else:
                current_ner.append((word, 'I-'+tag))
                prev_tag = 'I'if current_ner:
        bio_tagged_output += current_ner
    returnbio_tagged_outputtagged_sent= [('Rami', 'PERSON'), ('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'), ('at', 'O'), ('Stony', 'ORGANIZATION'), ('Brook', 'ORGANIZATION'), ('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'STATE_OR_PROVINCE')]
stanford_to_bio(tagged_sent)

[out]:

[('Rami', 'B-PERSON'),
 ('Eid', 'I-PERSON'),
 ('is', 'O'),
 ('studying', 'O'),
 ('at', 'O'),
 ('Stony', 'B-ORGANIZATION'),
 ('Brook', 'I-ORGANIZATION'),
 ('University', 'I-ORGANIZATION'),
 ('in', 'O'),
 ('NY', 'B-STATE_OR_PROVINCE')]

Post a Comment for "Get Stanford Ner Result Through Nltk With Iob Format"