Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWL literal values #20

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/src/error/type_mismatch_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ impl KindName for Kind {
Self::Normal => "a normal type",
Self::Union => "an union",
Self::Intersection => "an intersection",
Self::Restriction => "a restriction"
Self::Restriction => "a restriction",
Self::Enumeration => "an enumeration"
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions build/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{error, utils::TryCollect, Context, Descriptions, Error, ObjectToId};
use locspan::Location;
use treeldr::{Caused, Causes, Id, MaybeSet, Name, Vocabulary, WithCauses};
use treeldr::{Caused, Causes, Id, MaybeSet, Name, Vocabulary, WithCauses, Value};

pub mod array;
pub mod enumeration;
pub mod field;
pub mod primitive;
pub mod structure;
pub mod variant;

pub use array::Array;
Expand All @@ -19,6 +17,7 @@ pub enum Description<F> {
Struct(Id),
Reference(Id),
Enum(Id),
Singleton(Value),
Set(Id),
Array(Array<F>),
Alias(Id),
Expand All @@ -32,6 +31,7 @@ pub enum Kind {
Literal,
Struct,
Enum,
Singleton,
Set,
Array,
Alias,
Expand All @@ -45,6 +45,7 @@ impl<F> Description<F> {
Self::Struct(_) => Kind::Struct,
Self::Primitive(n) => Kind::Primitive(n.primitive().value().cloned()),
Self::Enum(_) => Kind::Enum,
Self::Singleton(_) => Kind::Singleton,
Self::Set(_) => Kind::Set,
Self::Array(_) => Kind::Array,
Self::Alias(_) => Kind::Alias,
Expand Down Expand Up @@ -248,6 +249,12 @@ impl<F> Description<F> {
let enm = treeldr::layout::Enum::new(name, variants);
Ok(treeldr::layout::Description::Enum(enm))
}
Description::Singleton(value) => {
let name = require_name(id, name, causes)?;
Ok(treeldr::layout::Description::Singleton(
treeldr::layout::Singleton::new(name, WithCauses::new(value, causes.clone()))
))
}
Description::Set(item_layout_id) => {
let item_layout_ref = *nodes
.require_layout(item_layout_id, causes.preferred().cloned())?
Expand Down
68 changes: 0 additions & 68 deletions build/src/layout/enumeration.rs

This file was deleted.

82 changes: 0 additions & 82 deletions build/src/layout/structure.rs

This file was deleted.

18 changes: 16 additions & 2 deletions build/src/layout/variant.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::{error, Context, Descriptions, Error};
use locspan::Location;
use treeldr::{Caused, Documentation, Id, MaybeSet, Name, Vocabulary, WithCauses};
use treeldr::{Caused, Documentation, Id, MaybeSet, Name, Vocabulary, WithCauses, Value};

/// Layout field definition.
#[derive(Clone)]
pub struct Definition<F> {
id: Id,
name: MaybeSet<Name, F>,
layout: MaybeSet<Id, F>,
value: MaybeSet<Value, F>
}

impl<F> Definition<F> {
Expand All @@ -16,6 +17,7 @@ impl<F> Definition<F> {
id,
name: MaybeSet::default(),
layout: MaybeSet::default(),
value: MaybeSet::default()
}
}

Expand Down Expand Up @@ -139,6 +141,18 @@ impl<F: Ord + Clone> Build<F> for WithCauses<Definition<F>, F> {
Ok(**nodes.require_layout(layout_id, causes.preferred().cloned())?)
})?;

Ok(treeldr::layout::Variant::new(name, layout, label, doc))
let payload = match layout.unwrap() {
None => treeldr::layout::enumeration::VariantPayload::None(self.value.clone()),
Some(layout) => {
match self.value.with_causes() {
Some(_value) => todo!(),
None => {
treeldr::layout::enumeration::VariantPayload::Some(layout)
}
}
}
};

Ok(treeldr::layout::Variant::new(name, payload, label, doc))
}
}
64 changes: 64 additions & 0 deletions build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,67 @@ impl<F: Clone> ObjectToId<F> for vocab::Object<F> {
}
}
}

