Conversation
Adds a new KnowledgeGraphDiagram diagram type to the Web Modeling Editor alongside ClassDiagram / ObjectDiagram / GUI / Quantum. Backend: - besser/BUML/metamodel/kg: typed KnowledgeGraph metamodel (KGClass, KGIndividual, KGProperty, KGLiteral, KGBlank, KGEdge, KnowledgeGraph) with getter/setter-validated aggregates. No code builder — KG is in-memory only, intended as the substrate for future KG → ClassDiagram / ObjectDiagram converters. - besser/utilities/owl_to_buml.py: deterministic, offline OWL/RDF parser (rdflib) that classifies each term into one of the five node kinds and turns every triple into a KGEdge. - services/converters: KG diagram processor (JSON → BUML) and converter (BUML → JSON), mirroring the Quantum pair; project converters now register "KnowledgeGraphDiagram" in both directions. - routers/conversion_router.py: new POST /import-owl endpoint behind the same validation stack as existing file uploads. - routers/validation_router.py: no-op KnowledgeGraphDiagram branch so /validate-diagram accepts the new type. Frontend submodule: bumped to the matching commit that ships the Cytoscape-backed KG editor with palette, filterable node list, inspector side panel, connect mode, concentric / fcose / grid layouts, soft/hard limits, double-click neighbor expansion, and Reset layout button. Tests: - tests/BUML/metamodel/kg: metamodel invariants (node types, edge endpoint membership, literal validation). - tests/utilities/web_modeling_editor/backend/test_kg_import_and_round_trip: OWL classification, JSON round-trip identity, /import-owl endpoint + /validate-diagram integration, extension rejection. Dependencies: rdflib>=7.0 added to requirements.txt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This includes a new hook for the conversion process and updates to the generator menu configuration and workspace context.
…uration. Allowed users to export the knowledge graph in OWL (RDF/XML) and Turtle (TTL) formats.
…be opened in a web browser without needing the full application. This allows users to easily share and view the KG outside of the application. The export includes all necessary resources (e.g., CSS, JS) embedded in the HTML file for a standalone experience.
…ersion to B-UML. The user can: accept the recommendations; decline recommendations and fix problems manually; decline recommendations and delete concerned nodes and edges.
…ered disconnected from classes anymore, given that the individual itself is connected to a class.
… their translation to UML+OCL
…erface
Brings the KG interface branch up to date with development (v7.13.0),
which added the BPMN and NN diagram types, the OCL normalization
subsystem, and the Supabase/testgen generators.
Conflicts were all additive registrations of a new diagram type; KG is
now registered alongside NN and BPMN in:
- services/converters/{,buml_to_json/,json_to_buml/}__init__.py
- both project_converter.py section maps
- routers/conversion_router.py
requirements.txt keeps development's bocl==1.0.1 bump alongside the
branch's rdflib/pyshacl additions.
Submodule frontend advances to the corresponding frontend merge
(5e9e950), which relocates the KG feature from packages/webapp2 to
packages/webapp following development's rename of that package.
Known follow-up (not a merge error): development replaced the lenient
regex OCL parser in ocl_parser.py with the real B-OCL/ANTLR parser, and
it rejects 50 of the 127 constraints the KG->UML converter emits
(asSet/intersection/isUnique/Set{} literals, plus invariants naming
association ends that do not exist on the generated class). This makes
tests/BUML/notations/kg_to_buml/test_bibo_regression.py
::test_model_round_trips_through_the_editor fail.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
maurodlt
marked this pull request as draft
August 21, 2026 14:34
The CI lint job runs ruff with F841,F401,F541,F811,E711,E721,E731,E741 over besser/. The KG work introduced 24 violations; development was clean, so the job would have failed on merge. 22 were cleared by `ruff --fix`: unused imports across the kg metamodel, notations, utilities and backend converters, plus eight f-strings without placeholders in preflight.py and a duplicated ConversionError import in conversion_router.py. Two needed a decision: - kg_to_object_diagram.py: `name_to_association_per_pair` was assigned and never read. It is vestigial rather than a dropped code path — link resolution goes through `property_iri_to_association`, falling back to scanning `src_cls.all_association_ends()`. Removed, along with the now unused Tuple import. - object_diagram_converter.py: renamed the ambiguous `lambda l:` sort key to `lambda lk:`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
project_to_json already knew how to read a `# KNOWLEDGE_GRAPH MODEL #`
section, but nothing wrote one: project_to_code classified models into
buckets for domain, object, agent, GUI, quantum, state machine, NN and
BPMN, so a KnowledgeGraph fell through unclassified and was dropped.
Exporting a project containing a KG diagram and re-importing it silently
lost the KG.
Adds kg_model_builder.py, the missing writer, and wires it into
project_to_code beside the quantum block.
Two constraints shaped the builder:
- The output is exec()'d by kg_buml_to_json against a restricted namespace
(builtins limited to set/list/dict/tuple/str/int/float/bool/len/range/
print plus the kg metamodel names), so it emits only literals and
constructor calls, and `set()` rather than a bare `{}` for empty node and
edge sets.
- project_to_code only prepends a numbered header when a project holds more
than one model of a type, so the builder emits its own banner — the same
reason domain_model_builder, agent_model_builder and bpmn_model_builder
emit theirs.
Values are rendered with repr() rather than _escape_python_string: node and
edge metadata carries nested constraint specs from OWL/SHACL import, where
hand-escaping is error-prone and repr is correct by construction. _literal()
restricts what reaches it to JSON-safe types.
Also fixes kg_buml_to_json, which returned kg_to_json's {title, model}
envelope where _convert_section drops the return value straight into a
diagram's `model` key, producing a doubly-nested model. It now returns the
bare model like its siblings; kg_to_json keeps the envelope for the HTTP
endpoints. The bug was unreachable until this commit gave the reader
something to read.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The KnowledgeGraphDiagram branch returned an unconditional pass without inspecting the payload. In the editor this is unreachable — Quality Check on a KG opens the Refine modal instead — but the endpoint is public, and a script or CI check calling it directly got a green light on a graph the consistency checker would reject. It now runs the two checks the modal runs: the static preflight (analyze_kg_for_class_diagram, 22 detectors) and the OWL/SHACL consistency check (pyshacl + owlrl). Each finding is flattened to a single line carrying its code, its human-readable description and the affected node ids. The modal's recommended/skip actions are deliberately not reported: they are interactive choices with no meaning in a validation response. Mapping, matching how the modal gates its Convert button: preflight findings -> errors consistency "violation" -> errors consistency "warning"/"info" -> warnings A malformed KG now surfaces as a conversion error through the existing handler rather than as a false pass. test_import_owl_endpoint_and_validation asserted isValid is True on a fixture that deliberately contains `_:b0 a :Person`; it now asserts the BLANK_NODE_INSTANCE finding that graph should produce. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… models /apply-kg-cleanup was documented as a backward-compatibility alias for /apply-kg-refinement?source=llm, but both endpoints are new on this branch, so there is no released client to stay compatible with, and no frontend caller. Removed. _apply_llm_decisions stays — /apply-kg-refinement uses it. Of its five tests, two duplicated existing /apply-kg-refinement coverage (accepted-class drop, signature mismatch) and are dropped; the three unique cases — skip is a no-op, missing llmIssues rejects, no decisions leaves the graph unchanged — are ported to /apply-kg-refinement with source="llm". The new helper is _llm_refine_payload, since the module already has an unrelated _llm_payload used by the LLM response mock. Also deletes KGResolutionOptionModel, KGIssueModel, KGPreflightResponse and KGResolutionInputModel from models/responses.py. They were referenced nowhere and described the abandoned v1 protocol — severity "blocking"/"advisory", blockingCount, suggestedResolutions — that preflight.py's docstring records as dropped. The endpoint actually returns issueCount / recommendedAction / skipAction, so anyone building a client from these models would have built the wrong one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Converting a whole ABox stops producing a usable diagram once a dataset has more than a few dozen individuals. /kg-to-object-diagram now accepts `rootIndividualIds` and `maxDepth`, and returns only the neighbourhood of the chosen individuals. Scoping happens in scope_abox(), on the KG and before conversion, and touches the ABox only. Every class, property and constraint node survives, so kg_to_class_diagram still sees the complete TBox and the surviving objects keep their types. The two alternatives were worse: pruning the whole graph would strip classes the surviving objects need, and converting everything then filtering the ObjectModel would waste the full conversion and leave dangling Links to clean up. Traversal keeps the roots; individuals reachable over individual-to-individual edges, followed in BOTH directions (an individual pointing at the root is related to it too); and, for each kept individual, its rdf:type edges and literal targets. Those last two are depth-0 attachments and never extend the frontier, so two individuals sharing a literal or a type do not become neighbours through it. maxDepth=None means the full connected component. The endpoint always derives the class diagram from the unscoped graph and passes it in explicitly, rather than letting the converter recompute it from the scoped graph: kg_to_class_diagram reads the ABox when widening multiplicities, so recomputing risks the object model and the referenceDiagramData it resolves against disagreeing. An unknown id, or one naming something other than an individual, is a 400 rather than an empty diagram — otherwise a typo is indistinguishable from a genuinely isolated individual. An ABOX_SCOPED warning reports how many individuals survived, so a small diagram does not read as a failed conversion. Omitting rootIndividualIds converts the whole ABox exactly as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The KG editor now offers a single conversion target, the Class Diagram. Drops kg_to_object_diagram and its ABox scoping, the object-diagram preflight analyzer and its six detectors, the /kg-to-object-diagram endpoint, and the diagramType parameter that selected between the two analyzers on /analyze-kg-for-buml-conversion and /apply-kg-refinement. Also updates the frontend submodule, which drops the matching individual-picker modal and Generate-menu entry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
_h_keep_first_only calls isinstance(e.target, KGLiteral) but the module never imported the name, so skipping a MULTIVALUED_LITERAL issue raised NameError and surfaced to the user as HTTP 500. `from __future__ import annotations` hides this class of defect from every rule in the CI lint selection, so F821 joins it. Two inert hits it flagged are cleared at the same time: a missing Set import in kg_to_rdf and an unimported KGResolution forward reference in kg_to_class_diagram. The mockup_to_buml LLM prompt examples are exempted -- they are few-shot snippets rather than importable modules. Preflight only ever asserted the action *key*, leaving handler bodies untested. Both new tests cover every handler preflight can name, not just this one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…am went It existed solely to serialise the ObjectModel that kg_to_object_diagram produced. Removing it also drops the module's last use of Link and ObjectModel, and with them an import that sat below the logger assignment. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Every other diagram type round-trips at both the project and the single-diagram level; the KG only had the project half. /export-buml had no KnowledgeGraphDiagram branch and fell through to "Unsupported or missing diagram type", and /get-json-model could not detect one -- its content sniffing had no KG keywords, and _entry_is_populated looked only for elements/relationships/pages, never the nodes a KG model carries. Not reachable from the editor today, which guards the single-diagram export behind an Apollon editor instance the Cytoscape KG canvas does not provide, but the API is now symmetric. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
check_kg_consistency is the heaviest thing this backend runs -- pyshacl with OWL2-RL inference takes ~3s on a 555-node ontology, and the OWL upload cap is 5 MB. It ran synchronously inside async handlers, so it blocked every other request for the duration. asyncio.to_thread, as the generators already do. Both call sites now import it lazily too, which keeps pyshacl and owlrl out of the import graph of a backend that never opens a KG. rdflib stays a startup dependency -- it is core to every KG path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The KG branch only updated the model-building guide. Adds the missing pieces: an api_kg reference page for the metamodel, a Knowledge Graph model-types page, and the ten KG endpoints in the backend reference. The kg2buml API page documented only besser.utilities.kg_to_buml, the LLM-assisted path, which shares a name with the new deterministic besser.BUML.notations.kg_to_buml and nothing else. Both are now listed, with a note distinguishing them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Overcome the need for Set() and Sequence() in OCL (which is not available) - Fix date being reserved to BOCL - fix isUnique with no parameters generate during convertion - Fix double quotes to single quates during convertion
maurodlt
marked this pull request as ready for review
September 4, 2026 15:31
ArmenSl
marked this pull request as draft
September 30, 2026 15:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR under development. Not yet ready to be merged
Add KG interface
Functionalities: