extract-sentence-parse-scores.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/python
  2. ## This script extracts requested scores from evalb file for every sentence.
  3. ##
  4. ## Current version: 1.1
  5. ##
  6. ## Changes:
  7. ## version 1.1:
  8. ## - The main part of the code was separated out into evalproc.py module
  9. ## to be reused elsewhere.
  10. ##
  11. import evalbproc
  12. import sys, optparse
  13. ##======================================================================
  14. ## main
  15. def main(argv=None):
  16. if argv is None:
  17. argv = sys.argv
  18. parser = optparse.OptionParser(usage="%prog <EVALB FILE> [options]" +
  19. "\nExtracts requested scores from evalb file for every sentence.", version="%prog 1.0")
  20. parser.add_option("-a", "--all", help="extract all columns", dest="extAll", action="store_true")
  21. parser.add_option("-n", help="include sentence number in the output", dest="extSentenceNo", action="store_true")
  22. parser.add_option("-p", "--precision", help="extract precision", dest="extPrecision", action="store_true")
  23. parser.add_option("-r", "--recall", help="extract recall", dest="extRecall", action="store_true")
  24. parser.add_option("-f", "--fscore", help="extract (colculate) f-score", dest="extFScore", action="store_true")
  25. (opts, posArgs) = parser.parse_args()
  26. if len(posArgs) < 1:
  27. parser.error("At least 1 argument is required")
  28. # processing options
  29. if opts.extAll:
  30. opts.extSentenceNo = True
  31. opts.extPrecision = True
  32. opts.extRecall = True
  33. opts.extFScore = True
  34. ## calling the extractor
  35. ## The last parameter makes the function to print the output into
  36. ## stdout. So, the return value of the function is not needed here.
  37. evalbproc.extractSentenceScores(posArgs[0], opts.extSentenceNo, opts.extPrecision, opts.extRecall, opts.extFScore)
  38. ##======================================================================
  39. ## calling main
  40. if __name__ == "__main__":
  41. sys.exit(main())