# Basic graph queries The core predicates of the RDF library are rdf/3 and rdf/4, using the signature below. - rdf(?Subject, ?Predicate, ?Object) - rdf(?Subject, ?Predicate, ?Object, ?Graph) If you run the query below by pressing the *play* button SWISH generates a table. The solutions are _rendered_ using the RDF renderer, which renders - *Resources* in abbreviated form, trying to show the _prefix_, followed by a label. The label is formed from `rdfs:label`, `skos:prefLabel`, etc., eventually using the _local name_. By *hovering over the top-left corner* of the result, the raw Prolog form can be requested, which is a Prolog atom representing the full IRI. - *Literals* are represented in their _Turtle_ representation. Again, by hovering and selecting _Prolog term_, you can view the actual representation. Clicking a resource will open the ClioPatria _Local View_ on the resource.
rdf(S, P, O).
The rdf/3 and rdf/4 relations are _pure_, i.e., they behave completely logically if part of their arguments is instantiated. So, to get the `rdf:type` triples, we can use the query below. The _RDF_ prefix is defined using rdf_register_prefix/2, and therefore we can also abbreviate the query:
rdf(S, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', O).
rdf(S, rdf:type, O).
## Combining graph queries Basic rdf/3 patterns can be combined using Prolog's logical connectives. The basic ones are `A,B` for conjuction (join) and `A;B` for disjunction (union). SPARQL OPTIONAL is realised by the *->/2 control structure: `(A *-> true ; true)`, where the first `true` is excuted if `A` has no solutions and the second for each solution of `A`. Here is a simple pattern, expressing instances of a direct subclass of `foaf:Agent`. Note that we need to put single quotes around `Agent` to turn it into an _atom_; identifiers that start with a capital letter are Prolog _variables_.
rdf(S, rdf:type, C), rdf(C, rdfs:subClassOf, foaf:'Agent').
## Naming queries One of the nicest things about using Prolog instead of e.g., SPARQL is that we can _name_ a pattern. E.g.,
foaf_agent_of_type(Agent, Type) :- rdf(Agent, rdf:type, Type), rdf(Type, rdfs:subClassOf, foaf:'Agent').
foaf_agent_of_type(Agent, Type).