480 likes | 694 Views
RDF Schema (RDFS). RDF user communities need to define the vocabularies (terms) to indicate that they are describing specific kinds or classes of resources and use specific properties in describing those resources Convention: A class name begins with an uppercase letter
E N D
RDF Schema (RDFS) • RDF user communities need to define the vocabularies (terms) to indicate that they • are describing specific kinds or classes of resources and • use specific properties in describing those resources • Convention: • A class name begins with an uppercase letter • A property name has an initial lowercase letter • Cf. Dublin Core and Friend Of A Friend • RDF itself has no way to define such application-specific classes and properties • They’re described as an RDF vocabulary, using extensions to RDF provided by RDF Schema (or RDFS)
RDFS provides a type system for RDF • Similar in some ways to the type systems of OO programming languages—e.g.: • Resources can be defined as instances of one or more classes • Classes organized in a hierarchical fashion • But RDF classes and properties are also very different from programming language types • Their descriptions don’t create a straightjacket into which info is forced • Instead, they provide additional info about RDF resources • RDFS facilities themselves are provided in the form of an RDF vocabulary—i.e., as a specialized set of predefined RDF resources with their own special meanings
The resources in the RDFS vocabulary have URIrefs with prefix http://www.w3.org/2000/01/rdf-schema# • Conventionally associated with QName prefix rdfs: • Vocabulary descriptions (schemas) written in RDFS are legal RDF graphs • So RDF software not written to process the RDFS vocabulary can still interpret a schema as a legal RDF graph • But won’t understand the built-in meanings of the RDFS terms
Describing Classes • A class corresponds to the generic concept of a Type or Category • Classes are described using • the RDFS resources rdfs:Classand rdfs:Resource and • the properties rdf:type and rdfs:subClassOf
Example • Organization example.org wants to provide info about kinds of motor vehicles • First needs a class to represent the category of things that are motor vehicles • The resources belonging to a class are its instances • A class is any resource having an rdf:type property whose value is the resource rdfs:Class • So the motor vehicle class is described by • assigning the class a URIref, say ex:MotorVehicle • using ex: to stand for the prefix for URIrefs from example.org's vocabulary, viz., http://www.example.org/schemas/vehicles • describing that resource with an rdf:type property whose value is the resource rdfs:Class • I.e., it would write the RDF statement ex:MotorVehicle rdf:type rdfs:Class . • Property rdf:type indicates that a resource is an instance of a class
Then resource exthings:companyCar is described as a motor vehicle by the RDF statement exthings:companyCar rdf:type ex:MotorVehicle . • The resource rdfs:Class itself has an rdf:type of rdfs:Class • A resource may be an instance of more than one class
After describing class ex:MotorVehicle, example.org describes additional classes for specialized kinds of motor vehicle: ex:Van rdf:type rdfs:Class . ex:Truck rdf:type rdfs:Class . Etc. • That they’re specialized kinds of ex:MotorVehicle is described using the rdfs:subClassOf property—e.g., ex:Van rdfs:subClassOf ex:MotorVehicle . • This means that any instance of class ex:Van is also an instance of class ex:MotorVehicle • So, if exthings:companyVan is an instance of ex:Van, then RDF software written to understand the RDFS vocabulary can infer that also exthings:companyVan is also an instance of ex:MotorVehicle
The rdfs:subClassOf property is transitive—e.g., given ex:Van rdfs:subClassOf ex:MotorVehicle . ex:MiniVan rdfs:subClassOf ex:Van . RDFS defines ex:MiniVan as also being a subclass of ex:MotorVehicle • A class may be a subclass of more than one class • RDFS defines all classes as subclasses of class rdfs:Resource • The instances belonging to all classes are resources • RDFS defines both the subjects and objects of statements using rdfs:subClassOf to be resources of type rdfs:Class • So this information could be inferred • But it’s good practice to provide this info explicitly
The class hierarchy discussed ex:MotorVehicle rdf:type rdfs:Class . ex:PassengerVehicle rdf:type rdfs:Class . ex:Van rdf:type rdfs:Class . ex:Truck rdf:type rdfs:Class . ex:MiniVan rdf:type rdfs:Class . ex:PassengerVehicle rdfs:subClassOf ex:MotorVehicle . ex:Van rdfs:subClassOf ex:MotorVehicle . ex:Truck rdfs:subClassOf ex:MotorVehicle . ex:MiniVan rdfs:subClassOf ex:Van . ex:MiniVan rdfs:subClassOf ex:PassengerVehicle .
In RDF/XML using typed nodes <?xml version="1.0"?> <!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base="http://example.org/schemas/vehicles"> <rdfs:Class rdf:ID="MotorVehicle"/> <rdfs:Class rdf:ID="PassengerVehicle"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="Truck"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="Van"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="MiniVan"> <rdfs:subClassOf rdf:resource="#Van"/> <rdfs:subClassOf rdf:resource="#PassengerVehicle"/> </rdfs:Class> </rdf:RDF>
Note the rdf:ID • To ensure that references to these schema classes are correct even if the schema is relocated, the class descriptions can also include xml:base="http://example.org/schemas/vehicles" • Use of an explicit xml:base declaration is good practice • To refer to these classes in RDF instance data located elsewhere, example.org must identify the classes either • by writing absolute URIrefs, or • by using relative URIrefs together with an appropriate xml:base declaration, or • by using QNames together with an appropriate namespace declaration
E.g., to describe the resource exthings:companyCar as an instance of the class ex:MotorVehicle: <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/schemas/vehicles#" xml:base="http://example.org/things"> <ex:MotorVehicle rdf:ID="companyCar"/> </rdf:RDF> • The QName ex:MotorVehicle when expanded using the namespace declaration becomes the full URIref http://example.org/schemas/vehicles#MotorVehicle • The xml:base declaration is used since a QName can’t be the value of an attribute (here rdf:ID)
Describing Properties • In RDFS, properties are described using • the RDF class rdf:Property, and • the RDFS properties rdfs:domain, rdfs:range, and rdfs:subPropertyOf • All properties in RDF are instances of class rdf:Property • A new property is described by • assigning the property a URIref, and • describing that resource with an rdf:type property whose value is the resource rdf:Property • E.g., exterms:weightInKg rdf:type rdf:Property .
RDF Schema provides vocabulary for describing how properties and classes are intended to be used together • Most important are RDFS properties rdfs:range and rdfs:domain • rdfs:range indicates that the values of a given property are instances of a designated class • E.g., example.org wants to indicate that property ex:author has values that are instances of class ex:Person: ex:Person rdf:type rdfs:Class . ex:author rdf:type rdf:Property . ex:author rdfs:range ex:Person .
A property, ex:hasMother, can have 0, 1, or more range properties • If it has no range property, nothing is said about the values of ex:hasMother • If has 1 range property, e.g., specifying ex:Person as the range, this says that the values of the ex:hasMother property are instances of class ex:Person • If it has > 1 range property, e.g., • 1 specifying ex:Person as its range, and • another specifying ex:Female as its range, this says that the values of the ex:hasMother property are resources that are instances of all of the classes specified as the ranges, • i.e., any value of ex:hasMother is both a ex:Femaleand a ex:Person
rdfs:range can also be used to indicate that the value of a property is given by a typed literal • E.g., to indicate that the ex:age has values from the XML Schema datatype xsd:integer: ex:age rdf:type rdf:Property . ex:age rdfs:range xsd:integer . • This URIref can be used without explicitly stating in the schema that it identifies a datatype • But it’s often useful to explicitly state that a given URIref identifies a datatype • Use the RDFs class rdfs:Datatype xsd:integer rdf:type rdfs:Datatype . • Not a definition of a datatype (in the sense of defining a new one)
No way to define datatypes in RDFS • Datatypes are defined externally to RDF (and to RDFS), and referred to in RDF statements by their URIrefs • This statement just documents the existence of the datatype, and indicates explicitly that it’s being used in this schema
rdfs:domain indicates that a given property applies to a designated class • E.g., to indicate that property ex:author applies to instances of class ex:Book: ex:Book rdf:type rdfs:Class . ex:author rdf:type rdf:Property . ex:author rdfs:domain ex:Book .
A property, exterms:weight, may have 0, 1, or more domain properties • If it has no domain property, nothing is said about the resources that exterms:weight properties may be used with • Any resource could have a exterms:weight property • If it has 1 domain property, e.g., specifying ex:Book as the domain, this says that the exterms:weight property applies to instances of class ex:Book • If it has > 1 domain properties, e.g., • 1 specifying ex:Book as the domain and • another specifying ex:MotorVehicle as the domain, this says that any resource that has a exterms:weight property is an instance of all of the classes specified as the domains, • i.e., any resource that has a exterms:weight property is both a ex:Bookand a ex:MotorVehicle
Extending the Example Vehicle Schema • Add 2 properties: • ex:registeredTo (applies to any ex:MotorVehicle, value is a ex:Person) • ex:rearSeatLegRoom, (for any ex:PassengerVehicle, value is an integer) • Add a new class ex:Person • Explicitly describe datatype xsd:integer as a datatype <rdf:Property rdf:ID="registeredTo"> <rdfs:domain rdf:resource="#MotorVehicle"/> <rdfs:range rdf:resource="#Person"/> </rdf:Property> <rdf:Property rdf:ID="rearSeatLegRoom"> <rdfs:domain rdf:resource="#PassengerVehicle"/> <rdfs:range rdf:resource="&xsd;integer"/> </rdf:Property> <rdfs:Class rdf:ID="Person"/> <rdfs:Datatype rdf:about="&xsd;integer"/>
Predefined property rdfs:subPropertyOf denotes the specialization relationship between 2 properties • E.g., ex:primaryDriver and ex:driver are properties, the former a specialization of the latter ex:driver rdf:type rdf:Property . ex:primaryDriver rdf:type rdf:Property . ex:primaryDriver rdfs:subPropertyOf ex:driver . • The meaning of this rdfs:subPropertyOf relationship: If an instance exstaff:fred is an ex:primaryDriver of the instance ex:companyVan, then exstaff:fred is also an ex:driver of ex:companyVan • A property may be a subproperty of 0, 1, or more properties • All rdfs:range and rdfs:domain properties that apply to a property also apply to its subproperties
In RDF/XML: <rdf:Property rdf:ID="driver"> <rdfs:domain rdf:resource="#MotorVehicle"/> </rdf:Property> <rdf:Property rdf:ID="primaryDriver"> <rdfs:subPropertyOf rdf:resource="#driver"/> </rdf:Property>
The Full Example Vehicle Schema <?xml version="1.0"?> <!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base="http://example.org/schemas/vehicles"> <rdfs:Class rdf:ID="MotorVehicle"/> <rdfs:Class rdf:ID="PassengerVehicle"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="Truck"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class>
<rdfs:Class rdf:ID="Van"> <rdfs:subClassOf rdf:resource="#MotorVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="MiniVan"> <rdfs:subClassOf rdf:resource="#Van"/> <rdfs:subClassOf rdf:resource="#PassengerVehicle"/> </rdfs:Class> <rdfs:Class rdf:ID="Person"/> <rdfs:Datatype rdf:about="&xsd;integer"/> <rdf:Property rdf:ID="registeredTo"> <rdfs:domain rdf:resource="#MotorVehicle"/> <rdfs:range rdf:resource="#Person"/> </rdf:Property>
<rdf:Property rdf:ID="rearSeatLegRoom"> <rdfs:domain rdf:resource="#PassengerVehicle"/> <rdfs:range rdf:resource="&xsd;integer"/> </rdf:Property> <rdf:Property rdf:ID="driver"> <rdfs:domain rdf:resource="#MotorVehicle"/> </rdf:Property> <rdf:Property rdf:ID="primaryDriver"> <rdfs:subPropertyOf rdf:resource="#driver"/> </rdf:Property> </rdf:RDF>
An Instance of ex:PassengerVehicle <?xml version="1.0"?> <!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/schemas/vehicles#" xml:base="http://example.org/things"> <ex:PassengerVehicle rdf:ID="johnSmithsCar"> <ex:registeredTo rdf:resource="http://www.example.org/staffid/85740"/> <ex:rearSeatLegRoom rdf:datatype="&xsd;integer"> 127 </ex:rearSeatLegRoom> <ex:primaryDriver rdf:resource="http://www.example.org/staffid/85740"/> </ex:PassengerVehicle> </rdf:RDF> • Note: ex:PassengerVehicle is a subclass of ex:MotorVehicle • So an ex:registeredTo property can be used in describing this instance of ex:PassengerVehicle
Interpreting RDF Schema Declarations • RDF differs from most programming language (PL) type systems in several ways • One important difference • A PL class has a collection of specific properties • An RDF schema describes properties as applying to specific classes of resources, using domain and range properties • In the PL class description, attribute author is part of the description of class Book • Applies only to instances of class Book • An attribute called author in another class is considered a different attribute
I.e., the scope of an attribute description in PLs is restricted to the class or type in which it is defined • But, in RDF, property descriptions are, by default, independent of class definitions • They have, by default, global scope (but may be restricted using domain specifications) • A benefit of the RDF property-based approach: • It’s easier to extend the use of property definitions to originally unanticipated cases
Another result of the global scope of RDF property descriptions: • Can’t define a given property as having locally-different ranges depending on the class of the resource it’s applied to • E.g., in defining ex:hasParent, we’d like it so humans have human parents, monkeys monkey parents • But, in RDFS, any range defined for a property applies to all uses of the property • Locally-different ranges can be defined in OWL
Another important difference between PL type systems and RDF: • RDF Schema descriptions aren’t necessarily prescriptive like PL type declarations • E.g., suppose a PL declares a class Book with an author attribute having values of type Person • This gives a group of constraints • The language won’t allow the • an instance of Book without an author attribute • an instance of Book with an author attribute that doesn’t have a Person as its value • And, if author is the only attribute for class Book, we can’t have an instance of Book with some other attribute
But RDFS provides schema info as additional descriptions of resources • Doesn’t prescribe how these descriptions should be used by an application • E.g., suppose an RDF schema states that an ex:author property has an rdfs:range of class ex:Person • This is just an RDF statement that RDF statements containing ex:author properties have instances of ex:Person as objects
This schema-supplied info might be used in various ways • One application might interpret this statement as specifying part of a template for RDF data it’s creating • Ensure that any ex:author property has a ex:Person value • I.e., interpret the schema description as a constraint(as a PL does) • Another application might interpret this statement as providing additional info about data it’s receiving— info not explicitly provided in the original data • E.g., suppose it receives some RDF data that includes an ex:author property whose value is a resource of unspecified class • It uses this schema statement to conclude that the resource is an instance of ex:Person
A 3rd application might use the statement for consistency checking • E.g., suppose it receives some RDF data that includes an ex:author property whose value is a resource of class ex:Corporation • It could warn of a possible inconsistency • But it might not be inconsistent after all • E.g., somewhere else there might be a declaration that a corporation is a (legal) person
Depending on how the application interprets the property descriptions, a description of an instance might be considered valid either • without some of the schema-specified properties or • with additional properties • RDF schema statements are always descriptions • They may also be prescriptive • But only if the application interpreting them wants to treat them so
Other Schema Information • See: Dan Brickley and R.V. Guha (eds.), RDF Vocabulary Description Language 1.0: RDF Schema, W3C Recommendation, 2004, http://www.w3.org/TR/rdf-schema/ • rdfs:label is an instance of rdf:Property used to provide a human-readable version of a resource's name • A triple of the form R rdfs:label L states that L is a human readable label for R • rdfs:domain is rdfs:Resource • rdfs:range is rdfs:Literal
rdfs:comment is an instance of rdf:Property used to provide a human-readable description of a resource • A triple of the form: R rdfs:comment L states that L is a human readable description of R • rdfs:domain is rdfs:Resource • rdfs:range is rdfs:Literal
N3 Example @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ex: <http://www.example.org/> . ex:Car a rdfs:Class . ex:foo a ex:Car ; rdfs:label "My car" ; rdfs:comment "I've owned it since 2002." . In RDF/XML <?xml version="1.0"?> <rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:ex="http://www.example.org/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdfs:Class rdf:about="http://www.example.org/Car" /> <ex:Car rdf:about="http://www.example.org/foo"> <rdfs:label>My car</rdfs:label> <rdfs:comment>I've owned it since 2002.</rdfs:comment> </ex:Car> </rdf:RDF>
rdfs:Container is a super-class of the RDF Container classes: rdf:Bag, rdf:Seq, rdf:Alt • rdfs:ContainerMembershipProperty class has as instances the properties rdf:_1, rdf:_2, rdf:_3 , ... • rdfs:member is an instance of rdf:Property that’s a super-property of all the container membership properties • I.e., each container membership property has an rdfs:subPropertyOf relationship to the property rdfs:member
rdfs:seeAlso is an instance of rdf:Property • Used to indicate a resource that might provide additional info about the subject resource • rdfs:isDefinedBy is an instance of rdf:Property • Used to indicate a resource defining the subject resource • May be used to indicate an RDF vocabulary in which a resource is described
N3 Example @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ex: <http://www.example.org/> . ex:Car a rdfs:Class ; rdfs:isDefinedBy <http://www.defs.motorVehicles#Car> . ex:foo a ex:Car ; rdfs:seeAlso <http://www.fredsTowing.com/> . In RDF/XML <?xml version="1.0"?> <rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:ex="http://www.example.org/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdfs:Class rdf:about="http://www.example.org/Car"> <rdfs:isDefinedBy rdf:resource="http://www.defs.motorVehicles#Car" /> </rdfs:Class> <ex:Car rdf:about="http://www.example.org/foo"> <rdfs:seeAlso rdf:resource="http://www.fredsTowing.com/" /> </ex:Car> </rdf:RDF>