Add a Vocabulary for DC Elements
Learn how to avoid managing URI strings using vocabularies, and follow step-by-step instructions to add a vocabulary for DC elements.
We'll cover the following
Build an RDF Graph
We’ll switch gears here and see how we can build up an RDF graph using RDF.ex
rather than writing out the RDF explicitly. We’ll aim to generate the book graph using the semantic RDF form we already discussed.
URI strings
One of the challenges to working with RDF is managing URI strings. We need to deal with node names ourselves for instance data because these generally use an application-specific naming. But for edges and node labels, we don’t want to be dealing with URI strings every time we add a property or a class name.
We can make use of one particular aspect of RDF.ex
—its support for RDF vocabularies. The distribution ships with five vocabularies (RDF, RDFS, OWL, SKOS, and XSD) already included. These vocabularies, however, provide terms from RDF schema languages for general data structuring rather than for capturing any specific semantics. But we can easily add in new vocabularies with their own semantics.
DC elements vocabulary
Let’s look first at the core DC elements vocabulary because this is very simple: 15 properties only. In fact, with this small number, we can easily list these out by hand. We’ll create a module called RDFGraph.Vocab
in the lib/rdf_graph/vocab.ex
location. We add a use RDF.Vocabulary.Namespace
declaration and also a defvocab
definition block for DC:
Get hands-on with 1200+ tech skills courses.