Skip to main content

linked_data_schema/
lib.rs

1mod linked_data_schema_field_visitor;
2
3pub use linked_data_schema_derive::LinkedDataSchema;
4pub use linked_data_schema_field_visitor::LinkedDataSchemaFieldVisitor;
5use shacl::ast::{ASTComponent, ASTSchema};
6
7pub mod reexports {
8  pub use iri_s;
9  pub use prefixmap;
10  pub use rudof_rdf;
11  pub use shacl;
12  pub use uuid;
13}
14
15pub trait LinkedDataSchema {
16  fn shacl() -> ASTSchema;
17
18  fn components() -> Vec<ASTComponent>;
19}
20
21#[macro_export]
22macro_rules! print_linked_data_schema_for {
23  ( $x:ty ) => {
24    let schema = <$x>::shacl();
25    {
26      use ::linked_data_schema::reexports::rudof_rdf::rdf_core::RDFFormat::Turtle;
27      use ::linked_data_schema::reexports::rudof_rdf::rdf_impl::InMemoryGraph;
28      use ::linked_data_schema::reexports::shacl::ir::IRSchema;
29      use ::linked_data_schema::reexports::shacl::rdf::ShaclWriter;
30
31      let mut shacl_writer = ShaclWriter::<InMemoryGraph>::default();
32
33      println!("{:#?}", schema);
34
35      let ir_schema = IRSchema::try_from(schema).unwrap();
36
37      shacl_writer.register(&ir_schema).unwrap();
38
39      let mut cursor = std::io::Cursor::new(Vec::new());
40
41      shacl_writer.serialize(&Turtle, &mut cursor).unwrap();
42
43      let content = cursor.into_inner();
44      let s = String::from_utf8(content).unwrap();
45      println!("{}", s);
46    }
47  };
48}