Skip to main content

One task in five languages

This document was generated using AI assistance

Content may include inaccuracies, outdated information, or technical errors. Users are advised to cross-check critical information before implementation.

The same question written in every language. In every example self is an ArchiMate element, and in SPARQL it is ?self.

Does the element carry a name

LanguageExpression
AQLself.name <> null and self.name.trim().size() > 0
OCLself.name <> null and self.name.size() > 0
EOLself.name.isDefined() and self.name.trim() <> ''
CELself.name != ""
SPARQLASK { ?self archimate:Nameable.name ?name .
     FILTER(STRLEN(STR(?name)) > 0) }

Is the element connected to anything

LanguageExpression
AQLself.incomingRelationships->notEmpty() or self.outgoingRelationships->notEmpty()
OCLself.incomingRelationships->notEmpty() or self.outgoingRelationships->notEmpty()
EOLnot self.incomingRelationships.isEmpty() or not self.outgoingRelationships.isEmpty()
CELself.incomingRelationships.size() > 0 || self.outgoingRelationships.size() > 0
SPARQLASK {
  { ?r archimate:ArchimateRelationship.source ?self }
  UNION
  { ?r archimate:ArchimateRelationship.target ?self }
}

The names of everything the element points at

LanguageExpression
AQLself.outgoingRelationships->collect(r | r.target.name)
OCLself.outgoingRelationships->collect(r | r.target.name)
EOLself.outgoingRelationships.collect(r | r.target.name)
CELself.outgoingRelationships.map(r, r.target.name)
SPARQLSELECT ?name WHERE {
  ?r archimate:ArchimateRelationship.source ?self ;
     archimate:ArchimateRelationship.target ?target .
  ?target archimate:Nameable.name ?name .
}

Collection operations are written with -> in AQL and OCL, with a dot in EOL, and as macros in CEL; SPARQL returns rows instead of a collection.

Is the owner property set exactly once

LanguageExpression
AQLself.properties->select(p | p.key = 'owner')->size() = 1
OCLself.properties->select(p | p.key = 'owner')->size() = 1
EOLself.properties.select(p | p.key = 'owner').size() = 1
CELself.properties.exists_one(p, p.key == "owner")
SPARQLASK {
  { SELECT (COUNT(?p) AS ?owners) WHERE {
      ?self archimate:Properties.properties ?p .
      ?p archimate:Property.key "owner" .
  } }
  FILTER(?owners = 1)
}

Note the equality operators: = in AQL, OCL and EOL, == in CEL, and a pattern match in SPARQL.

Trim a stray space out of the name

Only two languages change a model, so this task has two answers.

LanguageExpression
EOLself.name = self.name.trim();
SPARQLDELETE { GRAPH ?g { ?self archimate:Nameable.name ?name } }
INSERT { GRAPH ?g { ?self archimate:Nameable.name ?trimmed } }
WHERE { GRAPH ?g { ?self archimate:Nameable.name ?name }
         BIND(REPLACE(REPLACE(STR(?name), "^\\s+", ""),
                     "\\s+$", "") AS ?trimmed) }

In the update, ?g is bound to the graph of the model along with ?self.

The same body written in AQL, OCL or CEL is rejected where a change is required, and never touches the model where it is accepted.