SPARQL Conversion Examples

From Bibframe2Schema.org Community Group

Below are listed some examples of SPARQL scripts for [Bibframe] entity types/properties to be enhanced with Schema.org types/properties. They assume that the source Bibframe entities have been created by the Library of Congress marc2bibframe2 XSLT conversion from MARC to BIBFRAME RDF.

Each example is a self-contained SPARQL INSERT statement that would add the relevant Schema.org types/properties to an RDF store containing Bibframe 2.0 encoded entities. By replacing the INSERT verb with CONSTRUCT the created Schema.org triples would be returned as the results of the query.

(Examples supplied by Richard Wallis)

Comments are invited

All examples assume the following prefix assignments:

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix bf: <http://id.loc.gov/ontologies/bibframe/> 
prefix bfc: <http://id.loc.gov/ontologies/bflc/> 
prefix mads: <http://www.loc.gov/mads/rdf/v1#> 
prefix schema: <http://schema.org/> 


Event

INSERT {
  ?s a schema:Event.
}
where {
  ?s a bf:Event.
}

Person

INSERT {
  ?s a schema:Person;
     schema:name ?nam 
}
where {
    ?s a bf:Person;
         rdfs:label ?nam
}

Organization

INSERT {
  ?s a schema:Organization;
     schema:name ?nam 
}
where {
    ?s a bf:Organization;
         rdfs:label ?nam
}

Place

INSERT {
  ?s a schema:Place.
}
where {
    ?s a bf:Place .
}

Work

INSERT {
  ?w a schema:CreativeWork;
        a ?plustype;
        schema:name ?t.
}
where {
    ?w a bf:Work;
        bf:title/rdfs:label ?t.
   OPTIONAL{
      ?w a bf:Audio.
      BIND(schema:AudioObject as ?plustype).
    }
  OPTIONAL{
    ?w a bf:Dataset.
    BIND(schema:Dataset as ?plustype).
    }
  OPTIONAL{
    ?w a bf:Cartography.
    BIND(schema:Map as ?plustype).
    }
  OPTIONAL{
    ?w a bf:StillImage.
    BIND(schema:ImageObject as ?plustype).
    }
  OPTIONAL{
    ?w a bf:MovingImage.
    BIND(schema:VideoObject as ?plustype).
    }
  OPTIONAL{
    ?w a bf:Multimedia.
    BIND(schema:MediaObject as ?plustype).
    }
}

Instance

INSERT{
  ?s a schema:CreativeWork ;
     a schema:Product;
     a ?plustype;
       schema:exampleOfWork ?w;
       schema:name ?title;
       schema:contributor ?contributor;
       schema:creator ?creator;
       schema:description ?description;
       schema:inLanguage ?language.
       
  ?w schema:workExample ?s.
}
where {
        ?s a bf:Instance;
           bf:instanceOf ?w.
        OPTIONAL{
            ?w bf:title/rdfs:label ?title .
        }
       OPTIONAL{
            ?w bf:contributor ?contributor .
        }
        OPTIONAL{
            ?w bf:creator ?creator .
        }
        OPTIONAL{
            ?w bf:description ?description .
        }
        OPTIONAL{
            ?w bf:genre ?genre .
        }
        OPTIONAL{
            ?w bf:language ?language .
        }
       OPTIONAL{
          ?w a bf:Audio.
          BIND(schema:AudioObject as ?plustype).
       }
     OPTIONAL{
         ?w a bf:Dataset.
         BIND(schema:Dataset as ?plustype).
      }
     OPTIONAL{
         ?w a bf:Cartography.
         BIND(schema:Map as ?plustype).
     }
    OPTIONAL{
        ?w a bf:StillImage.
        BIND(schema:ImageObject as ?plustype).
     }
    OPTIONAL{
        ?w a bf:MovingImage.
       BIND(schema:VideoObject as ?plustype).
     }
    OPTIONAL{
       ?w a bf:Multimedia.
       BIND(schema:MediaObject as ?plustype).
    }
}

Item

