README-work
Raku UML::Translators
In brief
This repository is for a Raku package for the translations of code into Unified Modeling Language (UML) specifications and vice versa.
Currently, the package only translates Object-Oriented Programming (OOP) Raku code into:
The Domain Specific Language (DSL) of PlantUML
Argument specification of the UML class diagram function UMLClassGraph of the Mathematica / Wolfram Language (WL) package [AAp1]
Future plans
A fully fledged version of this package would translate:
C++, Java, Kotlin, or Raku code into UML specs
UML specs into C++, Java, Kotlin, or Raku code
Currently, only UML specs are generated to PlantUML's DSL and a much poorer WL DSL. Ideally, subsequent versions of this package would be able to use UML specifications encoded in XML and JSON.
Installation
From zef's ecosystem
zef install UML::Translators
From GitHub
zef install https://github.com/antononcube/Raku-UML-Translators.git
Command Line Interface (CLI)
> to-uml-spec --help
Usage:
to-uml-spec [--type=<Str>] [-I=<Str>] [--attributes] [--methods] [--conciseGrammarClasses] [--format=<Str>] <packageName> -- Make a UML diagram for a specified package.
<packageName> Package name.
--type=<Str> Type of the UML diagram. [default: 'class']
-I=<Str> Using include path to find libraries. [default: '']
--attributes Should the class attributes be included in the UML diagrams or not? [default: True]
--methods Should the class methods be included in the UML diagrams or not? [default: True]
--conciseGrammarClasses Should grammar classes be shortened or not? [default: True]
--format=<Str> Format of the output, one of 'Plant', 'PlantUML', 'WL', 'WLUML', or 'Whatever'. [default: 'PlantUML']
Usage examples
Using the script to-uml-spec:
to-uml-spec --/methods --/attributes "Lingua::NumericWordForms"
With this shell command we generate a Plant UML spec for the package "Chemistry::Stoichiometry" and create the UML diagram image with a local PlantUML JAR file (downloaded from [PUML1]):
to-uml-spec --/methods --/attributes 'Chemistry::Stoichiometry' | java -jar ~/Downloads/plantuml-1.2022.5.jar -pipe -tjpg > /tmp/myuml.jpg
Raku session
UML for ad hoc classes
use UML::Translators;
module MyPackageClass {
role A { method a1 {} }
class B does A { has $!b0; method b1 {} }
class C does A is B { has $!c0; method c1 {} }
}
to-uml-spec('MyPackageClass')
UML for packages
Get PlantUML code for the package 'Chemistry::Stoichiometry':
say to-uml-spec('Chemistry::Stoichiometry'):!methods:!attributes
Get WL UML graph spec for the package [AAp1]:
say to-uml-spec('Chemistry::Stoichiometry', format => 'wluml')
Classes in a name space
Get the classes of a name space:
.say for get-namespace-classes( 'ML::TriesWithFrequencies' ).map({ $_ ~~ Str ?? $_ !! $_.^name }).sort
References
[AA1] Anton Antonov, et al., "Find programmatically all classes, grammars, and roles in a Raku package", (2021), StackOverflow.
[AAp1] Anton Antonov, "UML Diagram Generation Mathematica package", (2016), MathematicaForPrediction at GitHub/antononcube.
[ES1] Eugene Steinberg and Vojtech Krasa, PlantUML integration IntelliJ IDEA plugin, JetBrains Plugins Marketplace.
[GV1] graphviz.org.
[PUML1] plantuml.com.
[PUML2] PlantUML online demo server.
[UMLD1] uml-diagrams.org.
[WK1] Wikipedia entry, "Graphviz".
[WK2] Wikipedia entry, "PlantUML".
[WK3] Wikipedia entry, "Unified Modeling Language".