# Enumerate all the predicates with their counts under the condition that their subject and object belong to:c1 and a locally-undeclared class, respectively. SELECT?p (COUNT(?p) AS?rc) WHERE.
I have a SPARQL query like this
Suppose now I want to specify the type of
NoorNoor?type
as being either prefix:type1
or prefix:type2
; how should this be done?8,6793232 gold badges113113 silver badges224224 bronze badges
3 Answers
Much faster than the
FILTER IN
function is the use of BINDINGS
. I would highly recommend using something along the lines of the following query rather than the FILTER(?type IN (wo:Kingdon, wo:Phylum)
. Using
chrkiBINDINGS
allows the SPARQL engine to limit results as it is being processed rather than returning all results before filtering them. This makes returning the results much faster.4,88244 gold badges2525 silver badges4747 bronze badges
BigDataBillBigDataBill
You could use
UNION
e.g.Note the use of
a
which is a SPARQL keyword that may be used in the predicate position and corresponds to the RDF type URI http://www.w3.org/1999/02/22-rdf-syntax-ns#type
There are other ways to do this such as using
FILTER
clauses with various expressions:- Series of
?type = prefix:type1
combined with the conditional or operator||
?type IN (prefix:type1, prefix:type2)
Or you could use a
VALUES
clause to specify the options for ?type
These may be better if your query is more complex and you don't want to duplicate much of the query onto both sides of the
RobVRobVUNION
or have more that two possibilites to consider.23.4k99 gold badges6666 silver badges109109 bronze badges
You could do it using the FILTER syntax, like this:
Please note that I cannot guarantee efficiency, as I do not know if the the filtering will apply after all the results will be returned or not.
Pantelis NatsiavasPantelis Natsiavas4,20711 gold badge1212 silver badges2727 bronze badges
Not the answer you're looking for? Browse other questions tagged rdfsparql or ask your own question.
Status | Published |
---|---|
Year started | 1998; 21 years ago |
Editors | Dan Brickley, Ramanathan V. Guha |
Base standards | RDF |
Related standards | OWL |
Domain | Semantic Web |
Abbreviation | RDFS |
Website | RDF Schema |
RDF Schema (Resource Description Framework Schema, variously abbreviated as RDFS, RDF(S), RDF-S, or RDF/S) is a set of classes with certain properties using the RDF extensible knowledge representation data model, providing basic elements for the description of ontologies, otherwise called RDF vocabularies, intended to structure RDF resources. These resources can be saved in a triplestore to reach them with the query language SPARQL.
The first version[1][2] was published by the World-Wide Web Consortium (W3C) in April 1998, and the final[3]W3C recommendation was released in February 2004. Many RDFS components are included in the more expressive Web Ontology Language (OWL).
- 1Main RDFS constructs
Main RDFS constructs[edit]
RDFS constructs are the RDFS classes, associated properties and utility properties built on the limited vocabulary of RDF.
Classes[edit]
- rdfs:Resource is the class of everything. All things described by RDF are resources.
- rdfs:Class declares a resource as a class for other resources.
A typical example of an rdfs:Class is foaf:Person in the Friend of a Friend (FOAF) vocabulary.[4] An instance of foaf:Person is a resource that is linked to the class foaf:Person using the rdf:typeproperty, such as in the following formal expression of the natural-language sentence : 'John is a Person'.
ex:John rdf:type foaf:Person
The definition of rdfs:Class is recursive: rdfs:Class is the class of classes, and so it is an instance of itself.
rdfs:Class rdf:type rdfs:Class
The other classes described by the RDF and RDFS specifications are:
- rdfs:Literal – literal values such as strings and integers. Property values such as textual strings are examples of RDF literals. Literals may be plain or typed.
- rdfs:Datatype – the class of datatypes. rdfs:Datatype is both an instance of and a subclass of rdfs:Class. Each instance of rdfs:Datatype is a subclass of rdfs:Literal.
- rdf:XMLLiteral – the class of XML literal values. rdf:XMLLiteral is an instance of rdfs:Datatype (and thus a subclass of rdfs:Literal).
- rdf:Property – the class of properties.
Properties[edit]
Properties are instances of the class rdf:Property and describe a relation between subject resources and object resources. When used as such a property is a predicate (see also RDF: reification).
- rdfs:domain of an rdf:Property declares the class of the subject in a triple whose predicate is that property.
- rdfs:range of an rdf:Property declares the class or datatype of the object in a triple whose predicate is that property.
For example, the following declarations are used to express that the property ex:employer relates a subject, which is of type foaf:Person, to an object, which is of type foaf:Organization:
ex:employer rdfs:domain foaf:Person
ex:employer rdfs:range foaf:Organization
Given the previous two declarations, from the triple:
ex:John ex:employer ex:CompanyX
can be inferred (resp. follows) that ex:John is a foaf:Person, and ex:CompanyX is a foaf:Organization.
- rdf:type is a property used to state that a resource is an instance of a class. A commonly accepted qname for this property is 'a'.[5]
- rdfs:subClassOf allows declaration of hierarchies of classes.[6]
For example, the following declares that 'Every Person is an Agent':
foaf:Person rdfs:subClassOf foaf:Agent
Hierarchies of classes support inheritance of a property domain and range (see definitions in next section) from a class to its subclasses.
- rdfs:subPropertyOf is an instance of rdf:Property that is used to state that all resources related by one property are also related by another.
- rdfs:label is an instance of rdf:Property that may be used to provide a human-readable version of a resource's name.
- rdfs:comment is an instance of rdf:Property that may be used to provide a human-readable description of a resource.
Utility properties[edit]
- rdfs:seeAlso is an instance of rdf:Property that is used to indicate a resource that might provide additional information about the subject resource.
- rdfs:isDefinedBy is an instance of rdf:Property that is used to indicate a resource defining the subject resource. This property may be used to indicate an RDF vocabulary in which a resource is described.
Examples of RDF Vocabularies[edit]
Popular RDF vocabularies represented in RDFS include:[6]
- FOAF: the source of the page http://xmlns.com/foaf/spec/ is RDFS written in the RDFa syntax.
- Dublin Core: RDFS source is available in several syntaxes[7]
- Schema.org: the source of the page http://schema.org/docs/schema_org_rdfa.html is RDFS written in the RDFa syntax.
- Simple Knowledge Organization System (SKOS): http://www.w3.org/TR/skos-reference/skos-xl.rdf is an OWL ontology for the SKOS vocabulary that uses the OWL RDF/XML syntax and hence makes use of a number of classes and properties from RDFS.
RDFS entailment[edit]
An entailment regime defines by using RDFS (or OWL, etc.) not only which entailment relation is used, but also which queries and graphs are well-formed for the regime. The RDFS entailment is a standard entailment relation in the semantic web.
For example, the following declares that 'Dog1 is an animal','Cat1 is a cat', 'Zoos host animals' and 'Zoo1 hosts the Cat2' :
But this graph is not well formed because the system can not guess that a cat is an animal. We have to add 'Cats are animals' to do a well-formed graph with :
Here is a correct example:
In English | The graph |
---|---|
| |
RDF/turtle |
If your triplestore (or RDF database) implements the regime entailment of RDF and RDFS, the SPARQL query as follows (the keyword 'a' is equivalent to rdf:type in SPARQL):
Gives the following result with cat1 in it because the Cat's type inherits of Animal's type:
animal |
---|
<http://example.org/dog1> |
<http://example.org/cat1> |
<http://example.org/cat2> |
See also[edit]
- SPARQL Query Language for RDF
- Platform for Internet Content Selection (PICS)
References[edit]
- ^RDFS first version
- ^'XML and Semantic Web W3C Standards Timeline'(PDF). 2012-02-04. Archived from the original(PDF) on April 24, 2013.
- ^Final W3C recommendation
- ^FOAF Vocabulary Specification 0.99 by Dan Brickley, Libby Miller.
- ^DuCharme, Bob (2011). Learning SPARQL. Sebastopol, California, United States: O'Reilly Media. p. 36. ISBN9781449306595.
- ^ abW3C RDF 1.1 Primer by Guus Schreiber and Yves Raimond
- ^DCMI term declarations represented in RDF schema language, Dublin Core Metadata Initiative
External links[edit]
- SPARQL2XQuery Map OWL-RDF/S ontologies and XML Schemas. Transform XML Schema to OWL.
Retrieved from 'https://en.wikipedia.org/w/index.php?title=RDF_Schema&oldid=888145371'