class RDF::Vocabulary

A {Vocabulary} represents an RDFS or OWL vocabulary.

A {Vocabulary} can also serve as a Domain Specific Language (DSL) for generating an RDF Graph definition for the vocabulary (see {RDF::Vocabulary#to_enum}).

### Defining a vocabulary using the DSL Vocabularies can be defined based on {RDF::Vocabulary} or {RDF::StrictVocabulary} using a simple Domain Specific Language (DSL).

Note that, by default, the prefix associated with the vocabulary for forming and interpreting PNames is created from the class name of the vocabulary. See {_prefix_=} for overriding this at runtime.

The simplest way to generate a DSL representation of a vocabulary is using {RDF::Vocabulary::Writer} given an {RDF::Graph} representation of the vocabulary.

### Vocabularies:

The following vocabularies are pre-defined for your convenience:

Other vocabularies are defined in the [rdf-vocab](rubygems.org/gems/rdf-vocab) gem

@example Using pre-defined RDF vocabularies

include RDF

RDF.type      #=> RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
RDFS.seeAlso  #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
OWL.sameAs    #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
XSD.dateTime  #=> RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")

@example Using ad-hoc RDF vocabularies

foaf = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
foaf.knows    #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
foaf[:name]   #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
foaf['mbox']  #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")

@example Defining a simple vocabulary

EX = Class.new(RDF::StrictVocabulay("http://example/ns#")) do
  # Ontology definition
  ontology :"http://example/ns#",
    label: "The RDF Example Vocablary",
    type: "http://www.w3.org/2002/07/owl#Ontology"

  # Class definitions
  term :Class,
    label: "My Class",
    comment: "Good to use as an example",
    type: "rdfs:Class",
    subClassOf: "http://example/SuperClass",
    "ex:prop": "Some annotation property not having a shortcut"

  # Property definitions
  property :prop,
    comment: "A description of the property",
    label: "property",
    domain: "http://example/ns#Class",
    range: "rdfs:Literal",
    isDefinedBy: %(ex:),
    type: "rdf:Property"
end

@example Method calls are converted to the typical RDF camelcase convention

foaf = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
foaf.family_name    #=> RDF::URI("http://xmlns.com/foaf/0.1/familyName")
owl.same_as         #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
# []-style access is left as is
foaf['family_name'] #=> RDF::URI("http://xmlns.com/foaf/0.1/family_name")
foaf[:family_name]  #=> RDF::URI("http://xmlns.com/foaf/0.1/family_name")

@example Generating RDF from a vocabulary definition

graph = RDF::Graph.new << RDF::RDFS.to_enum
graph.dump(:ntriples)

@see www.w3.org/TR/rdf-sparql-query/#prefNames