There isn’t really a simple “not” operator in RDF. Nevertheless, it’s useful, particularly for establishing default values. So what can we do?
Perhaps, but let's not get bogged down in semantics.
The semantics of “not” (more accurately, of “complement”) turn out to be tricky to express in RDF, not just in practice, but in theory as well. To understand why, we have to consider world views. RDF generally subscribes to an “open world” view, it accepts that at any given time, the available statements represent limited knowledge and that there’s more out there somewhere, it just hasn’t been encountered yet.
The semantics of “not” require a closed world view: informally, “not” asks if, in the known universe of information, is it the case that some statement has not been made? Consider the following statements:
Maple trees have green leaves.
Red Maple trees have red leaves.
Oak trees have green leaves.
Elm trees have brown bark.
Cherry trees have edible fruit.
Now ponder the question, “which trees do not have green leaves?” If we take those five statements as the total universe of information, the answer is elm and cherry trees, but anyone who’s seen an elm or cherry tree knows that’s not true.
Nevertheless, it is sometimes useful to be able to express “not,” particularly for establishing default values. So what can we do?
Before continuing, let’s pause to reflect on the fact that we can’t express “not” in RDF any more than we can express “blue, italic text” in XML. An XML document is just a tree of information items and an RDF document is just a collection of statements. We need an application to interpret our XML markup to make some text blue and italic. Similarly, we need an application to interpret the semantics of our RDF statements. In this essay, we use cwm to interpret the RDF.
Let’s work through this with a concrete example. We know that most trees have green leaves, so let’s try to make that the default. Here are our four statements, recast as RDF using N3 notation.
That describes five resources, says they’re each trees as defined by our tree schema, and gives them some descriptive characteristics. We want to find a way to say that if the color of a tree’s leaves is not specified, assume they’re green.
The answer to our “not” question lies in cwm’s
This operator loads an RDF document and returns a formula, a closed set of statements.
Allows us to ask if a particular statement occurs in a given formula.
Allows us to ask if a particular statement does not occur in a given formula.
In other words, these operators allow us to treat a single document as a closed world and that gives the “not” operator something to sink its teeth into.
With these tools, we can construct a rule for cwm to evaluate:
What does this mean?
First, we establish that
Next, we construct a formula from the statements in
At this point,
Our real goal, of course, is to narrow the selection to only
those subjects that do not have a
Finally, we end with an implication. For any subject that is selected,
we give it the property
Now we just have to get cwm to apply our rule:
1cwm --n3 trees.n3 rules.n3 --think --data > output.n3
Our elm and cherry trees have grown green leaves!
Credit where it’s due: several folks on irc://irc.freenode.net/rdfig, particularly Dan Connolly, patiently talked me through this the other day. I think Dan pointed me to the answer once before, but I didn’t grok it at the time.