Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
feat(docs): a diagram section's candidates carry its diagram family's p
Martin Vogel72b8176ffec7
diff --git a/src/pipeline/pass_semantic_edges.c b/src/pipeline/pass_semantic_edges.cindex 30b2c4954..e5822d809 100644--- a/src/pipeline/pass_semantic_edges.c+++ b/src/pipeline/pass_semantic_edges.c@@ -2904,12 +2904,39 @@ typedef struct {int n;} doc_rows_t;+/* The diagram family of a section: the highest of the Diagram nodes it+ * DEFINES (cbm_sem_diag_family), CBM_SEM_DIAG_NONE without one. */+static cbm_sem_diag_family_t doc_section_family(const cbm_gbuf_t *gbuf,+ const cbm_gbuf_node_t *sec) {+ const cbm_gbuf_edge_t **edges = NULL;+ int n = 0;+ cbm_sem_diag_family_t fam = CBM_SEM_DIAG_NONE;+ if (cbm_gbuf_find_edges_by_source_type(gbuf, sec->id, "DEFINES", &edges, &n) != 0) {+ return fam;+ }+ for (int i = 0; i < n; i++) {+ const cbm_gbuf_node_t *t = cbm_gbuf_find_by_id(gbuf, edges[i]->target_id);+ if (!t || !t->label || strcmp(t->label, "Diagram") != 0 || !t->properties_json) {+ continue;+ }+ char fmt[CBM_SZ_32];+ char kind[CBM_SZ_32];+ const char *f = json_str_value(t->properties_json, "format", fmt, sizeof(fmt));+ const char *k = json_str_value(t->properties_json, "diagram_kind", kind, sizeof(kind));+ cbm_sem_diag_family_t df = cbm_sem_diag_family(f, k);+ if (df > fam) {+ fam = df;+ }+ }+ return fam;+}+/* Append the candidate (section -> target) when its judged p is above 0 and* the graph does not link the pair exactly; false: out of memory (the row at* rw->n may hold partial strings). */static bool doc_row_add(doc_rows_t *rw, const cbm_gbuf_t *gbuf, const cbm_gbuf_node_t *sec,- const cbm_gbuf_node_t *target, const doc_hit_t *hit,- cbm_sem_doc_kind_t kind, const char *home) {+ cbm_sem_diag_family_t fam, const cbm_gbuf_node_t *target,+ const doc_hit_t *hit, cbm_sem_doc_kind_t kind, const char *home) {if (!target || !target->qualified_name || !sec->qualified_name) {return true;}@@ -2917,7 +2944,7 @@ static bool doc_row_add(doc_rows_t *rw, const cbm_gbuf_t *gbuf, const cbm_gbuf_ncbm_sem_doc_format_t fmt = cbm_sem_doc_format(sec->file_path);float p = kind == CBM_SEM_DOC_KIND_FOLDER? cbm_sem_doc_folder_p(fmt, sec->file_path)- : cbm_sem_doc_calibrated_p(fmt, kind, pos, hit->tfidf);+ : cbm_sem_doc_section_p(fmt, fam, kind, pos, hit->tfidf);if (p <= 0.0F || doc_pair_linked(gbuf, sec->id, target->id)) {return true; /* not stored for this band, kind or format; or linked exactly */}@@ -2944,25 +2971,26 @@ static bool doc_section_rows(doc_rows_t *rw, const cbm_gbuf_t *gbuf, const doc_cconst doc_place_t *pl, int s) {const cbm_gbuf_node_t *sec = dc->secs[s];const doc_result_t *r = &dc->res[s];+ cbm_sem_diag_family_t fam = doc_section_family(gbuf, sec);bool ok = true;for (int h = 0; ok && h < r->n + r->nlocal; h++) {const doc_hit_t *hit = h < r->n ? &r->hits[h] : &r->local[h - r->n];if (h < r->n && (hit->rank > CBM_SEM_DOC_TOP_K || hit->tfidf < CBM_SEM_DOC_MIN_SCORE)) {continue;}- ok =- doc_row_add(rw, gbuf, sec, cbm_gbuf_find_by_id(gbuf, dc->funcs[hit->func].node_id), hit,- h < r->n ? CBM_SEM_DOC_KIND_FUNCTION : CBM_SEM_DOC_KIND_LOCAL, pl->home[s]);+ ok = doc_row_add(+ rw, gbuf, sec, fam, cbm_gbuf_find_by_id(gbuf, dc->funcs[hit->func].node_id), hit,+ h < r->n ? CBM_SEM_DOC_KIND_FUNCTION : CBM_SEM_DOC_KIND_LOCAL, pl->home[s]);}for (int h = 0; ok && h < r->nfiles; h++) {const doc_file_hit_t *fh = &r->files[h];doc_hit_t hit = {.tfidf = fh->tfidf, .rank = fh->rank, .shared = fh->shared};- ok = doc_row_add(rw, gbuf, sec, dc->files->node[fh->file], &hit, CBM_SEM_DOC_KIND_FILE,+ ok = doc_row_add(rw, gbuf, sec, fam, dc->files->node[fh->file], &hit, CBM_SEM_DOC_KIND_FILE,pl->home[s]);}doc_hit_t first = {.rank = SKIP_ONE};- return ok && doc_row_add(rw, gbuf, sec, doc_home_folder(pl, s), &first, CBM_SEM_DOC_KIND_FOLDER,- pl->home[s]);+ return ok && doc_row_add(rw, gbuf, sec, fam, doc_home_folder(pl, s), &first,+ CBM_SEM_DOC_KIND_FOLDER, pl->home[s]);}/* The stored candidates of every section -- its best CBM_SEM_DOC_TOP_Kdiff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.hindex b40ea682b..da925d2ab 100644--- a/src/pipeline/pipeline_internal.h+++ b/src/pipeline/pipeline_internal.h@@ -1282,7 +1282,13 @@ int cbm_pipeline_build_fresh_semantic_manifest(cbm_pipeline_t *p, const char *pr* properties are read with their escapes, admission is best-first and* every edge carries "p"; doc_link_candidates holds doc section -> code* candidates. An index built before has the old pairs and no- * candidates, so it rebuilds once on upgrade. */+ * candidates, so it rebuilds once on upgrade. Released together with+ * 7 (no release in between, so no number of its own): doc comments of+ * Go, Java, Kotlin, Rust, Perl, TS/JS, PHP and C hold MENTIONS edges;+ * diagrams are Diagram/DiagramElement nodes with DIAGRAM_ARROW edges;+ * OpenAPI operations are Routes; a Markdown section's text keeps a+ * diagram fence's labels instead of its syntax, and its candidates+ * carry the p of its diagrams' kind family. */enum { CBM_SEMANTIC_INDEX_VERSION = 7 };typedef struct {diff --git a/src/semantic/semantic.c b/src/semantic/semantic.cindex af738151e..704994ede 100644--- a/src/semantic/semantic.c+++ b/src/semantic/semantic.c@@ -1973,6 +1973,72 @@ float cbm_sem_doc_folder_p(cbm_sem_doc_format_t fmt, const char *doc_path) {return readme ? 0.867F : 0.0F;}+cbm_sem_diag_family_t cbm_sem_diag_family(const char *format, const char *diagram_kind) {+ static const char *const mermaid[] = {"sequence", "class", "er",+ "c4_context", "c4_container", "c4_component",+ "c4_dynamic", "c4_deployment", "architecture"};+ static const char *const plantuml[] = {"c4", "class", "sequence", "usecase", "component"};+ if (!format || !format[0]) {+ return CBM_SEM_DIAG_NONE;+ }+ const char *const *structural = NULL;+ size_t n = 0;+ if (strcmp(format, "mermaid") == 0) {+ structural = mermaid;+ n = sizeof(mermaid) / sizeof(mermaid[0]);+ } else if (strcmp(format, "plantuml") == 0) {+ structural = plantuml;+ n = sizeof(plantuml) / sizeof(plantuml[0]);+ } else {+ return CBM_SEM_DIAG_GRAPH;+ }+ for (size_t i = 0; diagram_kind && i < n; i++) {+ if (strcmp(diagram_kind, structural[i]) == 0) {+ return CBM_SEM_DIAG_STRUCTURAL;+ }+ }+ return CBM_SEM_DIAG_PROSE;+}++/* Markdown sections that embed a diagram, by the section's family (DIAG-C,+ * 2026-10-11: 553 blind-judged candidates from sections of 16 held-out+ * repositories that embed a diagram, three reading rounds; function+ * candidates at or inside the home pooled, as both curves rose by band).+ * A diagram section is about its candidates more often than SEM7's Markdown+ * curve says, so its first band is stored too:+ * prose 0.24 / 0.28 / 0.45, local extras 11 of 40 = 0.275+ * structural 0.32 / 0.46 / 0.57, local extras 7 of 9 = 0.78 (every+ * local extra of the family; 95% interval 0.45-0.94)+ * Graph diagrams (DOT, D2) were not found in Markdown sections: SEM7. */+static const struct {+ bool fitted;+ float function[SEM_DOC_P_NBANDS];+ float local;+} SEM_DOC_P_MD_DIAGRAM[CBM_SEM_DIAG_COUNT] = {+ [CBM_SEM_DIAG_PROSE] = {true, {0.0F, 0.24F, 0.28F, 0.45F}, 0.275F},+ [CBM_SEM_DIAG_STRUCTURAL] = {true, {0.0F, 0.32F, 0.464F, 0.567F}, 0.778F},+};++float cbm_sem_doc_section_p(cbm_sem_doc_format_t fmt, cbm_sem_diag_family_t fam,+ cbm_sem_doc_kind_t kind, cbm_sem_doc_pos_t pos, float score) {+ bool fitted = fmt == CBM_SEM_DOC_FMT_MARKDOWN && (int)fam > 0 && fam < CBM_SEM_DIAG_COUNT &&+ SEM_DOC_P_MD_DIAGRAM[fam].fitted;+ bool home = pos == CBM_SEM_DOC_POS_GLOBAL || pos == CBM_SEM_DOC_POS_LOCAL;+ if (!fitted || !((kind == CBM_SEM_DOC_KIND_FUNCTION && home) ||+ (kind == CBM_SEM_DOC_KIND_LOCAL && pos == CBM_SEM_DOC_POS_LOCAL))) {+ return cbm_sem_doc_calibrated_p(fmt, kind, pos, score);+ }+ size_t band = 0;+ while (band < SEM_DOC_P_NBANDS - 1 && score >= SEM_DOC_P_CUTS[band]) {+ band++;+ }+ if (band == 0) {+ return 0.0F; /* below CBM_SEM_DOC_MIN_SCORE: never measured, nothing stored */+ }+ return kind == CBM_SEM_DOC_KIND_LOCAL ? SEM_DOC_P_MD_DIAGRAM[fam].local+ : SEM_DOC_P_MD_DIAGRAM[fam].function[band];+}+float cbm_sem_combined_score(const cbm_sem_func_t *a, const cbm_sem_func_t *b,const cbm_sem_config_t *cfg) {if (!a || !b || !cfg) {diff --git a/src/semantic/semantic.h b/src/semantic/semantic.hindex 66f4cc0a1..9f40c1041 100644--- a/src/semantic/semantic.h+++ b/src/semantic/semantic.h@@ -319,6 +319,28 @@ float cbm_sem_doc_calibrated_p(cbm_sem_doc_format_t fmt, cbm_sem_doc_kind_t kind* stored. */float cbm_sem_doc_folder_p(cbm_sem_doc_format_t fmt, const char *doc_path);+/* The kind family of a diagram a section embeds, by its format and+ * diagram_kind: structural (Mermaid sequence, class, ER, C4 and architecture;+ * PlantUML C4, class, sequence, use-case and component), prose (any other+ * Mermaid or PlantUML diagram) or graph (any other format). A section's family+ * is the highest any of its diagrams has, in this order. */+typedef enum {+ CBM_SEM_DIAG_NONE = 0,+ CBM_SEM_DIAG_GRAPH,+ CBM_SEM_DIAG_PROSE,+ CBM_SEM_DIAG_STRUCTURAL,+ CBM_SEM_DIAG_COUNT,+} cbm_sem_diag_family_t;+cbm_sem_diag_family_t cbm_sem_diag_family(const char *format, const char *diagram_kind);++/* cbm_sem_doc_calibrated_p for a section that embeds diagrams of family fam:+ * a Markdown section of a family with its own judged curve takes that curve+ * for function candidates at or inside the home and for local extras; every+ * other candidate, and every section of another family, as+ * cbm_sem_doc_calibrated_p. */+float cbm_sem_doc_section_p(cbm_sem_doc_format_t fmt, cbm_sem_diag_family_t fam,+ cbm_sem_doc_kind_t kind, cbm_sem_doc_pos_t pos, float score);+/* p as stored and shown: two decimals, half up (0.225 -> 0.23, 0.325 ->* 0.33; the epsilon absorbs the float representation of a judged x.xx5). */double cbm_sem_p_2dp(float p);diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex ddf7bc5a5..7684868e4 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -18948,11 +18948,12 @@ TEST(pipeline_semantic_edges_carry_p) {PASS();}-/* The p a stored candidate row must carry: the curve of the row's kind and- * position (read from its evidence) at its score, two decimals; -1 for an- * unknown kind or position. *is_function: a function candidate (top 5). */-static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float score,- bool *is_function) {+/* The p a stored candidate row of a section embedding diagrams of family fam+ * must carry: the curve of the row's kind and position (read from its+ * evidence) at its score, two decimals; -1 for an unknown kind or position.+ * *is_function: a function candidate (top 5). */+static double doc_row_want_family(const char *evidence, cbm_sem_doc_format_t fmt,+ cbm_sem_diag_family_t fam, float score, bool *is_function) {static const struct {const char *name;cbm_sem_doc_kind_t kind;@@ -18973,8 +18974,14 @@ static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float}*is_function = k == 0;return k < 0 || p < 0 ? -1.0- : cbm_sem_p_2dp(cbm_sem_doc_calibrated_p(fmt, KINDS[k].kind,- POSITIONS[p].pos, score));+ : cbm_sem_p_2dp(cbm_sem_doc_section_p(fmt, fam, KINDS[k].kind,+ POSITIONS[p].pos, score));+}++/* doc_row_want_family for a section without a diagram. */+static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float score,+ bool *is_function) {+ return doc_row_want_family(evidence, fmt, CBM_SEM_DIAG_NONE, score, is_function);}/* Count a section's stored doc -> code candidates (section QN containing@@ -19219,6 +19226,133 @@ TEST(pipeline_doc_candidates_skip_exact_links_and_use_format_curves) {PASS();}+/* The rows of a section (its QN contains heading): their count; *bad the+ * rows off the curve of the section's diagram family fam; *own the rows+ * whose p differs from a section without a diagram. */+static int doc_family_rows(cbm_store_t *s, const char *heading, cbm_sem_diag_family_t fam, int *bad,+ int *own) {+ sqlite3_stmt *st = NULL;+ *bad = 0;+ *own = 0;+ if (sqlite3_prepare_v2(cbm_store_get_db(s),+ "SELECT score, p, evidence FROM doc_link_candidates "+ "WHERE instr(section_qn, ?1) > 0",+ -1, &st, NULL) != SQLITE_OK) {+ return -1;+ }+ sqlite3_bind_text(st, 1, heading, -1, SQLITE_TRANSIENT);+ int n = 0;+ while (sqlite3_step(st) == SQLITE_ROW) {+ float score = (float)sqlite3_column_double(st, 0);+ double p = sqlite3_column_double(st, 1);+ const char *ev = (const char *)sqlite3_column_text(st, 2);+ bool is_function = false;+ double want = doc_row_want_family(ev, CBM_SEM_DOC_FMT_MARKDOWN, fam, score, &is_function);+ *bad += want <= 0.0 || p != want;+ *own += want != doc_row_want(ev, CBM_SEM_DOC_FMT_MARKDOWN, score, &is_function);+ n++;+ }+ sqlite3_finalize(st);+ return n;+}++/* The diagram_kind of the Diagram a section (its QN contains heading)+ * DEFINES, "" without one. */+static void doc_section_diagram_kind(cbm_store_t *s, const char *heading, char *out,+ size_t out_sz) {+ sqlite3_stmt *st = NULL;+ out[0] = '\0';+ if (sqlite3_prepare_v2(cbm_store_get_db(s),+ "SELECT json_extract(d.properties, '$.diagram_kind') FROM edges e "+ "JOIN nodes a ON a.id = e.source_id JOIN nodes d ON d.id = e.target_id "+ "WHERE e.type = 'DEFINES' AND a.label = 'Section' "+ "AND d.label = 'Diagram' AND instr(a.qualified_name, ?1) > 0",+ -1, &st, NULL) != SQLITE_OK) {+ return;+ }+ sqlite3_bind_text(st, 1, heading, -1, SQLITE_TRANSIENT);+ if (sqlite3_step(st) == SQLITE_ROW && sqlite3_column_text(st, 0)) {+ snprintf(out, out_sz, "%s", (const char *)sqlite3_column_text(st, 0));+ }+ sqlite3_finalize(st);+}++/* A Markdown section that embeds a diagram takes its diagram family's judged+ * curve (DIAG-C): a sequence diagram is structural, a flowchart is prose; a+ * section without a diagram keeps the Markdown curve. Some rows of each+ * diagram section must carry a p the Markdown curve would not give. */+TEST(pipeline_doc_candidates_diagram_family_curves) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_docdiag_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ static const char *const subjects[] = {"mail", "cache", "queue", "user", "server", "client"};+ for (size_t i = 0; i < sizeof(subjects) / sizeof(subjects[0]); i++) {+ write_py_family(tmp, subjects[i]);+ }+ char docs[512];+ snprintf(docs, sizeof(docs), "%s/docs", tmp);+ ASSERT_TRUE(cbm_mkdir_p(docs, 0755));+ write_temp_file(+ tmp, "docs/mail.md",+ "# Mail loading\n\n"+ "Load the mail config from disk and validate every mail field before the "+ "parsed mail settings are returned; missing mail fields fail the validation.\n\n"+ "```mermaid\nsequenceDiagram\n"+ " participant Loader\n participant Validator\n"+ " Loader->>Validator: validate mail config\n```\n\n"+ "# Mail writing\n\n"+ "Write the mail config back to disk after validating it, so the written "+ "mail config file always carries every mail field it needs.\n\n"+ "```mermaid\nflowchart TD\n"+ " validate[validate mail config] --> write[write mail config]\n```\n\n"+ "# Mail parsing\n\n"+ "Parse the mail config file and return the parsed mail settings; the mail "+ "config is loaded from disk and every mail field is validated first.\n");+ char db[512];+ snprintf(db, sizeof(db), "%s/docdiag.db", tmp);+ cbm_pipeline_incremental_test_reset_faults();+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ cbm_pipeline_free(p);++ cbm_store_t *s = cbm_store_open_path(db);+ ASSERT_NOT_NULL(s);+ char seq_kind[32];+ char flow_kind[32];+ char none_kind[32];+ doc_section_diagram_kind(s, "Mail-loading", seq_kind, sizeof(seq_kind));+ doc_section_diagram_kind(s, "Mail-writing", flow_kind, sizeof(flow_kind));+ doc_section_diagram_kind(s, "Mail-parsing", none_kind, sizeof(none_kind));+ int seq_bad = 0;+ int seq_own = 0;+ int flow_bad = 0;+ int flow_own = 0;+ int none_bad = 0;+ int none_own = 0;+ int seq = doc_family_rows(s, "Mail-loading", CBM_SEM_DIAG_STRUCTURAL, &seq_bad, &seq_own);+ int flow = doc_family_rows(s, "Mail-writing", CBM_SEM_DIAG_PROSE, &flow_bad, &flow_own);+ int none = doc_family_rows(s, "Mail-parsing", CBM_SEM_DIAG_NONE, &none_bad, &none_own);+ cbm_store_close(s);+ th_rmtree(tmp);+ cbm_pipeline_incremental_test_reset_faults();+ ASSERT_STR_EQ(seq_kind, "sequence");+ ASSERT_STR_EQ(flow_kind, "flowchart");+ ASSERT_STR_EQ(none_kind, "");+ ASSERT_EQ(cbm_sem_diag_family("mermaid", seq_kind), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", flow_kind), CBM_SEM_DIAG_PROSE);+ ASSERT_GT(seq, 0);+ ASSERT_EQ(seq_bad, 0);+ ASSERT_GT(seq_own, 0);+ ASSERT_GT(flow, 0);+ ASSERT_EQ(flow_bad, 0);+ ASSERT_GT(flow_own, 0);+ ASSERT_GT(none, 0);+ ASSERT_EQ(none_bad, 0);+ ASSERT_EQ(none_own, 0);+ PASS();+}+/* Lines of a CBM_SEM_DOC_SIGNALS dump whose section file, kind, position,* home and target file equal the given values (NULL: any). */static int doc_signal_count(const char *dump, const char *sec_file, const char *kind,@@ -20312,6 +20446,7 @@ SUITE(pipeline) {RUN_TEST(pipeline_doc_candidates_published_and_kept_by_delta);RUN_TEST(pipeline_doc_candidates_skip_exact_links_and_use_format_curves);RUN_TEST(pipeline_doc_candidates_home_position_and_kinds);+ RUN_TEST(pipeline_doc_candidates_diagram_family_curves);RUN_TEST(pipeline_cpp_static_factory_pointer_receiver_issue1153);RUN_TEST(pipeline_cpp_static_factory_reference_receiver_issue1153);RUN_TEST(pipeline_cpp_static_factory_unique_ptr_receiver_issue1153);diff --git a/tests/test_semantic.c b/tests/test_semantic.cindex f1ebd09f7..654c1b536 100644--- a/tests/test_semantic.c+++ b/tests/test_semantic.c@@ -611,6 +611,86 @@ TEST(sem_doc_calibrated_p_bands) {PASS();}+/* A section's diagram family (DIAG-C): Mermaid and PlantUML structural kinds,+ * any other Mermaid or PlantUML kind is prose, any other format a graph. */+TEST(sem_diag_family_by_format_and_kind) {+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "sequence"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "class"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "er"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "c4_deployment"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "architecture"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "flowchart"), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "state"), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", "usecase"), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("mermaid", NULL), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("plantuml", "usecase"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("plantuml", "component"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("plantuml", "c4"), CBM_SEM_DIAG_STRUCTURAL);+ ASSERT_EQ(cbm_sem_diag_family("plantuml", "activity"), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("plantuml", "er"), CBM_SEM_DIAG_PROSE);+ ASSERT_EQ(cbm_sem_diag_family("dot", "digraph"), CBM_SEM_DIAG_GRAPH);+ ASSERT_EQ(cbm_sem_diag_family("d2", "d2"), CBM_SEM_DIAG_GRAPH);+ ASSERT_EQ(cbm_sem_diag_family("", "sequence"), CBM_SEM_DIAG_NONE);+ ASSERT_EQ(cbm_sem_diag_family(NULL, NULL), CBM_SEM_DIAG_NONE);+ PASS();+}++/* A Markdown section that embeds a diagram (DIAG-C): function candidates at+ * or inside the home and local extras carry the family's judged curve, from+ * the first band; outside functions, files, other formats, graph diagrams+ * and sections without a diagram keep cbm_sem_doc_calibrated_p. */+TEST(sem_doc_section_p_diagram_families) {+ const cbm_sem_doc_format_t md = CBM_SEM_DOC_FMT_MARKDOWN;+ const cbm_sem_doc_kind_t fn = CBM_SEM_DOC_KIND_FUNCTION;+ const cbm_sem_doc_kind_t lx = CBM_SEM_DOC_KIND_LOCAL;+ const cbm_sem_doc_pos_t global = CBM_SEM_DOC_POS_GLOBAL;+ const cbm_sem_doc_pos_t local = CBM_SEM_DOC_POS_LOCAL;+ const cbm_sem_doc_pos_t outside = CBM_SEM_DOC_POS_OUTSIDE;+ const cbm_sem_diag_family_t prose = CBM_SEM_DIAG_PROSE;+ const cbm_sem_diag_family_t st = CBM_SEM_DIAG_STRUCTURAL;+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, prose, fn, global, 0.199F), 0.0F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, prose, fn, global, 0.20F), 0.24F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, prose, fn, local, 0.30F), 0.28F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, prose, fn, global, 0.40F), 0.45F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, prose, lx, local, 0.20F), 0.275F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, st, fn, local, 0.25F), 0.32F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, st, fn, global, 0.35F), 0.464F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, st, fn, local, 0.90F), 0.567F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, st, lx, local, 0.50F), 0.778F, 0.0);+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, st, lx, local, 0.199F), 0.0F, 0.0);+ /* stored as two decimals: 0.275 -> 0.28, 0.464 -> 0.46, 0.567 -> 0.57 */+ ASSERT_FLOAT_EQ(cbm_sem_p_2dp(cbm_sem_doc_section_p(md, prose, lx, local, 0.5F)), 0.28, 1e-12);+ ASSERT_FLOAT_EQ(cbm_sem_p_2dp(cbm_sem_doc_section_p(md, st, fn, local, 0.35F)), 0.46, 1e-12);+ static const cbm_sem_doc_kind_t KINDS[] = {CBM_SEM_DOC_KIND_FUNCTION, CBM_SEM_DOC_KIND_LOCAL,+ CBM_SEM_DOC_KIND_FILE};+ for (int fam = 0; fam < CBM_SEM_DIAG_COUNT; fam++) {+ for (size_t k = 0; k < sizeof(KINDS) / sizeof(KINDS[0]); k++) {+ for (int pos = 0; pos < CBM_SEM_DOC_POS_COUNT; pos++) {+ float last = 0.0F;+ for (int milli = 0; milli <= 1000; milli++) {+ float s = (float)milli / 1000.0F;+ cbm_sem_doc_pos_t ps = (cbm_sem_doc_pos_t)pos;+ float p =+ cbm_sem_doc_section_p(md, (cbm_sem_diag_family_t)fam, KINDS[k], ps, s);+ ASSERT_TRUE(p >= last);+ last = p;+ bool own = (fam == prose || fam == st) && ((KINDS[k] == fn && pos != outside) ||+ (KINDS[k] == lx && pos == local));+ if (!own) {+ ASSERT_FLOAT_EQ(p, cbm_sem_doc_calibrated_p(md, KINDS[k], ps, s), 0.0);+ }+ ASSERT_FLOAT_EQ(+ cbm_sem_doc_section_p(CBM_SEM_DOC_FMT_RST, (cbm_sem_diag_family_t)fam,+ KINDS[k], ps, s),+ cbm_sem_doc_calibrated_p(CBM_SEM_DOC_FMT_RST, KINDS[k], ps, s), 0.0);+ }+ }+ }+ }+ ASSERT_FLOAT_EQ(cbm_sem_doc_section_p(md, CBM_SEM_DIAG_COUNT, fn, global, 0.25F), 0.0F, 0.0);+ PASS();+}+/* p is stored and shown at two decimals, half up, whatever the float* representation of the judged value (0.225F is 0.22499999...). */TEST(sem_p_two_decimals_half_up) {@@ -841,6 +921,8 @@ SUITE(semantic) {RUN_TEST(sem_admit_best_first_keeps_the_best);RUN_TEST(sem_calibrated_p_bands);RUN_TEST(sem_doc_calibrated_p_bands);+ RUN_TEST(sem_diag_family_by_format_and_kind);+ RUN_TEST(sem_doc_section_p_diagram_families);RUN_TEST(sem_doc_format_by_extension);RUN_TEST(sem_p_two_decimals_half_up);RUN_TEST(sem_json_str_honours_escapes);