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.

Hello World description

Complete file listing (Turtle version)

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.

/helloworld.rdf (The actual file used in the example is in RDF/XML)
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix d2d:  <http://rdfns.org/d2d/> .
@prefix mad:  <http://example.d2dsite.net/d2d/ad/MyArticle#> .

<http://example.d2dsite.net/helloworld>
  a <http://rdfns.org/d2d/Document> ;
  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 <http://example.d2dsite.net/d2d/ad/PersonProfile#PersonProfile> ;

  d2d:hasArticle [
    a <http://example.d2dsite.net/d2d/ad/MyArticle#MyArticle> ;

    mad:header """
      Hello World!
    """^^xsd:string ;

    mad:subheader """
      A basic d2d web document example
    """ ;

    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.
    """ ;

    d2d:hasArticle <http://dbpedia.org/resource/Tim_Berners-Lee> ;

    mad:footer """      
        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>.
    """

  ] .

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.

/d2d/ad/MyArticle.rdf (The actual file used in the example is in RDF/XML)
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix d2d:  <http://rdfns.org/d2d/> .

<http://example.d2dsite.net/d2d/ad/MyArticle#MyArticle>
  a <http://rdfns.org/d2d/ArticleDefinition> ;
  rdfs:label "Basic d2d Article definition for 5 fields." ;

  d2d:hasFieldSpec (
    [
      a d2d:FieldSpecification ;
      d2d:hasFieldType d2d:H4 ;
      d2d:mustSatisfy <http://example.d2dsite.net/d2d/ad/MyArticle#header>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:hasFieldType d2d:H5 ;
      d2d:mustSatisfy <http://example.d2dsite.net/d2d/ad/MyArticle#subheader>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:hasFieldType d2d:Div ;
      d2d:mustSatisfy <http://example.d2dsite.net/d2d/ad/MyArticle#content>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:hasFieldType d2d:Article ;
      d2d:mustSatisfy d2d:hasArticle
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:hasFieldType d2d:I ;
      d2d:mustSatisfy <http://example.d2dsite.net/d2d/ad/MyArticle#footer>
    ]

 ) .

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.

/d2d/ad/PersonProfile.rdf (The actual file used in the example is in RDF/XML)
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix d2d:  <http://rdfns.org/d2d/> .

<http://example.d2dsite.net/d2d/ad/PersonProfile#PersonProfile>
  a <http://rdfns.org/d2d/ArticleDefinition> ;
  d2d:skipOnError "1" ;
  d2d:fitsClass <http://dbpedia.org/ontology/Person> ;
  rdfs:label "D2D Article Defintion for a Person Profile." ;

  d2d:hasFieldSpec (
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:limit "1" ;
      d2d:useLabel "0" ;
      d2d:createLink "0" ;
      d2d:hasFieldType d2d:A ;
      d2d:mustSatisfy foaf:isPrimaryTopicOf
    ]
    [
      a d2d:FieldSpecification ;
      d2d:limit "1" ;
      d2d:language "en" ;
      d2d:hasFieldType d2d:H4 ;
      d2d:mustSatisfy <http://dbpedia.org/property/name> ;
      d2d:hasAlternative <http://dbpedia.org/property/fullName>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:limit "1" ;
      d2d:isOptional "1" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy <http://dbpedia.org/ontology/birthDate> ;
      d2d:hasAlternative <http://dbpedia.org/property/birthDate>, 
                         <http://dbpedia.org/property/dateOfBirth>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:language "en" ;
      d2d:useLabel "1" ;
      d2d:createLink "1" ;
      d2d:limit "1" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy [
        a d2d:TripleSpecification ;
        d2d:hasPredicate <http://dbpedia.org/property/birthPlace> ;
        d2d:hasRole d2d:Content ;
        d2d:mustSatisfy [
          a d2d:TripleSpecification ;
          d2d:hasPredicate <http://dbpedia.org/property/countryCode> ;
          d2d:hasRole d2d:Exclusion
        ]
      ]
    ]
    [
      a d2d:FieldSpecification ;
      d2d:limit "1" ;
      d2d:isOptional "1" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy <http://dbpedia.org/ontology/deathDate> ;
      d2d:hasAlternative <http://dbpedia.org/property/deathDate>, 
                         <http://dbpedia.org/property/dateOfDeath>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:language "en" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy [
        a d2d:TripleSpecification ;
        d2d:hasPredicate <http://dbpedia.org/property/deathPlace> ;
        d2d:hasRole d2d:Content ;
        d2d:hasObjectType <http://dbpedia.org/ontology/Settlement>
      ]
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:limit "1" ;
      d2d:language "en" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy <http://dbpedia.org/property/almaMater>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:limit "1" ;
      d2d:hasFieldType d2d:Img ;
      d2d:mustSatisfy <http://dbpedia.org/ontology/thumbnail>
    ]
    [
      a d2d:FieldSpecification ;
      d2d:isOptional "1" ;
      d2d:language "en" ;
      d2d:hasFieldType d2d:P ;
      d2d:mustSatisfy <http://dbpedia.org/ontology/abstract>
    ]

 ) .

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/.