Skip to content

Export number and date attributes with valid XSD lexical forms - #1086

Open
Floating-Y wants to merge 1 commit into
deeplethe:devfrom
Floating-Y:fix/rdf-attribute-literals
Open

Floating-Y wants to merge 1 commit into
deeplethe:devfrom
Floating-Y:fix/rdf-attribute-literals

Conversation

@Floating-Y

Copy link
Copy Markdown
Contributor

Why

Valid normalized attributes can produce ill-typed RDF literals: JSON numbers may use exponent notation that xsd:decimal does not accept, while year, month and timestamp values are all labeled xsd:date.

This is a follow-up to #865 and the export audit discussed in #831. It preserves the summary/class and missing-object behavior already fixed by #865.

What changes

  • Expand exponent notation exactly through the existing BigDecimal type, retaining xsd:decimal without another floating-point conversion or fixed-scale rounding. Bound expansion to the exponent range produced by normalized finite numbers.
  • Select gYear, gYearMonth, date or dateTime from the date value. Format calendar fields without truncating negative or extended years.
  • Preserve offsets and all fractional-second digits. Complete reduced hour/minute clocks with the zero fields required by XSD, normalize supported timezone spellings, and leave timezone-free clocks timezone-free.
  • Preserve value precedence, string-valued summary/class and relative values, and omission of unresolved objects.
  • Replace three invalid numeric fixtures with valid numeric examples while retaining their original precedence and resolution assertions.

Examples:

Before After
"1e-7"^^xsd:decimal "0.0000001"^^xsd:decimal
"1e+20"^^xsd:decimal "100000000000000000000"^^xsd:decimal
"2024"^^xsd:date "2024"^^xsd:gYear
"2024-07"^^xsd:date "2024-07"^^xsd:gYearMonth
"2024-07-15T14Z"^^xsd:date "2024-07-15T14:00:00Z"^^xsd:dateTime

Changes are confined to rdf.rs and its tests. There are no dependency, storage, input-validation, ontology-datatype or unrelated export-structure changes. parse_time is used only for calendar-only values, so its timestamp truncation cannot discard an attribute's clock or fractional seconds.

XSD dateTime alone cannot encode source hour/minute precision; this patch adds no precision predicates. Unrecognized text continues through the existing fallback, including malformed clock text that today's permissive input validation may accept.

How it was checked

  • Added regressions before implementation: the original implementation passed 25 RDF tests and failed the three new regression tests.
  • Added a failing calendar-boundary regression during review, then corrected negative/extended-year formatting.
  • All 30 final RDF tests pass. They independently assert lexical values and datatypes across Turtle and JSON-LD, ordinary fact objects, current triples, qualifiers and derived facts. Coverage includes negative numbers, zero, ordinary decimals, the smallest/largest finite f64 values, a stored integer beyond exact f64 precision, reduced clocks, timezone variants and fractional seconds beyond nanosecond precision.
  • cargo fmt --all --check
  • cargo clippy --locked --offline --workspace --all-targets -- -D warnings
  • cargo test --locked --offline --workspace --no-fail-fast
  • git diff --check

The final Windows workspace run passed with CLI temporary-directory writes permitted and NO_PROXY=localhost,127.0.0.1,::1 for the test process. Database-backed tests skipped because UTOPIA_DATABASE_URL was unset; six existing ignored tests were not run. Frontend checks were not run because no frontend files changed.

Before review

  • Every commit is signed off (git commit -s).
  • Format, workspace Clippy and workspace tests pass, with the environment and skipped-test limitations above.

Signed-off-by: Floating-Y <118035379+Floating-Y@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant