module DataKitten::PublishingFormats::RDFa
Private Class Methods
supported?(instance)
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 9 def self.supported?(instance) graph = RDF::Graph.load(instance.uri, :format => :rdfa) query = RDF::Query.new({ :dataset => { RDF.type => RDF::Vocabulary.new("http://www.w3.org/ns/dcat#").Dataset } }) query.execute(graph)[0][:dataset].to_s rescue false end
Public Instance Methods
contributors()
click to toggle source
A list of contributors.
@see Dataset#contributors
# File lib/data_kitten/publishing_formats/rdfa.rb, line 104 def contributors [] end
data_title()
click to toggle source
The human-readable title of the dataset.
@see Dataset#data_title
# File lib/data_kitten/publishing_formats/rdfa.rb, line 129 def data_title metadata[dataset_uri][dct.title.to_s][0] rescue nil end
description()
click to toggle source
A brief description of the dataset
@see Dataset#description
# File lib/data_kitten/publishing_formats/rdfa.rb, line 136 def description metadata[dataset_uri][dct.description.to_s][0] rescue nil end
distributions()
click to toggle source
A list of distributions, referred to as resources
by Datapackage
.
# File lib/data_kitten/publishing_formats/rdfa.rb, line 111 def distributions distributions = [] uris = metadata[dataset_uri][dcat.distribution.to_s] uris.each do |distribution_uri| distribution = { :title => first_value( distribution_uri, RDF::DC.title ), :accessURL => first_value( distribution_uri, dcat.accessURL ) } distributions << Distribution.new(self, dcat_resource: distribution) end return distributions rescue [] end
issued()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 166 def issued date = first_value(dataset_uri, RDF::DC.issued) || first_value(dataset_uri, RDF::DC.created) if date return Date.parse( date ) end return nil end
keywords()
click to toggle source
Keywords for the dataset
@see Dataset#keywords
# File lib/data_kitten/publishing_formats/rdfa.rb, line 143 def keywords keywords = [] metadata[dataset_uri][dcat.keyword.to_s].each do |k| keywords << k end rescue [] end
licenses()
click to toggle source
A list of licenses.
@see Dataset#licenses
# File lib/data_kitten/publishing_formats/rdfa.rb, line 86 def licenses licenses = [] uris = metadata[dataset_uri][RDF::DC.license.to_s] if uris.nil? [] else uris.each do |license_uri| licenses << License.new(:uri => license_uri, :name => first_value( license_uri, RDF::DC.title )) end return licenses end rescue => e [] end
maintainers()
click to toggle source
A list of maintainers.
@see Dataset#maintainers
# File lib/data_kitten/publishing_formats/rdfa.rb, line 35 def maintainers [] end
modified()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 175 def modified date = first_value(dataset_uri, RDF::DC.modified) if date return Date.parse( date ) end return nil end
publishers()
click to toggle source
A list of publishers.
@see Dataset#publishers
# File lib/data_kitten/publishing_formats/rdfa.rb, line 42 def publishers publishers = [] uris = metadata[dataset_uri][RDF::DC.publisher.to_s] uris.each do |publisher_uri| publishers << Agent.new(:name => first_value( publisher_uri, RDF::FOAF.name ), :homepage => first_value( publisher_uri, RDF::FOAF.homepage ), :mbox => first_value( publisher_uri, RDF::FOAF.mbox )) end return publishers rescue [] end
publishing_format()
click to toggle source
The publishing format for the dataset. @return [Symbol] :rdfa
@see Dataset#publishing_format
# File lib/data_kitten/publishing_formats/rdfa.rb, line 28 def publishing_format :rdfa end
rights()
click to toggle source
The rights statment for the data
@see Dataset#rights
# File lib/data_kitten/publishing_formats/rdfa.rb, line 58 def rights rights_uri = metadata[dataset_uri][RDF::DC.rights.to_s][0] if !metadata[rights_uri] return Rights.new(:uri => rights_uri) else return Rights.new(:uri => uri, :dataLicense => first_value( rights_uri, odrs.dataLicense ), :contentLicense => first_value( rights_uri, odrs.contentLicense ), :copyrightNotice => first_value( rights_uri, odrs.copyrightNotice ), :attributionURL => first_value( rights_uri, odrs.attributionURL ), :attributionText => first_value( rights_uri, odrs.attributionText ), :copyrightHolder => first_value( rights_uri, odrs.copyrightHolder ), :databaseRightHolder => first_value( rights_uri, odrs.databaseRightHolder ), :copyrightYear => first_value( rights_uri, odrs.copyrightYear ), :databaseRightYear => first_value( rights_uri, odrs.databaseRightYear ), :copyrightStatement => first_value( rights_uri, odrs.copyrightStatement ), :databaseRightStatement => first_value( rights_uri, odrs.databaseRightStatement ) ) end rescue => e #puts e #puts e.backtrace nil end
sources()
click to toggle source
Where the data is sourced from
@see Dataset#sources
# File lib/data_kitten/publishing_formats/rdfa.rb, line 155 def sources [] end
update_frequency()
click to toggle source
How frequently the data is updated.
# File lib/data_kitten/publishing_formats/rdfa.rb, line 162 def update_frequency first_value( dataset_uri, dcat.accrualPeriodicity ) end
Private Instance Methods
dataset_uri()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 209 def dataset_uri query = RDF::Query.new({ :dataset => { RDF.type => dcat.Dataset } }) query.execute(graph)[0][:dataset].to_s end
dcat()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 219 def dcat RDF::Vocabulary.new("http://www.w3.org/ns/dcat#") end
dct()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 223 def dct RDF::Vocabulary.new("http://purl.org/dc/terms/") end
first_value(resource, property, default=nil)
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 189 def first_value(resource, property, default=nil) if metadata[resource] && metadata[resource][property.to_s] return metadata[resource][property.to_s][0] end return default end
graph()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 185 def graph @graph ||= RDF::Graph.load(uri, :format => :rdfa) end
metadata()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 196 def metadata @metadata ||= {} # This is UGLY, and exists solely to make getting data out of the graph easier. We will probably change this later graph.triples.each do |triple| @metadata[triple[0].to_s] ||= {} @metadata[triple[0].to_s][triple[1].to_s] ||= [] @metadata[triple[0].to_s][triple[1].to_s] << triple[2].to_s unless @metadata[triple[0].to_s][triple[1].to_s].include? triple[2].to_s end return @metadata end
odrs()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 227 def odrs RDF::Vocabulary.new("http://schema.theodi.org/odrs#") end
void()
click to toggle source
# File lib/data_kitten/publishing_formats/rdfa.rb, line 231 def void RDF::Vocabulary.new("http://rdfs.org/ns/void#") end