-
-
Save funktor/e5a6e431672e503b9e3ae72c6cca7232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_phrase(test_sentence, tagger): | |
test_features = sent2features(test_sentence) | |
pred_labels, phrase_chunks = tagger.tag(test_features), [] | |
start, end = 0, 0 | |
for idx in range(len(pred_labels)): | |
if pred_labels[idx] == 'B': | |
start = idx | |
elif pred_labels[idx] == 'E': | |
end = idx | |
phrase_chunks.append((start, end)) | |
if end < start: | |
phrase_chunks.append((start, len(pred_labels)-1)) | |
return [test_sentence[start:end+1] for start, end in phrase_chunks] | |
def extract_phrase_chunks(test_sentences, tagger): | |
output = [extract_phrase(sent, tagger) for sent in test_sentences] | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment