diff --git a/src/model/data.rs b/src/model/data.rs index 8eb7434f..a3d63a8f 100644 --- a/src/model/data.rs +++ b/src/model/data.rs @@ -93,6 +93,12 @@ pub enum Literal { lazy_static! { static ref XSD_BOOLEAN: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#boolean").unwrap(); + static ref XSD_DOUBLE: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#double").unwrap(); + static ref XSD_FLOAT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#float").unwrap(); + static ref XSD_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#integer").unwrap(); static ref XSD_STRING: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#string").unwrap(); static ref RDF_LANG_STRING: NamedNode = @@ -193,6 +199,33 @@ impl From for Literal { } } +impl From for Literal { + fn from(value: usize) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_INTEGER.clone(), + } + } +} + +impl From for Literal { + fn from(value: f32) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_FLOAT.clone(), + } + } +} + +impl From for Literal { + fn from(value: f64) -> Self { + Literal::TypedLiteral { + value: value.to_string(), + datatype: XSD_DOUBLE.clone(), + } + } +} + impl FromStr for Literal { type Err = ();