Ejemplo n.º 1
0
 def _is_valid(cls: Union[type, Tuple[type, ...]], instance) -> bool:
     if issubclass(type(instance), cls) or isinstance(instance, (int, float, bool, date, time, datetime)):
         return True
     elif isinstance(instance, rdflib.Literal):
         return instance.datatype and instance.datatype != XSD.string
     elif isinstance(instance, str):
         l = Literal._to_n3(instance)
         return l.datatype and l.datatype != XSD.string
     return False
Ejemplo n.º 2
0
 def __setattr__(self, key, value):
     if key != 'v':
         super().__setattr__(key, value)
     elif isinstance(value, (int, float, bool, date, datetime, time)):
         cl = rdflib.Literal(value)
         super().__setattr__('v', TypedLiteral(cl.value, cl.datatype))
     elif isinstance(value, str) or not self.set_v(value):
         l = Literal._to_n3(value)
         if l is None:
             raise ValueError(f"Literal: {value} is not a valid literal")
         if l.language:
             vv = StringLiteralWithLanguage(l.value, l.language)
         elif l.datatype and l.datatype != XSD.string:
             vv = TypedLiteral(l.value, l.datatype)
         else:
             vv = StringLiteralNoLanguage(l.value)
         super().__setattr__('v', vv)
Ejemplo n.º 3
0
 def _parse_input(cls, v: Any) -> Tuple[Any]:
     if issubclass(type(v), cls):
         return (v.literal, v.datatype)
     l = Literal._to_n3(v)
     return (l.value, l.datatype)
Ejemplo n.º 4
0
 def _is_valid(cls, instance) -> bool:
     return Literal._to_n3(instance) is not None
Ejemplo n.º 5
0
 def _is_valid(cls, instance) -> bool:
     return bool(Literal._to_n3(instance))