Converts to xsd:integer its derived datatypes

pull/10/head
Tpt 6 years ago
parent a15e8548f3
commit fc040a4e45
  1. 22
      lib/src/model/literal.rs
  2. 36
      lib/src/model/vocab.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 }
})

@ -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();

Loading…
Cancel
Save