def _handle_object(self, object_input):
'''
Method to handle possible values passed for adding, removing, modifying triples.
Detects type of input and sets appropriate http://www.w3.org/2001/XMLSchema# datatype
Args:
object_input (str,int,datetime,): many possible inputs
Returns:
(rdflib.term.Literal): with appropriate datatype attribute
'''
# if object is string, convert to rdflib.term.Literal with appropriate datatype
if type(object_input) == str:
return rdflib.term.Literal(object_input, datatype=rdflib.XSD.string)
# integer
elif type(object_input) == int:
return rdflib.term.Literal(object_input, datatype=rdflib.XSD.int)
# float
elif type(object_input) == float:
return rdflib.term.Literal(object_input, datatype=rdflib.XSD.float)
# date
elif type(object_input) == datetime.datetime:
return rdflib.term.Literal(object_input, datatype=rdflib.XSD.date)
else:
return object_input
评论列表
文章目录