better match wikibase data model

This commit is contained in:
Smitty 2021-05-28 09:54:42 -04:00
parent 10fad9247e
commit d1d175628f
3 changed files with 20 additions and 8 deletions

View file

@ -1,12 +1,14 @@
use crate::ids::{consts, Fid, Lid, Pid, Qid, Sid};
use crate::text::{Text, Lang};
use chrono::{DateTime, TimeZone, Utc};
use serde::{Deserialize, Serialize};
/// A Wikibase entity.
/// A Wikibase entity: this could be an entity, property, or lexeme.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub claims: Vec<(Pid, ClaimValue)>,
pub entity_type: EntityType,
pub description: Text,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
@ -30,10 +32,8 @@ pub enum ClaimValueData {
Item(Qid),
Property(Pid),
Stringg(String),
MonolingualText {
text: String,
lang: String,
},
MonolingualText(Text),
MultilingualText(Vec<Text>),
ExternalID(String),
Quantity {
amount: f64, // technically it could exceed the bound, but meh
@ -359,10 +359,10 @@ impl ClaimValueData {
precision: parse_wb_number(&take_prop("precision", &mut value))
.expect("Invalid precision {}") as u8,
}),
"monolingualtext" => Ok(ClaimValueData::MonolingualText {
"monolingualtext" => Ok(ClaimValueData::MonolingualText(Text {
text: get_json_string(take_prop("text", &mut value))?,
lang: get_json_string(take_prop("language", &mut value))?,
}),
lang: Lang(get_json_string(take_prop("language", &mut value))?),
})),
_ => Err(EntityError::UnknownDatatype),
}
}

View file

@ -3,3 +3,4 @@
pub mod entity;
pub mod ids;
pub mod text;

11
src/text.rs Normal file
View file

@ -0,0 +1,11 @@
use serde::{Deserialize, Serialize};
/// A language used in the Wikibase data model.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Lang(pub String);
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Text {
pub text: String,
pub lang: Lang,
}