Advertisement
joxeankoret

Python summarizer

May 24th, 2024 (edited)
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import sys
  4. import nltk
  5.  
  6. #-------------------------------------------------------------------------------
  7. stmts = [
  8.   "disassemble 10 first instructions at main",
  9.   "pet 10 cats and 2 rabbits",
  10.   "what's the weather like in california",
  11.   "Diaphora 3.0 checkpoint at end of March 2023"
  12. ]
  13.  
  14. INTERESTING = [
  15.   "JJ", "CD", "NN"
  16. ]
  17.  
  18. #-------------------------------------------------------------------------------
  19. def summarize(sentence):
  20.   tokens = nltk.word_tokenize(sentence)
  21.   tagged = nltk.pos_tag(tokens)
  22.   entities = nltk.chunk.ne_chunk(tagged)
  23.  
  24.   summary = []
  25.   for ent in entities:
  26.     for inte in INTERESTING:
  27.       if ent[1].startswith(inte):
  28.         summary.append(ent)
  29.  
  30.   print(">Sentence:", repr(sentence))
  31.   print(">Summary :", list(summary))
  32.   print(">Entities:", list(entities))
  33.   print()
  34.  
  35. #-------------------------------------------------------------------------------
  36. def main():
  37.   for stmt in stmts:
  38.     summarize(stmt)
  39.  
  40. if __name__ == "__main__":
  41.   main()
  42.  
  43.  
Tags: summarize
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement