PlantUML basic example - plantuml

I'm evaluating if PlantUML can be a good alternative to GraphViz.
It's promoted as "intuitive" but honestly the very first example from the homepage is already confusing.
Why does the following create "Bob" and "Alice" twice?
I'm seeing 2 nodes in the text, and 4 in the output.
Also, the arrow doesn't go between the nodes, but between relations between duplications of the nodes.
Bob->Alice : hello
It makes zero sense to me.
What is the meaning of this example, and what would be a more trivial example with just 2 nodes and an arrow between them?

I see you have fallen for the classical trap of "The first page of the manual is not representative of the tool".(1)
Besides various UML diagrams (like the sequence diagram you encounered), PlantUML has support for various other Software development related formats (such as archimate, Block diagram, bpmn, c4, Computer network diagrams, erd, gantt chart, Mind maps, and wbd), as well as visualization of json and yaml files.
In fact, it even understands Graphviz syntax!(2)
Because of all of this, "intuitive" doesn't happen until you have some basic knowledge of PlantUML.
So back to your issue... What you are seeing isn't what you think it is.
What is that?
Relating things to Graphviz, instead of this:
digraph d {
Bob -> Alice : hello
}
You are actually seeing this:(3)
#startuml
digraph sequenceDiagramExample {
bobHead [ label="Bob" pos="0,1.5!" shape="record" ];
bobPoint0 [ pos="0,0.75!" shape="point" width="0" ]
bobFoot [ label="Bob" pos="0,0!" shape="record" ];
aliceHead [ label="Alice" pos="1,1.5!" shape="record" ];
alicePoint0 [ pos="1,0.75!" shape="point" width="0" ]
aliceFoot [ label="Alice" pos="1,0!" shape="record" ];
bobHead -> bobPoint0 -> bobFoot [ dir="none" style="dashed" ]
aliceHead -> alicePoint0 -> aliceFoot [ dir="none" style="dashed" ]
bobPoint0 -> alicePoint0 [ label="hello" labelloc="c" style="solid" ]
}
#enduml
Gimme an example!
What an example with just two nodes and an arrow between them looks like depends on the kind of graph chosen...
What you have to remember is that, with Graphviz, you have to apply all meaning to a diagram yourself. With PlantUML, the meaning is provided by PlantUML for you. All you need to do is tell PlantUML what you mean.
With a few basic pointers, this becomes intuitive quite quickly. You just need to know what kind of diagram you want to draw before starting...
As you can see from the examples below, PlantUML is a very powerful tool to add to your software developer toolbelt.
I hope the examples will help to make things more intuitive, and that your first misstep won't keep you from exploring PlantUML further!
Activity
#startuml
:Alice;
:Bob;
#enduml
Archimate
#startuml
archimate #Application Alice
archimate #Business Bob
Alice -> Bob
#enduml
Class
#startuml
Alice -|> Bob: Hello
#enduml
Component
#startuml
[Alice] -> [Bob]: Hello
#enduml
Deployment
#startuml
folder Alice
file Bob
Alice -> Bob: Hello
#enduml
Ditaa
#startuml
ditaa
+-------+ +-----+
| | hello | |
| Alice +------>| Bob |
| | | |
+-------+ +-----+
#enduml
Gantt
#startgantt
[Alice]->[Bob]
#endgantt
JSON
#startjson
{
"Alice": ["Bob"]
}
#endjson
MindMap
#startmindmap
+ Alice
++ Bob
#endmindmap
Network
#startuml
nwdiag {
network hello {
Alice;
Bob;
}
}
#enduml
Object
#startuml
object Alice
object Bob
Alice -> Bob
#enduml
Sequence
#startuml
Bob -> Alice : hello
#enduml
State
#startuml
[*] -> Alice
Alice -> Bob: hello
Bob -> [*]
#enduml
Timing
#startuml
concise Hello
0 is Alice
+100 is Bob
#enduml
Use Case
#startuml
:Alice: -> :Bob: : Hello
#enduml
WBS
#startwbs
+ Alice
++ Bob
#endwbs
Footnotes
It's not realy a classic, I just made that up. But it is something that commonly happens.
Reference the manual here: https://plantuml.com/dot
Rendered in neato not dot, see https://stackoverflow.com/a/53470455/153049

They are not “four nodes”, they are top and bottom headers for every participant in the sequence. This is useful for readability in larger sequence diagrams, see some examples here https://plantuml.com/en/sequence-diagram
You can style your diagram to comply with strict UML with
skinparam style strictuml
Full code
#startuml
skinparam style strictuml
Bob -> Alice : hello
Alice -> Bob : ok
#enduml

Related

Nested alt in plantUML Syntax

How to add nested alt flow in plant UML ?
I have a use case in which I want nested alt. Similar to below
When I add it only innermost alt is displayed. Need help in finding right syntax for it
alt [condition 1]
do some steps
alt [condition 2]
do some steps
else [condition 2 Not true] so do nothing
else [condition 2 Not true] so do nothing
You have to add an end statement to close the alt block.
As a side note: You do not need to add the square brackets in your alt statements. PlantUML renders those itself.
alt condition 1
bob -> alice
alt condition 2
bob -> alice
else condition 3
bob -> alice
end
else condition 4
bob -> alice
end

How to mix different plantuml diagram type elements?

I want to have deployment and sequence stuff in one and the same rendered plantuml picture. So I tried the following but it does not work, the rendering shows the sequence stuff for A, B and C as deployment.
How can I force rendering for "A->B" and "B->C" as sequence diagram stuff?
#startuml
file main.c
note right: I want to have description text here
A -> B : main()
note left : program\nentry function
B -> C : load()
note left : another important function
#enduml
I think you need to add your note later:
#startuml
title file main.c
A -> B : main()
note left : program\nentry function
B -> C : load()
note left : another important function
note right: I want to have description text here
#enduml
Result:

Inconsistent classification of individuals in Protege 4.3

I have been studying Protege and I have a question. I added an individual with name aaa in ontology "people.owl" which I downloaded from the internet.
I set type assertion as:
sheep and hasCC value 200,
where hasCC is data property.
Then, in class animal I created two classes: hhh and lll.
I set hhh as equivalent and there wrote:
animal and (hasCC some decimal[>= 150])
For lll I set:
animal and (hasCC some decimal[< 250])
When I run HermiT reasoner I see that the individual aaa is classified in both lll and hhh classes.
But when I set lll and hhh classes to be disjoint and run the reasoner the classes are not classified in the class "Nothing" as, for example, the class "mad_cow". I get a message:
"Your ontology is inconsistent which means that the OWL reasoner will no longer be able to provide any useful information about the ontology." After clicking the button "Explain" I get:
Could you say, why lll and hhh classes cannot be classified as Nothing?
What should I correct to let lll and hhh classes to be classified as Nothing?
Thank you!
"Your ontology is inconsistent which means that the OWL reasoner will no longer be able to provide any useful information about the ontology."
Isn't this saying it all already? You complain that the reasoner is not doing something but the reasoner explicitly tells you that it is not able to provide any useful information! Make your ontology consistent, then you can expect something from the reasoner.
In any case, you cannot expect a class that contains an instance (here the classes hhh and lll both must contain instance aaa) to be equivalent to Nothing. Nothing precisely means "the class that does not have any instance".

Plantuml class diagram with multiple children: Any way to bifurcate the arrow?

My attempt:
Animal <|-- Cat
Animal <|-- Dog
Result:
┌────────┐
│ Animal │
└────────┘
Δ Δ
│ │
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘
That is not how a class diagram is supposed to look like.
This is:
┌────────┐
│ Animal │
└────────┘
Δ
┌──┴───┐
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘
As suggested, I asked if this is possible on the PlantUML forum.
You can do something like this:
#startuml
class Animal
together {
class Dog
class Cat
}
Animal <|-- Cat
Dog -- (Animal, Cat)
#enduml
There's skinparam groupInheritance 2 which will serve your purpose, although it doesn't work with skinparam linetype ortho as one might expect. Alas, GraphViz is the rendering engine, so that has limitations.
#startuml
skinparam style strictuml
hide empty members
skinparam groupInheritance 2
class Animal
class Cat extends Animal
class Dog extends Animal
#enduml
An interesting thing to do in plantUML but "this is not how class diagram is supposed to look like" is not correct (to my knowledge, at least).
The notation is clear for inheritance/generalization but whether you join the lines before the arrow or have separate lines with separate arrows is a matter of visual preference/making it easier to understand:
Try to sketch the image on top of that wiki you linked with distinct arrow from each child to it's parent, it will be much more messy
Scroll down a bit on wiki to https://en.wikipedia.org/wiki/Class_diagram#Generalization/Inheritance

How to use java #repeatable with cucumber

I have different string for same businesses logic in cucumber.
So I trying to get a way to tag a multiple Gherkins string with one function.
I am trying with below but I m not able understand to formulate it with cucumber
Using #Repeatable while mainaining support for Java 7
Example:
Scenario Outline: Looking up the definition of fruits
the user is on the Wikionary home page for fruits
When the user looks up the definition of the word <name>
Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
Examples:
| name |
| pear |
Scenario Outline: Looking up the definition of orange
Given the user is on the Wikionary home page for orange
When the user looks up the definition of the word <name>
Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
Examples:
| name |
| pear |
In above statement Given is different but the business function is same.
How I can tag this with repeatable with java.
Or any other way except concatenate string with |
Any work around will be helpful!!!
Have a step definition like this - It should match any similar step and also non-capturing
#Given("^the user is on the Wikionary home page for (?:\\w+)$")
public void given() {
System.out.println("givn");
}
#Given("^should go to given (?:,*) $")
#Given("^should go to given - (.*?) - (?:,*) $")
#Given("^should go to given - (.*?) - (.*?) - (?:,*) $")
This will take in different parameters. But this will completely ruin the gherkin step text, make it total gibberish. Would be very uncomfortable using this.
You can write the Step Definition Java code only once for above both scenario it will automatically run the same step definition code for the two different scenarios:
Scenario Outline: Looking up the definition of fruits
Given the user is on the Wikionary home page for "fruits"
Scenario Outline: Looking up the definition of orange
Given the user is on the Wikionary home page for "orange"
For above #Given statement you can write only one step defination method it will automatically execute for both scenario as per the different parameters configuration:
#Given("the user is on the Wikionary home page for (.*))
public void given(String fruitName)
{
System.out.println(fruitName);
}

Resources