[Eugenia] Negation [message #759019] |
Fri, 25 November 2011 10:40  |
Eclipse User |
|
|
|
What i have to do if i want to negate the following constraint ?
context Claim {
constraint UniqueRoot {
check : Claim.all.one(as|as.claims.includes(self))
message : 'Could not find the root node. Maybe its not unique ?'
}
}
I want that constraint to show up, if there is not exactly one Claim, that NOT appear in the relation "claims".
For now the constraint show up, if there is not exactly one Claim, that APPEAR in the relation "claims".
Can i use the NOT Operator on the regular expression in any way ?
|
|
|
|
Re: [Eugenia] Negation [message #759097 is a reply to message #759070] |
Sat, 26 November 2011 06:05   |
Eclipse User |
|
|
|
[quote title=Snakebyte wrote on Fri, 25 November 2011 17:05]This is the corresponding model :
@namespace(uri="argumentmodel", prefix="argumentmodel")
@gmf(foo="bar")
package ArgumentModel;
@gmf.diagram(onefile="false")
class TrustCase {
val Claim[*] valclaims;
}
@gmf.node(label="name", phantom="true")
class Claim {
attr String name;
attr String description;
@gmf.link(foo="bar")
val ArgumentStrategy[*] connectarg;
}
@gmf.node(label="name", phantom="true")
class ArgumentStrategy {
attr String description;
attr String name;
@gmf.link(incoming="true")
ref Claim [*] claims;
}
Quote:
What i want is to ensure that there is only one Claim not referenced by any ArgumentStrategy.
The metamodel doesn't adapt very nicely to that query, but I guess this could work (untested, sorry!):
context TrustCase {
check {
var referencedClaims :=
ArgumentStrategy.all.collect(a|a.claims).flatten().asSet();
var claimsNotReferenced := self.valclaims.excludingAll(referencedClaims);
return claimsNotReferenced.size() = 1;
}
message : 'Exactly one claim should not be referenced by any ArgumentStrategy'
}
Basically, we compute the set of every claim referenced in some ArgumentStrategy, and then subtract it from the set of all claims. Another way would be to go claim by claim, checking that it's not referenced from any argument strategy and then adding it to a set. However, I think that might be more expensive (and harder to read).
Edit: you're trying to validate a property of your entire model, and not just of one Claim or one ArgumentStrategy. You'll probably need to use the model entity that represents the whole model as context in EVL in those cases.
[Updated on: Sat, 26 November 2011 12:01] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04312 seconds