refactor: src/lib structure

This commit is contained in:
Matthieu Bessat 2023-05-06 08:54:15 +02:00
parent 2f5d6a9ffd
commit bed0a3355b
30 changed files with 98 additions and 2 deletions

View file

@ -10,3 +10,8 @@ reqwest = { version = "0.11.13", features = ["blocking"] }
serde = "1.0.148"
serde_json = "1.0.89"
wikidata = { path = "../rust_wikidata/" }
[lib]
name = "popequer"
path = "src/lib/lib.rs"

View file

@ -0,0 +1,78 @@
use std::env;
use std::fs;
use popequer::wikidata_editor::fetch_item;
use popequer::schema_parser::{parse_schema, PropertySchema};
use serde_json;
fn main() {
// Lycée de gaillon : Q113129975
// Linus Torvalds : Q34253
println!("Parsing schema...");
let inp_schema = fs::read_to_string("/mnt/extra/data/workspace/popequer/data_schema/tmp_schema.txt")
.expect("Should have been able to read the schema file");
let schema_res = parse_schema(inp_schema);
if let Err(err) = schema_res {
println!("Could not parse schema file");
dbg!(err);
return;
}
let props: Vec<PropertySchema> = schema_res.unwrap();
let args: Vec<String> = env::args().collect();
let mut cmd = "help";
if args.len() >= 2 {
// command mode
cmd = &args[1];
}
match cmd {
"help" => {
println!("This is the help command");
},
"fetch-properties" => {
println!("Will fetch the most commons properties of wikidata to populate the database");
return;
},
"fetch" => {
println!("Will fetch an item and create a .txt file representation");
println!("Fetching item...");
let arg_opt = args.get(2);
if arg_opt.is_none() {
println!("Argument must be provided");
return;
}
let raw_arg = arg_opt.unwrap();
let arg_prefix_check_opt = raw_arg.chars().next();
if arg_prefix_check_opt.is_none() {
println!("Argument must be provided");
return;
}
if let Some(prefix) = arg_prefix_check_opt {
if prefix != 'Q' {
println!("Argument must be an item");
return;
}
}
let item_id_parse_res = u64::from_str_radix(raw_arg.as_str(), 10);
if let Err(err) = item_id_parse_res {
println!("Argument must be a valid wikidata item: int paring failed");
return;
}
let item = fetch_item(item_id_parse_res.unwrap()).expect("Must fetch item");
dbg!(&item);
println!("Fetched item");
let res = popequer::serializer::serialize(props, &item);
println!("{}", res);
return;
},
_ => {
println!("Invalid command issued");
}
};
return;
}

10
src/lib/data_model/mod.rs Normal file
View file

@ -0,0 +1,10 @@
// here we should define the undelying model that a popequer database should support
// this model is compatible with the wikibase model (for wikidata)
// we need to have a way to have a model of the popequer entries
// so that we can ingress them into a database
// Ideally a graph database, capable of executing SPARQL-like queries easily
// probably not a relational database
struct {
}

View file

@ -0,0 +1,3 @@
fn parse_note_file() {
}

View file

@ -16,9 +16,9 @@ fn main()
// parse_schema_wrapper();
// parse_pdel_demo();
parse_pdel_demo();
wikidata_editor_demo();
// wikidata_editor_demo();
// deserializer_wikidata_json_ld_demo();
}