The following sample program can be used to determine if two persons directly or indirectly know each other.
The above program can be tested within any Prolog system, with the goal :
/* predicate will be build-in that retrieves foaf:knows from the RDF repository */
knows(a,b).
knows(b,c).
knows(c,d).
knows(x,e).
/* Actual theory */
exists(X) :- knows(X,_).
exists(X) :- knows(_,X).
foaf(X,Y) :- knows(X,Y).
foaf(X,Y) :- knows(Y,X).
foaf(X,Y) :- knows(X,Z), foaf(Z,Y).
friend(X,Y) :- exists(X), exists(Y), foaf(X,Y).
?- friend(a,d).
The above program is the bare bone proof-of-concept. It can be further improved by adding degrees of separation and common linkages of friends separation the two persons.