Nodetyping Models
Nodetyping models represent the type that RDF nodes have in a graph. RDF nodes can be typed either as a Literal, or as a URI Reference. Nodes without a type are Blank Nodes.
Nodetyping models are used to constrain results to be literals or URI references. These types have the URIs of http://www.w3.org/2000/01/rdf-schema#Literal
and http://mulgara.org/mulgara#uriReference
. Generally, the standard set of aliases should be in place, and these URIs and can be referred to in the aliased forms: rdfs:Literal
and mulgara:uriReference
.
The standard set of aliases is defined by the alias
command:
alias <http://mulgara.org/mulgara#> as mulgara;
alias <http://www.w3.org/1999/02/22-rdf-syntax-ns#> as rdf;
alias <http://www.w3.org/2000/01/rdf-schema#> as rdfs;
Like datatyping models, nodetyping models are generally read-only. You do not insert statements into them as you do with standard or full-text models. Conceptually, they contain statements about the datatypes of nodes, such as:
[ <http://namespace/ns#value> <rdf:type> <mulgara:uriReference> ]
Nodetyping models also contain statements describing the type for all literals. While statements about literals are not strictly legal RDF, the statements do not exist in any RDF model, and are only used to constrain variables. An example of this kind of statement is:
[ 'This is a string' <rdf:type> <rdfs:Literal> ]
Creating Nodetyping Models
Use the create
command with the optional type argument of http://mulgara.org/mulgara#TypeModel
in addition to the model name. There should never be a need to create more than one nodetyping model per server.
For example, to create the nodetyping model #type
:
create <rmi://mysite.com/server1#type> <http://mulgara.org/mulgara#TypeModel>;
The http://mulgara.org/mulgara#TypeModel
URI can be referred to in the aliased form <mulgara:TypeModel>
, when the mulgara
alias is active:
alias <http://mulgara.org/mulgara#> as mulgara;
Querying Nodetyping Models
Querying nodetyping models is much the same as for normal Mulgara models. Nodetyping models contain type statements for all URI reference and literal nodes on the server (not just for a single model).
To use a nodetyping model in a query, make sure you have a node type model available. See the Creating Nodetyping Models section for more information. Then compose a constraint with the <rdf:type>
property, and direct it at the node type model with an in
specifier.
The example queries shown assume that the standard aliases are in place, as follows:
alias <http://mulgara.org/mulgara#> as mulgara;
alias <http://www.w3.org/1999/02/22-rdf-syntax-ns#> as rdf;
alias <http://www.w3.org/2000/01/rdf-schema#> as rdfs;
The first example uses the nodetyping model rmi://mysite.com/server1#type
to return all subjects with the type URI Reference.
select $subject from <rmi://mysite.com/server1#data>
where $subject $predicate $object
and $subject <rdf:type> <mulgara:uriReference> in <rmi://mysite.com/server1#type>;
This returns:
[ http://qqq.com/staff/corky ]
[ http://qqq.com/staff/ppan ]
[ http://qqq.com/staff/spiderman ]
[ http://qqq.com/staff/superman ]
The next example finds all predicates which are not used to refer to blank nodes. That is, the object node is either a literal or a URI reference.
select $predicate from <rmi://mysite.com/server1#data>
where $subject $predicate $object
and ($object <rdf:type> <mulgara:uriReference> in <rmi://mysite.com/server1#type>
or $object <rdf:type> <rdfs:Literal> in <rmi://mysite.com/server1#type>);
This returns:
[ http://www.w3.org/1999/02/22-rdf-syntax-ns#value ]
[ http://www.w3.org/2001/vcard-rdf/3.0#FN ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Family ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Given ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Other ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Prefix ]
[ http://www.w3.org/2001/vcard-rdf/3.0#BDAY ]
[ http://www.w3.org/2001/vcard-rdf/3.0#TITLE ]
[ http://www.w3.org/2001/vcard-rdf/3.0#ROLE ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Street ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Locality ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Pcode ]
[ http://www.w3.org/2001/vcard-rdf/3.0#Country ]
[ http://www.w3.org/2001/vcard-rdf/3.0#NOTE ]
The next example does not return any data as it looks for all statements that have a literal as the subject. This is not valid RDF so no data matches the constraints.
select $subject from <rmi://mysite.com/server1#data>
where $subject $predicate $object
and $subject <rdf:type> <rdfs:Literal> in <rmi://mysite.com/server1#type>);
The next example finds a list of all literals in the system. Note that the model in the from
clause is overridden and not used in the query.
select $l from <rmi://mysite.com/server1#data>
where $l <rdf:type> <rdfs:Literal> in <rmi://mysite.com/server1#type>;
The final example lists the literals found in a single model. It is only necessary to join the variable to the object position in the constraint, as literals can only appear in this position in RDF.
select $object from <rmi://mysite.com/server1#data>
where $subject $predicate $object
and $object <rdf:type> <rdfs:Literal> in <rmi://mysite.com/server1#type>;
The first 10 lines of this 48 line result are:
[ Corky Crystal ]
[ Crystal ]
[ Corky ]
[ Jacky ]
[ Dr ]
[ 1980-01-01 ]
[ Computer Officer Class 3 ]
[ Programmer ]
[ +61 7 555 5555 ]
[ corky@qqq.com ]