pub trait ObjectToValue<F> {
fn into_value(self, cause: Option<&locspan::Location<F>>) -> Result<treeldr::Value, Error<F>>;
}

impl<F: Clone> ObjectToValue<F> for vocab::Object<F> {
fn into_value(self, cause: Option<&locspan::Location<F>>) -> Result<treeldr::Value, Error<F>> {
match self {
vocab::Object::Literal(lit) => {
let lit = match lit {
vocab::Literal::String(s) => treeldr::value::Literal::String(s.into_value().into()),
vocab::Literal::TypedString(s, ty) => {
match ty.into_value() {
vocab::Term::Xsd(vocab::Xsd::Boolean) => {
if s.as_ref() == "true" {
treeldr::value::Literal::Boolean(true)
} else if s.as_ref() == "false" {
treeldr::value::Literal::Boolean(false)
} else {
todo!("invalid boolean")
}
}
vocab::Term::Owl(vocab::Owl::Rational) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::Decimal) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::Integer) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::NonNegativeInteger) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::PositiveInteger) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::Float) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::Double) => {
todo!()
}
vocab::Term::Xsd(vocab::Xsd::String) => {
todo!()
}
ty => {
treeldr::value::Literal::Unknown(s.into_value(), ty)
}
}
}
vocab::Literal::LangString(s, _lang) => {
// TODO do not ignore lang tag.
treeldr::value::Literal::String(s.into_value().into())
}
};

Ok(treeldr::Value::Literal(lit))
},
vocab::Object::Iri(id) => Ok(treeldr::Value::Node(vocab::Id::Iri(id))),
vocab::Object::Blank(id) => Ok(treeldr::Value::Node(vocab::Id::Blank(id))),
}
}
}
24 changes: 6 additions & 18 deletions build/src/rdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ impl<F: Clone + Ord, D: Descriptions<F>> Document<F, D>
let Loc(types_id, types_loc) = expect_id(object)?;
ty.declare_intersection(types_id, Some(types_loc))?
}
Term::Owl(vocab::Owl::OneOf) => {
todo!()
}
Term::Owl(vocab::Owl::OnDatatype) => {
todo!()
}
Expand Down Expand Up @@ -246,30 +249,15 @@ impl<F: Clone + Ord, D: Descriptions<F>> Document<F, D>
let layout = context.require_layout_mut(id, Some(id_loc))?;
layout.set_deref_to(target_id, Some(loc))?
}
// Term::TreeLdr(vocab::TreeLdr::Singleton) => {
// let Loc(string, _) = expect_raw_string(object)?;
// let layout = context.require_layout_mut(id, Some(id_loc))?;
// layout.set_literal(string.into(), Some(loc))?
// }
// Term::TreeLdr(vocab::TreeLdr::Matches) => {
// let Loc(regexp_string, regexp_loc) = expect_raw_string(object)?;
// let regexp = treeldr::layout::literal::RegExp::parse(&regexp_string).map_err(
// move |e| {
// Error::new(
// error::RegExpInvalid(regexp_string.into(), e).into(),
// Some(regexp_loc),
// )
// },
// )?;
// let layout = context.require_layout_mut(id, Some(id_loc))?;
// layout.set_literal(regexp, Some(loc))?
// }
Term::TreeLdr(vocab::TreeLdr::DerivedFrom) => {
todo!()
}
Term::TreeLdr(vocab::TreeLdr::WithRestrictions) => {
todo!()
}
Term::TreeLdr(vocab::TreeLdr::Singleton) => {
todo!()
}
Term::TreeLdr(vocab::TreeLdr::Enumeration) => {
let Loc(fields_id, _) = expect_id(object)?;
let layout = context.require_layout_mut(id, Some(id_loc))?;
Expand Down
Loading