4 ms·
Speaking of enums, what's a better serialization framework for C++ like Serde in Rust, and then what about Linked Data support and of course also form validatio
by westurner 2y ago
Speaking of enums, what's a better serialization framework for C++ like Serde in Rust, and then what about Linked Data support and of course also form validation.
Linked Data triples have (subject, predicate, object) and quads have (graph, subject, predicate, object).
RDF has URIs for all Subjects and Predicates.
RDF Objects may be URIs or literal values like xsd:string, xsd:float64, xsd:int (32bit signed value), xsd:integer, xsd:long, xsd:time, xsd:dateTime, xsd:duration.
RDFS then defines Classes and Properties, identified by string URIs.
How best to get from an Enum with (type,attr, {range of values}) to an rdfs:range definition in a schema with a URI prefix?
Python has dataclasses which is newer than attrs, but serde also emits Python pickles
- beached_whale 2y agore Serde: If you want JSON, https://github.com/beached/daw_json_link https://github.com/beached/daw_json_link is about as close as we can get. It interop's well with the reflection(or like) libraries such as Boost Describe or Boost PFR and will work well with std reflection when it is available.
- westurner 2y agoProbably not too much work to add and then also build a JSONLD @context from all of the ~ message structs. :Thing > https://schema.org/name https://schema.org/name , :URL , :identifier and subclasses Thing > Intangible > Enumeration: https://schema.org/Enumeration https://schema.org/Enumeration
- beached_whale 2y agoAdding reflection will be simple and backwards compatible with existing code as it would only come into play when someone hasn't manually mapped a type. This leaves the cases where reflection doesn't work(private member variables) still workable too. Haven't looked at JSONLD much, but it seems like it could be added but would be a library above I think. Extracting the mappings is already doable and is done in the JSON Schema export.
- westurner 2y ago"Exporting JSON Schema" https://github.com/beached/daw_json_link/blob/release/docs/cookbook/json_schema.md https://github.com/beached/daw_json_link/blob/release/docs/c... : include <daw/json/daw_json_schema.h> std::string daw::json::to_json_schema<MyType>( "identifier", "title" ); From https://westurner.github.io/hnlog/#comment-38526588 https://westurner.github.io/hnlog/#comment-38526588 : > SHACL is used for expressing integrity constraints on complete data, while OWL allows inferring implicit facts from incomplete data; SHACL reasoners perform validation, while OWL reasoners do logical inference. - "Show HN: Pg_jsonschema – A Postgres extension for JSON validation" https://news.ycombinator.com/item?id=32186878 https://news.ycombinator.com/item?id=32186878 re: json-ld-schema, which bridges JSONschema and SHACL for JSONLD
- pjmlp 2y agoSo far, most people would use whatever is provided alongside the frameworks they are already using for their application. Since the 90's, Turbo Vision, OWL, MFC, CSet++, Tools.h++, VCL, ATL, PowerPlant, Qt, Boost, JUCE, Unreal, CryEngine,.... Maybe if reflection does indeed land into C++26, something might be more universally adopted.
- westurner 2y ago"Reflection for C++26" (2024) https://news.ycombinator.com/item?id=40836594 https://news.ycombinator.com/item?id=40836594 Wt:Dbo years ago but that's just objects to and from SQL, it's not linked data schema or fast serialization with e.g. Arrow. There should be easy URIs for Enums, which I guess map most closely to the rdfs:range of an rdfs:Property. Something declarative and/or extracted by another source parser would work. To keep scheme definitions DRY
- nly 2y agoBoost Fusion or Boost Hana + whatever serialization library you want to use is probably best imho.
- morni 2y agoGlaze (https://github.com/stephenberry/glaze https://github.com/stephenberry/glaze) is great if you have C++20 and want JSON or CSV. Compile time reflection is built in.