Skip to content

Commit

Permalink
feat: Expose computations to WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
hobofan committed Mar 24, 2023
1 parent 334a1a4 commit 21cdd98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/api/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::Ontology;
use js_sys::{Array, Number, JSON};
use wasm_bindgen::{prelude::*, JsCast};
use web_sys::console::error_1;
use crate::computation::GetComputations;

#[wasm_bindgen]
impl Ontology {
Expand Down Expand Up @@ -99,6 +100,20 @@ impl Ontology {
}
array.unchecked_into()
}

/// Get all FNO/Oxolotl computations of this ontology.
#[wasm_bindgen(js_name = "computations")]
pub fn wasm_computations(&self) -> ComputationArray {
let array = Array::new();
for a in self.computations() {
if let Ok(s) = serde_json::to_string(&a) {
if let Ok(value) = JSON::parse(&s) {
array.push(&value);
}
}
}
array.unchecked_into()
}
}

#[wasm_bindgen]
Expand All @@ -107,6 +122,8 @@ extern "C" {
pub type AxiomArray;
#[wasm_bindgen(typescript_type = "Array<Declaration>")]
pub type DeclarationArray;
#[wasm_bindgen(typescript_type = "Array<Computation>")]
pub type ComputationArray;
}

#[wasm_bindgen(typescript_custom_section)]
Expand Down Expand Up @@ -153,6 +170,11 @@ interface Axiom {
HasKey?: HasKey
}
interface Computation {
iri: IRI,
axioms: Array<Axiom>,
}
export interface AxiomMatcher<R> {
AnnotationAssertion?: (a: AnnotationAssertion) => R
SubObjectPropertyOf?: (a: SubObjectPropertyOf) => R
Expand Down
4 changes: 3 additions & 1 deletion src/computation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

use crate::{
api::{Ontology, IRI},
owl::{well_known, Axiom, ClassAssertion, ClassConstructor},
};

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Computation {
iri: IRI,
axioms: Vec<Axiom>,
Expand All @@ -19,7 +21,7 @@ impl Computation {
}
}

trait GetComputations {
pub trait GetComputations {
fn computations(&self) -> Vec<Computation>;
}

Expand Down
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ mod tests {
},
parser::{ParserOptions, ParserOptionsBuilder},
};
use crate::computation::GetComputations;

#[test]
fn ontology() {
Expand Down

0 comments on commit 21cdd98

Please sign in to comment.