Hello World

Description of the basic 'Hello World' example

Basics

A simple example of how the d2d vocabulary can be used.

Hello World!

A basic d2d example

To illustrate the use of the d2d vocabulary, we have included a basic 'Hello World' example. The resulting document can be found here:

http://example.d2dsite.net/helloworld

This example consists of one 'document' containing two 'articles'; One article created specifically for the example, and one article that consists of a DBpedia resource that is used as such. It uses two 'Article Definitions' that define the composition of the articles. The DBpedia based article is a nested article and as such is part of the other artile, being one of its fields. This minimal example does not use any 'Rendering Definitions' or templates; if these are not specified, the various content fields are rendered in the tag corresponding with the field type indicated in the article definition, while further styling can be done using CSS. The use of templates for more specialized forms of rendering is discussed at our project website.

Serialisation Formats

Data 2 Documents supports multiple RDF serialisations

The examples on this site are listed as RDF/XML, because it allows for a more recognisable document structure. This allows editors to add and edit content even when the true technical details are not fully understood, in a copy-paste-compare fashion. However, the d2d reference implementation also supports other RDF serialisation formats such as N-Triples, Turtle Terse RDF Triple Language, Notation3 and JSON-LD.

Klik here to view the Hello World explanation with listings in the Turtle serialisation format.

Hello World description

Complete file listing

Below is a listing of the file 'helloworld.rdf' that contains the d2d:Document resource and the root article for the document. The rdf:about property is set to the empty string, which results in the document URL being used as URI for the document resource. The root article of the document (<mad:MyArticle>) is a blank node, since it is only used for this document. However, a reference to an external resource could also be used. Because in this case the article node is an instance of the article definition, the rendering engine can determine its type automatically. According to its definition, which is listed below the document, the root article contains five 'fields' of which one can be used for nested articles. The nested article is an external resource, i.e. the DBpedia URI for Tim Berners-Lee. The rendering engine knows how to process this resource due to the preferred article definition that is indicated at the top of the document. That article definition specifies the types of resources that it fits; in this case resources of type http://dbpedia.org/ontology/Person. It is also possible to indicate preferred definitions on lower levels in the document hierarchy, in order to process resources of the same type differently at several places in the document.

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:d2d="http://rdfns.org/d2d/"
         xmlns:mad="http://example.d2dsite.net/d2d/ad/MyArticle#" >

 <d2d:Document rdf:about="" d2d:title="Data 2 Documents - Hello World!"
                            d2d:charset="utf-8"
                            d2d:generator="Data 2 Documents"
                            d2d:keywords="d2d RDF Linked Data Document"
                            d2d:hasStyle="/css/hello_world.css" >

  <d2d:prefArticleDef rdf:resource="/d2d/ad/PersonProfile#PersonProfile" />
             
  <d2d:hasArticle>
   <mad:MyArticle>  <!-- 'mad' is short for My Article Definition -->

    <mad:header rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
      Hello World!
    </mad:header>

    <mad:subheader>
      A basic d2d web document example
    </mad:subheader>

    <mad:content>
      This example consists of one 'document' containing two 'articles'; One article 
      created specifically for this example (this text), and one article that 
      consists of a DBpedia resource that is used as such. It uses two 'Article 
      Definitions' that define the composition of the articles. The DBpedia based 
      article is a nested article and as such is part of this artile, being one of 
      its fields.
    </mad:content>

    <d2d:hasArticle rdf:resource="http://dbpedia.org/resource/Tim_Berners-Lee" />

    <mad:footer>
      <![CDATA[
        This example was created by Niels Ockeloen on April 30<sup>th</sup> 
        2016 and is described <a href="http://example.d2dsite.net/helloworldinfo" 
        target="_blank">here</a>.
      ]]>
    </mad:footer>

   </mad:MyArticle>
  </d2d:hasArticle>

 </d2d:Document>
</rdf:RDF>

Below is a listing of the article definition for the root article (MyArticle.rdf). It contains five 'Field Specifications' that define which property of the article resource is to be used to gather content for the field. It also specifies the type of field, e.g. a paragraph of text or a nested article. These field types correspond with the HTML5 semantics. Though not included in this basic example, it is also possible to specify more elaborated property paths and specify constrains such as object or data type, the required absence of a certain property, or alternative triple specifications.

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:d2d="http://rdfns.org/d2d/"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >

 <d2d:ArticleDefinition rdf:about="#MyArticle">
  <rdfs:label>Basic d2d Article definition for 5 fields.</rdfs:label>
  <d2d:hasFieldSpec rdf:parseType="Collection">

   <d2d:FieldSpecification>
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/H4" /> 
    <d2d:mustSatisfy rdf:resource="#header" /> <!--Shorthand triple spec-->
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/H5" />
    <d2d:mustSatisfy rdf:resource="#subheader" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification>
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/Div" />
    <d2d:mustSatisfy rdf:resource="#content" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/Article" />
    <d2d:mustSatisfy rdf:resource="http://rdfns.org/d2d/hasArticle" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/I" />
    <d2d:mustSatisfy rdf:resource="#footer" />
   </d2d:FieldSpecification>

  </d2d:hasFieldSpec>
 </d2d:ArticleDefinition>

