1use std::collections::HashMap;
2
3use uni_cypher::ast::{Clause, 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 best_by: Option<BestByClause>,
63 pub output: RuleOutput,
64 pub priority: Option<i64>,
65}
66
67#[derive(Debug, Clone, PartialEq)]
69pub struct YieldColumn {
70 pub name: String,
71 pub is_key: bool,
72 pub is_prob: bool,
73}
74
75#[derive(Debug, Clone)]
77pub struct CompilerWarning {
78 pub code: WarningCode,
79 pub message: String,
80 pub rule_name: String,
81}
82
83#[derive(Debug, Clone, PartialEq)]
84pub enum WarningCode {
85 MsumNonNegativity,
86 ProbabilityDomainViolation,
87}
88
89#[derive(Debug, Clone, PartialEq)]
91pub enum RuntimeWarningCode {
92 SharedProbabilisticDependency,
95 BddLimitExceeded,
98 CrossGroupCorrelationNotExact,
102}
103
104#[derive(Debug, Clone)]
106pub struct RuntimeWarning {
107 pub code: RuntimeWarningCode,
109 pub message: String,
111 pub rule_name: String,
113 pub variable_count: Option<usize>,
115 pub key_group: Option<String>,
117}