INSERT {
  ?it a schema:CreativeWork ;
     a schema:Product;
     a ?plustype;
       schema:exampleOfWork ?in;
       schema:name ?title;
       schema:contributor ?contributor;
       schema:creator ?creator;
       schema:description ?description;
       schema:inLanguage ?language;
       schema:sku ?shel.
       
  ?in schema:workExample ?it.
}
where {
    
        ?it a bf:Item;
           bf:itemOf ?in;
           bf:itemOf/bf:instanceOf ?w.
        OPTIONAL{
            ?it bf:shelfMark/rdfs:label ?contributor. 
        }
        OPTIONAL{
            ?w bf:title/rdfs:label ?title .
        }
        OPTIONAL{
            ?w bf:contributor ?contributor .
        }
        OPTIONAL{
            ?w bf:creator ?creator .
        }
        OPTIONAL{
            ?w bf:description ?description .
        }
        OPTIONAL{
            ?w bf:genre ?genre .
        }
        OPTIONAL{
            ?w bf:language ?language .
        }
       OPTIONAL{
          ?w a bf:Audio.
          BIND(schema:AudioObject as ?plustype).
       }
     OPTIONAL{
         ?w a bf:Dataset.
         BIND(schema:Dataset as ?plustype).
      }
     OPTIONAL{
         ?w a bf:Cartography.
         BIND(schema:Map as ?plustype).
     }
    OPTIONAL{
        ?w a bf:StillImage.
        BIND(schema:ImageObject as ?plustype).
     }
    OPTIONAL{
        ?w a bf:MovingImage.
       BIND(schema:VideoObject as ?plustype).
     }
    OPTIONAL{
       ?w a bf:Multimedia.
       BIND(schema:MediaObject as ?plustype).
    }
}

Language

INSERT {
  ?s a schema:Language;
      schema:name ?nam.
} WHERE {
    {
      ?s a bf:Language;
          bf:identifiedBy/rdf:value ?nam.
    }
}

Meeting

INSERT {
  ?s a schema:Event;
     a schema:Organization .
}
where {
    ?s a bf:Meeting .
}

Genre

INSERT {
  ?s a schema:DefinedTerm ;
      schema:name ?n;
      schema:inDefinedTermSet ?set.
}
WHERE {
    ?s a bf:Genre;
        rdfs:label ?n;
        bf:source/bf:code ?set.
}

Publication

INSERT {
  ?ent schema:publication ?ev;
       schema:publisher ?ag.
  ?ev a schema:PublicationEvent;
        schema:location ?pl;
        schema:startDate ?dt;
    	schema:publishedBy ?ag.
} where {
    ?ent ?p ?ev.
    ?ev a bf:Publication;
         bf:date ?dt;
         bf:place ?pl;
         bf:agent ?ag.
}

adience

INSERT {
  ?s schema:adience ?a.
  ?a a schema:Audience;
       schema:audienceType ?au.
} WHERE {
  ?s bf:intendedAudience ?a;
       rdfs:label ?au.
}

identifier

INSERT {
      _:id a schema:PropertyValue;
             schema:value ?id;
             schema:propertyID ?so.
      ?s schema:identifier _:id;
         schema:isbn ?isbn;
         schema:issn ?issn.
    
    } WHERE {
            {
                ?s  bf:adminMetadata/bf:identifiedBy ?ident.
            } UNION {
                ?s bf:identifiedBy ?ident.
            }
            ?ident rdf:value ?id;
                   bf:source/rdfs:label ?so.
      		OPTIONAL{
                ?ident a bf:Isbn;
                       rdf:value ?isbn.
            }
            OPTIONAL{
                ?ident a bf:Issn;
                       rdf:value ?issn.
            }
    }

award

INSERT {
  ?s schema:award ?o .
}
where {
  ?s bf:awards ?o .
}

contributor

INSERT {
  ?s schema:contributor ?a .
}
WHERE {
  ?s bf:contribution/bf:agent ?a.
}
  1. TODO Need to use role to identify authors etc.


subject

INSERT {
  ?s schema:about ?o .
}
WHERE {
  ?s bf:subject ?o .
}
  1. TODO add ?o schema:subjectOf ?s where ?o is a URI


title

INSERT { 
    ?s schema:name ?o . 
} 
WHERE {
    ?s bf:title/rdfs:label ?o . 
}

Metadata (special case)

INSERT {
  ?s schema:sdPublisher {name or uri of publishing organization}.
  ?s schema:sdLicense {URI of licence - eg. <https://creativecommons.org/publicdomain/zero/1.0/>}.
  ?s schema:sdDatePublished {date of conversion/processing}.
}
where {
  ?s a ?type.
  FILTER (?type IN (bf:Work, bf:Instance, bf:Item, bf:Person, bf:Organization, bf:Place, bf:Event))
}