Skip to content

Commit

Permalink
example from uniprot
Browse files Browse the repository at this point in the history
  • Loading branch information
angelip2303 committed Jun 26, 2023
1 parent d603406 commit 50143db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/from_uniprot/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use pregel_rs::graph_frame::GraphFrame;
use pschema_rs::backends::ntriples::NTriples;
use pschema_rs::backends::parquet::Parquet;
use pschema_rs::backends::Backend;
use pschema_rs::pschema::PSchema;
use pschema_rs::shape::shex::{ShapeAnd, ShapeReference, TripleConstraint};

fn main() -> Result<(), String> {
// Define validation rules
let start = ShapeAnd::new(
"protein",
vec![
TripleConstraint::new(
"IsProtein",
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
"<http://purl.uniprot.org/core/Protein>",
)
.into(),
ShapeReference::new(
"annotation",
"<http://purl.uniprot.org/core/annotation>",
TripleConstraint::new(
"IsGlycosylation",
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>",
"<http://purl.uniprot.org/core/Glycosylation_Annotation>",
)
.into(),
)
.into(),
],
)
.into();

// Load Wikidata entities
let edges = NTriples::import("./examples/from_uniprot/uniprotkb_reviewed_viruses_10239.nt")?;

// Perform schema validation
match GraphFrame::from_edges(edges) {
Ok(graph) => match PSchema::new(start).validate(graph) {
Ok(subset) => Parquet::export("uniprotkb_reviewed_viruses_10239.parquet", subset),
Err(error) => Err(error.to_string()),
},
Err(error) => Err(format!("Cannot create a GraphFrame: {}", error)),
}
}
Binary file not shown.

0 comments on commit 50143db

Please sign in to comment.