#!/usr/bin/python3 import sys import nltk #------------------------------------------------------------------------------- stmts = [ "disassemble 10 first instructions at main", "pet 10 cats and 2 rabbits", "what's the weather like in california", "Diaphora 3.0 checkpoint at end of March 2023" ] INTERESTING = [ "JJ", "CD", "NN" ] #------------------------------------------------------------------------------- def summarize(sentence): tokens = nltk.word_tokenize(sentence) tagged = nltk.pos_tag(tokens) entities = nltk.chunk.ne_chunk(tagged) summary = [] for ent in entities: for inte in INTERESTING: if ent[1].startswith(inte): summary.append(ent) print(">Sentence:", repr(sentence)) print(">Summary :", list(summary)) print(">Entities:", list(entities)) print() #------------------------------------------------------------------------------- def main(): for stmt in stmts: summarize(stmt) if __name__ == "__main__": main()