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:
- Python PIP TypeError: expected str, bytes or os.PathLike object, not int
- Typeerror in Python regular expression: expected string or bytes like object
- [Solved] Python Error: TypeError: write() argument must be str, not bytes
- [Solved] pycocotools Install Error: ERROR: Error expected str, bytes or os.PathLike object, not NoneType while executing
- [Solved] TypeError: Object of type ‘bytes’ is not JSON serializable
- [Solved] Python3.9 Pycropto RSA Error: TypeError: can’t concat str to bytes
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- Djangorestframework-simplejwt: ‘str‘ object has no attribute ‘decode‘ [Solved]
- TypeError: Decimal type object is not a JSON serialization solution
- Python parsing JSON Error: NameError: name ‘false’ is not defined
- AttributeError str object has no attribut [How to Solve]
- [Solved] Python serializate error: NameError: name ‘JSON’ is not defined
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- Python: ___ () vs ___ str__()
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- Python error: ‘int’ object is not callable
- Python TypeError: coercing to Unicode: need string or buffer, NoneType found
- Python TypeError: Unrecognized value type: <class ‘str‘>dateutil.parser._parser.ParserError: Unknow