</rdf:RDF>

The article definition for the nested article is listed below. It is constructed in a similar fashion, using DBpedia property IRIs. Apart from the required property, options are specified such as the required language, whether a field is optional, if a label or link should be used/created in case of a resource property and the maximum number of values that is desired in case multiple values are specified. Furthermore, alternatives are specified for cases where multiple predicate names are used interchangeably within DBpedia, as is the case for birth dates.

<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:d2d="http://rdfns.org/d2d/"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >

 <d2d:ArticleDefinition rdf:about="#PersonProfile" d2d:skipOnError="1">
  <d2d:fitsClass rdf:resource="http://dbpedia.org/ontology/Person" />
  <rdfs:label>D2D Article Defintion for a Person Profile.</rdfs:label>
  <d2d:hasFieldSpec rdf:parseType="Collection">

   <d2d:FieldSpecification d2d:isOptional="1" d2d:limit="1" 
                           d2d:useLabel="0" d2d:createLink="0">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/A" />
    <d2d:mustSatisfy rdf:resource="http://xmlns.com/foaf/0.1/isPrimaryTopicOf" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:limit="1" d2d:language="en">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/H4" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/property/name" />
    <!-- Alternative (in shorthand notation) -->
    <d2d:hasAlternative rdf:resource="http://dbpedia.org/property/fullName" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:limit="1" d2d:isOptional="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/ontology/birthDate" />
    <d2d:hasAlternative rdf:resource="http://dbpedia.org/property/birthDate" />
    <d2d:hasAlternative rdf:resource="http://dbpedia.org/property/dateOfBirth" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1" d2d:language="en" 
                           d2d:useLabel="1" d2d:createLink="1" d2d:limit="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" /> 
    <d2d:mustSatisfy>
     <d2d:TripleSpecification>
      <d2d:hasPredicate rdf:resource="http://dbpedia.org/property/birthPlace" />
      <d2d:hasRole rdf:resource="http://rdfns.org/d2d/Content" />
      <d2d:mustSatisfy>
       <d2d:TripleSpecification>
        <d2d:hasPredicate rdf:resource="http://dbpedia.org/property/countryCode" />
        <d2d:hasRole rdf:resource="http://rdfns.org/d2d/Exclusion" />
       </d2d:TripleSpecification>
      </d2d:mustSatisfy>
     </d2d:TripleSpecification>
    </d2d:mustSatisfy>
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:limit="1" d2d:isOptional="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/ontology/deathDate" />
    <d2d:hasAlternative rdf:resource="http://dbpedia.org/property/deathDate" />
    <d2d:hasAlternative rdf:resource="http://dbpedia.org/property/dateOfDeath" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1" d2d:language="en">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" /> 
    <d2d:mustSatisfy>
     <d2d:TripleSpecification>
      <d2d:hasPredicate rdf:resource="http://dbpedia.org/property/deathPlace" />
      <d2d:hasRole rdf:resource="http://rdfns.org/d2d/Content" />
      <d2d:hasObjectType rdf:resource="http://dbpedia.org/ontology/Settlement" />
     </d2d:TripleSpecification>
    </d2d:mustSatisfy>
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1" d2d:limit="1" d2d:language="en">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/property/almaMater" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1" d2d:limit="1">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/Img" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/ontology/thumbnail" />
   </d2d:FieldSpecification>

   <d2d:FieldSpecification d2d:isOptional="1" d2d:language="en">
    <d2d:hasFieldType rdf:resource="http://rdfns.org/d2d/P" />
    <d2d:mustSatisfy rdf:resource="http://dbpedia.org/ontology/abstract" />
   </d2d:FieldSpecification>

  </d2d:hasFieldSpec>
 </d2d:ArticleDefinition>

</rdf:RDF>

The three listings above are all that is needed for the Hello World example, of which the latter two, the article definitions, can be re-used for other documents. For example, the PersonProfile definition is also used in this example. The examples here are expressed in XML/RDF to allow for a recognizable document structure, but other RDF serialisation formats such as N3 or Turtle can also be used.

All files of this example, as well as the files of other examples, can be found at:
http://example.d2dsite.net/browser/.