utils.py 889 B

1234567891011121314151617181920212223242526272829
  1. import json
  2. # Check if contains num
  3. def notNumStr(instr):
  4. for item in instr:
  5. if '\u0041' <= item <= '\u005a' or ('\u0061' <= item <='\u007a') or item.isdigit():
  6. return False
  7. return True
  8. # Read Target Case if Json
  9. def readSingleTestCases(testFile):
  10. with open(testFile) as json_data:
  11. try:
  12. testData = json.load(json_data)
  13. except:
  14. # This try block deals with incorrect json format that has ' instead of "
  15. data = json_data.read().replace("'",'"')
  16. try:
  17. testData = json.loads(data)
  18. # This try block deals with empty transcript file
  19. except:
  20. return ""
  21. returnString = ""
  22. for item in testData:
  23. try:
  24. returnString += item['text']
  25. except:
  26. returnString += item['statement']
  27. return returnString