Semantic Web Reasoning With N3

A simple rule

Notation3 is more than a convenient way to write RDF.
Specifically, it allows us to express rules.

The need for rules

We're already aware that Cindy knows John. In the FOAF sense, knowing someone is assumed reciprocal. So John also knows Cindy.

We could just add that fact to our knowledge base. But that would violate the DRY principle: why add knowledge that's already there?

Instead, we are going to generate this kind of facts automatically.

A first rule

So far, we've only added facts to our knowledge base. We will now add another kind of knowledge: a rule. Maybe you're familiar with these (no worries if you're not):

P implies Q

The above reads “P implies Q”, or in an instructive manner: “if we have P, we also have Q”. Let's express that in N3 with Cindy and John:

@prefix ppl: <http://example.org/people#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

{
    ppl:Cindy foaf:knows ppl:John.
}
=>
{
    ppl:John foaf:knows ppl:Cindy.
}.

Obviously, we're saying here that if Cindy knows John, then John also knows Cindy.
N3 uses braces {} to group triples and a textual arrow => for the implication symbol.
Also, don't forget to end the rule with a period ., just like regular triples.

Next

We execute the rule we just created… online!

References