[Solved] python-sutime Error: the JSON object must be str, bytes or bytearray, not ‘java.lang.String‘

Problems arising

The JSON object must be STR, bytes or byte array, not ‘Java.lang.String’

Solution:

The last in sutime.py is this:

	return json.loads(self._sutime.annotate(input_str, reference_date))
return json.loads(self._sutime.annotate(input_str))

Replace it with:

	return json.loads(str(self._sutime.annotate(input_str, reference_date)))
return json.loads(str(self._sutime.annotate(input_str)))

 

Test sutime package (this part is also referred to the above website)

import json
import os
from sutime import SUTime

if __name__ == '__main__':
    test_case = "I need a desk for tomorrow from 2pm to 3pm"
    # D:/python_projects/SPARQA/common_resources/resources_sutime/python-sutime-master/jars
    jar_files = os.path.join(os.path.dirname('D:/python_projects/SPARQA/common_resources/resources_sutime/python-sutime-master/jars'),'jars')
    sutime = SUTime(jars=jar_files, include_range=True)
    print(json.dumps(sutime.parse(test_case), sort_keys=True, indent=4))

The operation result is:

[
    {
        "end": 26,
        "start": 18,
        "text": "tomorrow",
        "type": "DATE",
        "value": "2021-12-31"
    },
    {
        "end": 35,
        "start": 32,
        "text": "2pm",
        "type": "TIME",
        "value": "2021-12-30T14:00"
    },
    {
        "end": 42,
        "start": 39,
        "text": "3pm",
        "type": "TIME",
        "value": "2021-12-30T15:00"
    }
]

Read More: