A refactored Python implementation of the original uml2semantics tool, updated so that
OWL 2 semantics are used consistently throughout the generated ontology.
This work would not be possible without Henriette Harmse's https://henrietteharmse.com/uml-vs-owl/uml-class-diagram-to-owl-and-sroiq-reference/ and the reference implementation here https://github.com/henrietteharmse/uml2semantics
- Converts UML models (via XMI/TSV) into OWL 2 ontologies
- Preserves UML class, property, and enumeration structure
- Generates OWL 2 class, object property, and data property axioms
- Supports datatype restrictions using proper OWL 2 patterns (DatatypeRestriction, facets)
- Choice patterns (inclusive/exclusive) mapped to union/disjointness
- Pluggable profiles for ISO 20022 and generic UML
- Declarative annotations via
AnnotationProperties.tsv+Annotations.tsv
pip install .or, using pipx:
pipx install .The main entry point is:
uml2semantics [OPTIONS]Supported options (compatible with 0.8.2, extended):
-i, --input PATH- UML/XMI input file-o, --output PATH- Output ontology path (RDF/XML, Turtle, or OWL/XML)-f, --format {rdfxml,turtle,nt,jsonld,trig,n3}- Output serialisation format-b, --base-iri IRI- Base IRI for generated ontology-p, --profile {generic,iso20022}- Mapping profile to apply--imports IRI- Additional ontology IRI to import (repeatable)--no-imports- Disable automatic imports--validate / --no-validate- Turn structural validation on/off--log-level {ERROR,WARNING,INFO,DEBUG}- Logging verbosity--dry-run- Parse and build in memory, but do not write a file--version- Show version information and exit--annotation-properties PATH- TSV defining annotation properties--annotations PATH- TSV of annotation assertions
Example:
uml2semantics -i examples/simple-model.xmi -o examples/simple-model.owl -f turtle -p iso20022from uml2semantics.ontology_builder import build_ontology
from uml2semantics.tsv_loader import load_model
model = load_model(
classes_tsv="examples/Classes.tsv",
attributes_tsv="examples/Attributes.tsv",
datatypes_tsv="examples/Datatypes.tsv",
enums_tsv="examples/Enumerations.tsv",
enum_literals_tsv="examples/EnumerationNamedValues.tsv",
annotation_properties_tsv="examples/AnnotationProperties.tsv",
annotations_tsv="examples/Annotations.tsv",
)
g = build_ontology(
model,
ontology_iri="http://example.org/uml2semantics/demo#",
prefix_str="ex=http://example.org/;rdfs=http://www.w3.org/2000/01/rdf-schema#;dct=http://purl.org/dc/terms/;xsd=http://www.w3.org/2001/XMLSchema#",
)
g.serialize("examples/demo.ttl", format="turtle")AnnotationProperties.tsvcolumns:Curie,Name,DefinitionAnnotations.tsvcolumns:TargetCurie,AnnotationProperty,Value,Language,Datatype
ChoiceOfon a class lists alternative class/attribute tokens.ChoiceSemantics=exclusiveemits anowl:unionOfplus anAllDisjointClassescovering the choice and its members. Blank orinclusiveemits only the union.
BaseDatatypeis required when facets are present; a missing base raises an error to avoid defaulting toxsd:string.
See docs/cli.md and docs/architecture.md for more details.