1use std::collections::HashMap;
2
3use uni_cypher::ast::{Clause, Expr, Pattern, Query};
4use uni_cypher::locy_ast::{
5 AbduceQuery, AlongBinding, BestByClause, DeriveCommand, ExplainRule, FoldBinding, GoalQuery,
6 RuleCondition, RuleOutput,
7};
8
9#[derive(Debug, Clone)]
11pub struct CompiledProgram {
12 pub strata: Vec<Stratum>,
13 pub rule_catalog: HashMap<String, CompiledRule>,
14 pub warnings: Vec<CompilerWarning>,
15 pub commands: Vec<CompiledCommand>,
16}
17
18#[derive(Debug, Clone)]
20pub enum CompiledCommand {
21 GoalQuery(GoalQuery),
22 Assume(CompiledAssume),
23 Abduce(AbduceQuery),
24 ExplainRule(ExplainRule),
25 DeriveCommand(DeriveCommand),
26 Cypher(Query),
27}
28
29#[derive(Debug, Clone)]
31pub struct CompiledAssume {
32 pub mutations: Vec<Clause>,
33 pub body_program: CompiledProgram,
34 pub body_commands: Vec<CompiledCommand>,
35}
36
37#[derive(Debug, Clone)]
39pub struct Stratum {
40 pub id: usize,
41 pub rules: Vec<CompiledRule>,
42 pub is_recursive: bool,
43 pub depends_on: Vec<usize>,
44}
45
46#[derive(Debug, Clone)]
48pub struct CompiledRule {
49 pub name: String,
50 pub clauses: Vec<CompiledClause>,
51 pub yield_schema: Vec<YieldColumn>,
52 pub priority: Option<i64>,
53}
54
55#[derive(Debug, Clone)]
57pub struct CompiledClause {
58 pub match_pattern: Pattern,
59 pub where_conditions: Vec<RuleCondition>,
60 pub along: Vec<AlongBinding>,
61 pub fold: Vec<FoldBinding>,
62 pub having: Vec<Expr>,
64 pub best_by: Option<BestByClause>,
65 pub output: RuleOutput,
66 pub priority: Option<i64>,
67}
68
69#[derive(Debug, Clone, PartialEq)]
71pub struct YieldColumn {
72 pub name: String,
73 pub is_key: bool,
74 pub is_prob: bool,
75}
76
77#[derive(Debug, Clone)]
79pub struct CompilerWarning {
80 pub code: WarningCode,
81 pub message: String,
82 pub rule_name: String,
83}
84
85#[derive(Debug, Clone, PartialEq)]
86pub enum WarningCode {
87 MsumNonNegativity,
88 ProbabilityDomainViolation,
89}
90
91#[derive(Debug, Clone, PartialEq)]
93pub enum RuntimeWarningCode {
94 SharedProbabilisticDependency,
97 BddLimitExceeded,
100 CrossGroupCorrelationNotExact,
104}
105
106#[derive(Debug, Clone)]
108pub struct RuntimeWarning {
109 pub code: RuntimeWarningCode,
111 pub message: String,
113 pub rule_name: String,
115 pub variable_count: Option<usize>,
117 pub key_group: Option<String>,
119}