use std::collections::HashMap;
use crate::{IID, analyze::VariableAnnotations, concept};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ConjunctionID(pub usize);
#[derive(Debug, Clone)]
pub struct Conjunction {
pub constraints: Vec<ConstraintWithSpan>,
pub variable_annotations: HashMap<Variable, VariableAnnotations>,
}
#[repr(C)]
#[derive(Debug, Clone)]
pub enum ConstraintExactness {
Exact,
Subtypes,
}
#[derive(Debug, Clone)]
pub struct ConstraintSpan {
pub begin: usize,
pub end: usize,
}
#[derive(Debug, Clone)]
pub struct ConstraintWithSpan {
pub constraint: Constraint,
pub span: Option<ConstraintSpan>,
}
#[derive(Debug, Clone)]
pub enum Constraint {
Isa { instance: ConstraintVertex, r#type: ConstraintVertex, exactness: ConstraintExactness },
Has { owner: ConstraintVertex, attribute: ConstraintVertex, exactness: ConstraintExactness },
Links {
relation: ConstraintVertex,
player: ConstraintVertex,
role: ConstraintVertex,
exactness: ConstraintExactness,
},
Sub { subtype: ConstraintVertex, supertype: ConstraintVertex, exactness: ConstraintExactness },
Owns { owner: ConstraintVertex, attribute: ConstraintVertex, exactness: ConstraintExactness },
Relates { relation: ConstraintVertex, role: ConstraintVertex, exactness: ConstraintExactness },
Plays { player: ConstraintVertex, role: ConstraintVertex, exactness: ConstraintExactness },
FunctionCall { name: String, assigned: Vec<ConstraintVertex>, arguments: Vec<ConstraintVertex> },
Expression { text: String, assigned: ConstraintVertex, arguments: Vec<ConstraintVertex> },
Is { lhs: ConstraintVertex, rhs: ConstraintVertex },
Iid { concept: ConstraintVertex, iid: IID },
Comparison { lhs: ConstraintVertex, rhs: ConstraintVertex, comparator: Comparator },
Kind { kind: concept::Kind, r#type: ConstraintVertex },
Label { r#type: ConstraintVertex, label: String },
Value { attribute_type: ConstraintVertex, value_type: concept::ValueType },
Or {
branches: Vec<ConjunctionID>,
},
Not {
conjunction: ConjunctionID,
},
Try {
conjunction: ConjunctionID,
},
}
#[derive(Debug, Hash, Clone, Eq, PartialEq)]
pub struct Variable(pub u32);
#[derive(Debug, Clone, PartialEq)]
pub enum ConstraintVertex {
Variable(Variable),
Label(concept::type_::Type),
Value(concept::Value),
NamedRole(NamedRole),
}
#[derive(Debug, Clone)]
pub struct NamedRole {
pub variable: Variable,
pub name: String,
}
impl PartialEq for NamedRole {
fn eq(&self, other: &Self) -> bool {
self.variable == other.variable }
}
#[repr(C)]
#[derive(Debug, Clone)]
pub enum Comparator {
Equal,
NotEqual,
LessThan,
LessOrEqual,
Greater,
GreaterOrEqual,
Like,
Contains,
}
impl Comparator {
pub fn symbol(&self) -> &'static str {
match self {
Comparator::Equal => "==",
Comparator::NotEqual => "!=",
Comparator::LessThan => "<",
Comparator::LessOrEqual => "<=",
Comparator::Greater => ">",
Comparator::GreaterOrEqual => ">=",
Comparator::Like => "Like",
Comparator::Contains => "Contains",
}
}
}