Commit 1da7dba6 authored by Ulrich's avatar Ulrich

harvest for Toms thesis

parent bd60490b
......@@ -13,6 +13,8 @@ use spotter_lib::data::*;
use libxml::tree::*;
use libxml::parser::Parser;
//Creates Harvests for Tom Wiesing's BSc thesis
pub fn main() {
let args : Vec<_> = env::args().collect();
......@@ -101,14 +103,17 @@ pub fn read_document(s : &str, config : &Config, filename : &str) -> String{
let doc = opt_doc.unwrap();
let root = doc.get_root_element();
let mut content = format!("<?xml version=\"1.0\" ?>\n<mws:harvest xmlns:m=\"http://www.w3.org/1998/Math/MathML\" xmlns:mws=\"http://search.mathweb.org/ns\">");
let mut content = format!("<?xml version=\"1.0\" ?>\n<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns\" xmlns:m=\"http://www.w3.org/1998/Math/MathML\">\n");
let expr = create_harvest(&root, &doc, config, filename);
let vec = create_harvest(&root, &doc, config, filename);
content.push_str(&expr);
for expr in vec {
content.push_str(&expr);
content.push_str("\n");
}
content = format!("{}</mws:harvest>", content);
content = format!("{}</rdf:RDF>", content);
return content;
......@@ -116,9 +121,10 @@ pub fn read_document(s : &str, config : &Config, filename : &str) -> String{
//doc.save_file(&s).unwrap();
}
fn create_harvest(node : &Node, document : &Document, config : &Config, filename : &str) -> String{
fn create_harvest(node : &Node, document : &Document, config : &Config, filename : &str) -> Vec<String>{
let mut cnml = false;
let mut result = String::new();
let mut result = Vec::new();
let mut resource = String::new();
match node.get_type().unwrap() {
NodeType::ElementNode => {
if node.get_name().eq("Description"){
......@@ -126,31 +132,12 @@ fn create_harvest(node : &Node, document : &Document, config : &Config, filename
let mut c = node.get_first_child();
let mut opt_id = String::new();
while c.is_some(){
let c_unw = c.unwrap();
if c_unw.get_name().eq("annotates"){
let resource = c_unw.get_property("resource").unwrap();
let mut start = false;
for c in resource.chars(){
if start{
if c.eq(&'\''){
break;
}else{
opt_id.push(c);
}
}else{
if c.eq(&'\''){
start = true;
}
}
}
resource = c_unw.get_property("resource").unwrap();
}else if c_unw.get_name().eq("contentmathml"){
......@@ -172,8 +159,8 @@ fn create_harvest(node : &Node, document : &Document, config : &Config, filename
}
if opt_harvest.is_some() {
let bla = format!("<mws:expr url=\"http://localhost/{}#{}\">\n{}</mws:expr>\n", filename, opt_id.clone(), opt_harvest.unwrap());
result.push_str(&bla);
let test = format!("<rdf:Description rdf:about=\"{}\">\n<rdf:XMLLiteral>\n{}\n</rdf:XMLLiteral>\n</rdf:Description>", resource.clone(), opt_harvest.unwrap());
result.push(test);
}
}
......@@ -192,7 +179,7 @@ fn create_harvest(node : &Node, document : &Document, config : &Config, filename
if !cnml {
let mut c: Option<Node> = node.get_first_child();
while let Some(child) = c {
result.push_str(&create_harvest(&child, document, config, filename));
result.append(&mut create_harvest(&child, document, config, filename));
c = child.get_next_sibling();
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment