pub use oxrdf::{BlankNode, Literal, NamedNode, Term};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct NodeKindSet {
pub iri: bool,
pub blank: bool,
pub literal: bool,
}
impl NodeKindSet {
pub const IRI: Self = Self {
iri: true,
blank: false,
literal: false,
};
pub const BLANK_NODE: Self = Self {
iri: false,
blank: true,
literal: false,
};
pub const LITERAL: Self = Self {
iri: false,
blank: false,
literal: true,
};
pub const BLANK_NODE_OR_IRI: Self = Self {
iri: true,
blank: true,
literal: false,
};
pub const BLANK_NODE_OR_LITERAL: Self = Self {
iri: false,
blank: true,
literal: true,
};
pub const IRI_OR_LITERAL: Self = Self {
iri: true,
blank: false,
literal: true,
};
pub fn matches(&self, term: &Term) -> bool {
match term {
Term::NamedNode(_) => self.iri,
Term::BlankNode(_) => self.blank,
Term::Literal(_) => self.literal,
}
}
pub fn complement(self) -> NodeKindSet {
NodeKindSet {
iri: !self.iri,
blank: !self.blank,
literal: !self.literal,
}
}
pub fn is_empty(self) -> bool {
!self.iri && !self.blank && !self.literal
}
}