qualia_core_db/query/
visual_model_bridge.rs1use crate::{q_hash, NQuin};
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct UiLogicNode {
8 pub id: usize,
9 pub title: String,
10 pub kind: String,
11}
12
13#[derive(Serialize, Deserialize, Debug, Clone)]
14pub struct UiLogicEdge {
15 pub from: usize,
16 pub to: usize,
17 pub label: String,
18 pub status: String,
19}
20
21#[derive(Serialize, Deserialize, Debug, Clone)]
22pub struct UiLogicGraph {
23 pub nodes: Vec<UiLogicNode>,
24 pub edges: Vec<UiLogicEdge>,
25}
26
27#[derive(Serialize, Deserialize, Debug, Clone)]
28pub struct EvaluationReport {
29 pub contradictions: Vec<usize>, pub validations: Vec<usize>,
31}
32
33pub fn translate_graph_to_quins(graph: &UiLogicGraph, out: &mut [NQuin]) -> usize {
36 let mut count = 0;
37
38 for edge in &graph.edges {
40 if count >= out.len() {
41 break; }
43
44 let from_node = graph.nodes.iter().find(|n| n.id == edge.from);
45 let to_node = graph.nodes.iter().find(|n| n.id == edge.to);
46
47 if let (Some(f), Some(t)) = (from_node, to_node) {
48 let mut q = NQuin::default();
49 q.subject = q_hash(&f.title);
50 q.predicate = q_hash(&edge.label);
51 q.object = q_hash(&t.title);
52
53 q.parity = q.subject ^ q.predicate ^ q.object ^ q.context;
55
56 out[count] = q;
57 count += 1;
58 }
59 }
60
61 count
62}
63
64pub fn evaluate_ui_graph(graph: &UiLogicGraph) -> EvaluationReport {
66 let mut out_quins = [NQuin::default(); 128];
67 let _quin_count = translate_graph_to_quins(graph, &mut out_quins);
68
69 let mut contradictions = Vec::new();
72 let mut validations = Vec::new();
73
74 for edge in &graph.edges {
75 if edge.label == "object" {
76 contradictions.push(edge.from); } else {
78 validations.push(edge.from);
79 }
80 }
81
82 EvaluationReport {
83 contradictions,
84 validations,
85 }
86}