Conversion and comparison

Convert and compare schemas, and read DCTAP profiles and rdf-config documents.

Schema conversion and comparison

These operations need the conversion and comparison features, which are on by default.

#![allow(unused)]
fn main() {
use rudof_lib::{Rudof, RudofConfig};
use rudof_lib::formats::{
    ComparisonFormat, ComparisonMode, ConversionFormat, ConversionMode, InputSpec,
    ResultComparisonFormat, ResultConversionFormat, ResultConversionMode,
};
use std::str::FromStr;

let mut rudof = Rudof::new(RudofConfig::default());
let shacl_input = InputSpec::from_str(
    r#"
        prefix sh: <http://www.w3.org/ns/shacl#>
        prefix : <http://example.org/>
        prefix xsd: <http://www.w3.org/2001/XMLSchema#>
        :PersonShape a sh:NodeShape ;
            sh:property [ sh:path :name ; sh:datatype xsd:string ] .
    "#
).unwrap();

// Convert SHACL shapes to ShExC and write the result to standard output
rudof.show_schema_conversion(
    &shacl_input,
    &ConversionMode::Shacl,
    &ResultConversionMode::ShEx,
    &ConversionFormat::Turtle,
    &ResultConversionFormat::ShExC,
    &mut std::io::stdout(),
)
.execute()
.unwrap();

// Compare a ShEx shape with a SHACL shape
let shex_input = InputSpec::from_str(
    r#"
        prefix : <http://example.org/>
        prefix xsd: <http://www.w3.org/2001/XMLSchema#>
        :PersonShape { :name xsd:string }
    "#
).unwrap();
rudof.show_schema_comparison(
    &shex_input,
    &shacl_input,
    &ComparisonFormat::ShExC,
    &ComparisonFormat::Turtle,
    &ComparisonMode::ShEx,
    &ComparisonMode::Shacl,
    &mut std::io::stdout(),
)
.with_shape1("http://example.org/PersonShape")
.with_shape2("http://example.org/PersonShape")
.with_result_format(&ResultComparisonFormat::Json)
.execute()
.unwrap();
}

DCTAP

#![allow(unused)]
fn main() {
use rudof_lib::{Rudof, RudofConfig};
use rudof_lib::formats::{InputSpec, DCTapFormat, ResultDCTapFormat};
use std::str::FromStr;

let mut rudof = Rudof::new(RudofConfig::default());
let dctap_input = InputSpec::from_str(
    r#"
        shapeID,propertyID,mandatory,repeatable,valueDataType
        :Person,rdf:type,true,false,
        :Person,schema:name,true,false,xsd:string
        :Person,schema:age,false,false,xsd:integer
        :Person,schema:memberOf,false,true,:Organization
        :Organization,rdf:type,true,false,
        :Organization,schema:name,true,false,xsd:string
        :Organization,schema:location,false,false,xsd:string
    "#
).unwrap();

// Load a DCTAP into Rudof's state
rudof.load_dctap(&dctap_input)
    .with_dctap_format(&DCTapFormat::Csv)
    .execute()
    .unwrap();

// Serialize the loaded DCTAP to standard output
rudof.serialize_dctap(&mut std::io::stdout())
    .with_result_dctap_format(&ResultDCTapFormat::Json)
    .execute()
    .unwrap();

// Reset DCTAP state
rudof.reset_dctap().execute();
}

rdf-config

#![allow(unused)]
fn main() {
use rudof_lib::{Rudof, RudofConfig};
use rudof_lib::formats::{InputSpec, RdfConfigFormat, ResultRdfConfigFormat};
use std::str::FromStr;

let mut rudof = Rudof::new(RudofConfig::default());
let config_input = InputSpec::from_str(
    r#"
        - Person ex:person1 ex:person2:
        - a: ex:Person
        - rdfs:label:
            - name: "Alice"
        - ex:age?:
            - age_value: 32
        - ex:memberOf:
            - organization: Organization
        - Organization ex:org1:
        - a: ex:Organization
        - rdfs:label:
            - org_name: "Example Org"
        - ex:location:
            - city: "Oviedo"
    "#).unwrap();

// Load RDF config
rudof.load_rdf_config(&config_input)
    .with_rdf_config_format(&RdfConfigFormat::Yaml)
    .execute()
    .unwrap();

// Serialize the loaded RDF config to standard output
rudof.serialize_rdf_config(&mut std::io::stdout())
    .with_result_rdf_config_format(&ResultRdfConfigFormat::Yaml)
    .execute()
    .unwrap();

// Reset RDF config state
rudof.reset_rdf_config().execute();
}