You probably need to get your intended semantics straightened out a little bit more.
From what I gather, you want isFriendWith
at least to be symmetric, i.e. when isFriendWith(bob, alice)
then also isFriendWith(alice, bob)
.
Also, if you want to have friendsAll
to have any meaning, isFriendWith
cannot be transitive. This would also capture the natural meaning, as a friend of my friend is not necessarily my friend.
To elaborate: If isFriendWith
where symmetric and transitive every friend of bob
would automatically also be a friend of all of bob's friends (because isFriendWith(bob, alice)
implies isFriendWith(alice, bob)
. From there on, with any isFriendWith(bob, carol)
transitivity implies that isFriendWith(alice, carol)
. So if isFriendWith
is symmetric and transitive, you get the clique automatically.
But as stated, this is probably not, what you want.
As for formulating this in SWRL, let's give it a try, shall we?
friendsAll
is most likely reflexive, i.e. let's just assume everybody is his/her own friend. Now, we need an recursive rule that extends this set while still fulfilling the condition: "In this set, everybody is everybody's friend".
To include bob's friends, you would need to be able to quantify over isFriendWith
and check if that any candidate friend of bob
is also a friend of all other friends of bob
. Since you cannot nest quantifiers in SWRL, I'm more or less sure, you cannot express that algorithm in the rule language alone. However, I maybe wrong here and there is a neat little trick hidden inside the semantics. It is not one that I know of, however and the need for quantifier nesting in the direct formulation leaves me believing that it is not possible.
It basically boils down to a well-known graph-theoretic problem: given a starting point bob
friendsAll
is the largest subset of bob
's friends such that every everbody in the group is friends with everyone else, i.e. bob's Maximal Clique.