-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f109033
commit 643dc36
Showing
3 changed files
with
42 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,48 @@ | ||
use serde_json::{Value}; | ||
use crate::ofn_2_ldtab::util; | ||
use serde_json::json; | ||
use crate::ofn_2_ldtab::util as util; | ||
|
||
pub fn translate(v : &Value) -> Value { | ||
use serde_json::Value; | ||
|
||
pub fn translate(v: &Value) -> Value { | ||
match v[0].as_str() { | ||
Some("ObjectInverseOf") => translate_inverse_of(v), | ||
Some("ObjectInverseOf") => translate_inverse_of(v), | ||
Some(_) => panic!(), | ||
//None => owl::OWL::Named(String::from(v.as_str().unwrap())), | ||
None => translate_named_entity(&v), | ||
} | ||
} | ||
|
||
pub fn translate_named_entity(v: &Value) -> Value { | ||
let o: String = String::from(v.as_str().unwrap()); | ||
json!(o) | ||
let o: String = String::from(v.as_str().unwrap()); | ||
json!(o) | ||
} | ||
|
||
pub fn translate_inverse_of(v : &Value) -> Value { | ||
|
||
let argument: Value = translate(&v[1]); | ||
pub fn translate_inverse_of(v: &Value) -> Value { | ||
let argument: Value = translate(&v[1]); | ||
|
||
let argument_o : Value = json!({"object" : argument, | ||
let argument_o: Value = json!({"object" : argument, | ||
"datatype" : String::from(util::translate_datatype(&v[1]).as_str().unwrap())}); | ||
|
||
json!({"owl:inverseOf" : vec![argument_o]}) | ||
} | ||
json!({"owl:inverseOf" : vec![argument_o]}) | ||
} | ||
|
||
pub fn get_object(v : &Value) -> Value { | ||
pub fn get_object(v: &Value) -> Value { | ||
let o: Value = translate(&v); | ||
let d: String = String::from(util::translate_datatype(&v).as_str().unwrap()); | ||
|
||
json!({"object" : o, | ||
"datatype" : d}) | ||
"datatype" : d}) | ||
} | ||
|
||
pub fn translate_list(v : &[Value]) -> Value { | ||
|
||
//TODO: refactor common parts | ||
if v.len() == 1 { | ||
pub fn translate_list(v: &[Value]) -> Value { | ||
|
||
let first_o : Value = get_object(&v[0]); | ||
let rest_o : Value = get_object(&json!("rdf:nil")); | ||
let mut list = Vec::new(); | ||
|
||
for e in v.iter() { | ||
let e_object: Value = get_object(&e); | ||
list.push(e_object); | ||
|
||
json!({"rdf:first" : vec![first_o], | ||
"rdf:rest" : vec![rest_o]}) | ||
} else { | ||
} | ||
|
||
//let first: Value = translate(&v[0]); | ||
let rest: Value = translate_list(&v[1..]);//datatype is necessarily _JSON? | ||
Value::Array(list) | ||
|
||
let first_o : Value = get_object(&v[0]); | ||
let rest_o : Value = json!({"object" : rest, "datatype" : String::from("_JSON")}); | ||
//let rest_o : Value = get_object(rest); | ||
// | ||
json!({"rdf:first" : vec![first_o], | ||
"rdf:rest" : vec![rest_o]}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters