From fc040a4e454ef94078c8c88731fcccf72551a76e Mon Sep 17 00:00:00 2001 From: Tpt Date: Thu, 18 Oct 2018 14:20:47 +0200 Subject: [PATCH] Converts to xsd:integer its derived datatypes --- lib/src/model/literal.rs | 22 +++++++++++++++------- lib/src/model/vocab.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/lib/src/model/literal.rs b/lib/src/model/literal.rs index 9b7afee2..cb2d5541 100644 --- a/lib/src/model/literal.rs +++ b/lib/src/model/literal.rs @@ -83,7 +83,20 @@ impl Literal { Ok(value) => LiteralContent::Double(OrderedFloat(value)), Err(_) => LiteralContent::TypedLiteral { value, datatype }, } - } else if datatype == *xsd::INTEGER { + } else if datatype == *xsd::INTEGER + || datatype == *xsd::BYTE + || datatype == *xsd::SHORT + || datatype == *xsd::INT + || datatype == *xsd::LONG + || datatype == *xsd::UNSIGNED_BYTE + || datatype == *xsd::UNSIGNED_SHORT + || datatype == *xsd::UNSIGNED_INT + || datatype == *xsd::UNSIGNED_LONG + || datatype == *xsd::POSITIVE_INTEGER + || datatype == *xsd::NEGATIVE_INTEGER + || datatype == *xsd::NON_POSITIVE_INTEGER + || datatype == *xsd::NON_NEGATIVE_INTEGER + { match value.parse() { Ok(value) => LiteralContent::Integer(value), Err(_) => LiteralContent::TypedLiteral { value, datatype }, @@ -93,7 +106,7 @@ impl Literal { Ok(value) => LiteralContent::Decimal(value), Err(_) => LiteralContent::TypedLiteral { value, datatype }, } - } else if datatype == *xsd::DATE_TIME { + } else if datatype == *xsd::DATE_TIME || datatype == *xsd::DATE_TIME_STAMP { match DateTime::parse_from_rfc3339(&value) { Ok(value) => LiteralContent::DateTime(value), Err(_) => match NaiveDateTime::parse_from_str(&value, "%Y-%m-%dT%H:%M:%S") { @@ -101,11 +114,6 @@ impl Literal { Err(_) => LiteralContent::TypedLiteral { value, datatype }, }, } - } else if datatype == *xsd::DATE_TIME_STAMP { - match DateTime::parse_from_rfc3339(&value) { - Ok(value) => LiteralContent::DateTime(value), - Err(_) => LiteralContent::TypedLiteral { value, datatype }, - } } else { LiteralContent::TypedLiteral { value, datatype } }) diff --git a/lib/src/model/vocab.rs b/lib/src/model/vocab.rs index e04fd265..e7e6ceb9 100644 --- a/lib/src/model/vocab.rs +++ b/lib/src/model/vocab.rs @@ -52,6 +52,9 @@ pub mod xsd { /// true, false pub static ref BOOLEAN: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#boolean").unwrap(); + /// 128…+127 (8 bit) + pub static ref BYTE: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#byte").unwrap(); /// Dates (yyyy-mm-dd) with or without timezone pub static ref DATE: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#date").unwrap(); @@ -91,15 +94,48 @@ pub mod xsd { /// Gregorian calendar year and month pub static ref G_YEAR_MONTH: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#gYearMonth").unwrap(); + /// -2147483648…+2147483647 (32 bit) + pub static ref INT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#int").unwrap(); /// Arbitrary-size integer numbers pub static ref INTEGER: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#integer").unwrap(); + /// -9223372036854775808…+9223372036854775807 (64 bit) + pub static ref LONG: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#long").unwrap(); + /// Integer numbers <0 + pub static ref NEGATIVE_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#negativeInteger").unwrap(); + /// Integer numbers ≥0 + pub static ref NON_NEGATIVE_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#nonNegativeInteger").unwrap(); + /// Integer numbers ≤0 + pub static ref NON_POSITIVE_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#nonPositiveInteger").unwrap(); + /// Integer numbers >0 + pub static ref POSITIVE_INTEGER: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#positiveInteger").unwrap(); /// Times (hh:mm:ss.sss…) with or without timezone pub static ref TIME: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#time").unwrap(); + /// -32768…+32767 (16 bit) + pub static ref SHORT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#short").unwrap(); /// Character strings (but not all Unicode character strings) pub static ref STRING: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#string").unwrap(); + /// 0…255 (8 bit) + pub static ref UNSIGNED_BYTE: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedByte").unwrap(); + /// 0…4294967295 (32 bit) + pub static ref UNSIGNED_INT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedInt").unwrap(); + /// 0…18446744073709551615 (64 bit) + pub static ref UNSIGNED_LONG: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedLong").unwrap(); + /// 0…65535 (16 bit) + pub static ref UNSIGNED_SHORT: NamedNode = + NamedNode::from_str("http://www.w3.org/2001/XMLSchema#unsignedShort").unwrap(); /// Duration of time (months and years only) pub static ref YEAR_MONTH_DURATION: NamedNode = NamedNode::from_str("http://www.w3.org/2001/XMLSchema#yearMonthDuration").unwrap();