partially improved add()
@@ -645,15 +645,24 @@ class Literal(Identifier):
rdflib.term.Literal(u'11')
"""
- py = self.toPython()
- if not isinstance(py, Literal):
+ # convert the val to a Literal, if it isn't already one
+ if not isinstance(val, Literal):
+ val = Literal(val)
+
+ if self.datatype == val.datatype \
+ or \
+ (
+ self.datatype in _NUMERIC_LITERAL_TYPES
+ and
+ val.datatype in _NUMERIC_LITERAL_TYPES
+ ):
+ # return Literal(round(self.toPython() + val.toPython(), 10))
+ return Literal(self.toPython() + val.toPython())
+ else:
try:
- return Literal(py + val)
+ return Literal(self.value + val.value)
except TypeError:
- pass # fall-through
-
- s = text_type.__add__(self, val)
- return Literal(s, self.language, self.datatype)
+ return Literal(str(self.value) + str(val), self.language, datatype=_XSD_STRING)
def __bool__(self):
"""
