Class: Fsp::Proxies::FairDataPoint
- Inherits:
-
Object
- Object
- Fsp::Proxies::FairDataPoint
- Defined in:
- lib/fsp/proxies.rb
Overview
Your code goes hereā¦
Instance Attribute Summary collapse
-
#cite_as ⇒ Object
Returns the value of attribute cite_as.
-
#describedby ⇒ Object
Returns the value of attribute describedby.
-
#html ⇒ Object
Returns the value of attribute html.
-
#items ⇒ Object
Returns the value of attribute items.
-
#types ⇒ Object
Returns the value of attribute types.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #get_cite_as(repo:) ⇒ Object
- #get_described_by(repo:) ⇒ Object
- #get_items(repo:) ⇒ Object
- #get_types(repo:) ⇒ Object
-
#initialize(url:) ⇒ FairDataPoint
constructor
A new instance of FairDataPoint.
- #proxy ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(url:) ⇒ FairDataPoint
Returns a new instance of FairDataPoint.
18 19 20 21 22 23 24 25 |
# File 'lib/fsp/proxies.rb', line 18 def initialize(url:) @url = url @cite_as = '' @describedby = '' @items = '' @html = '' @types = '' end |
Instance Attribute Details
#cite_as ⇒ Object
Returns the value of attribute cite_as.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def cite_as @cite_as end |
#describedby ⇒ Object
Returns the value of attribute describedby.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def describedby @describedby end |
#html ⇒ Object
Returns the value of attribute html.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def html @html end |
#items ⇒ Object
Returns the value of attribute items.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def items @items end |
#types ⇒ Object
Returns the value of attribute types.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def types @types end |
#url ⇒ Object
Returns the value of attribute url.
16 17 18 |
# File 'lib/fsp/proxies.rb', line 16 def url @url end |
Instance Method Details
#get_cite_as(repo:) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fsp/proxies.rb', line 53 def get_cite_as(repo:) query = SPARQL.parse(" PREFIX dcterms: <http://purl.org/dc/terms/> SELECT * WHERE { ?s a <http://purl.org/spar/datacite/Identifier> . ?s dcterms:identifier ?id }") id = '' repo.query(query) do |result| warn result.inspect id = result[:id].to_s end link = LinkHeader.new([[id, [%w[rel cite-as]]]]).to_html warn "LINK: #{link}" link end |
#get_described_by(repo:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fsp/proxies.rb', line 71 def get_described_by(repo:) query = SPARQL.parse(" PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX ldp: <http://www.w3.org/ns/ldp#> SELECT distinct ?meta WHERE { VALUES ?pred {<https://w3id.org/fdp/fdp-o#metadataIssued> <http://rdf.biosemantics.org/ontologies/fdp-o#metadataIssued>} ?meta ?pred ?o . }") ids = [] repo.query(query) do |result| warn result.inspect ids << [result[:meta].to_s, [%w[rel describedby], %w[type text/turtle]]] end link = LinkHeader.new(ids).to_html warn "LINK: #{link}" link end |
#get_items(repo:) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fsp/proxies.rb', line 90 def get_items(repo:) query = SPARQL.parse(" PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX ldp: <http://www.w3.org/ns/ldp#> SELECT distinct ?id WHERE { ?s a ldp:DirectContainer . ?s ldp:contains ?id }") ids = [] repo.query(query) do |result| warn result.inspect ids << [result[:id].to_s, [%w[rel item], %w[type text/html]]] end link = LinkHeader.new(ids).to_html warn "LINK: #{link}" link end |
#get_types(repo:) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/fsp/proxies.rb', line 109 def get_types(repo:) # https://schema.org/CreativeWork http://www.re3data.org/schema/3-0#Repository # https://schema.org/DataCatalog http://www.re3data.org/schema/3-0#dataCatalog dcat:Catalog # https://schema.org/Dataset dcat:Dataset # https://schema.org/DataDownload dcat:Distribution query = SPARQL.parse(" PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX ldp: <http://www.w3.org/ns/ldp#> SELECT distinct ?type WHERE { VALUES ?type {<https://schema.org/CreativeWork> <http://www.re3data.org/schema/3-0#Repository> <https://w3id.org/fdp/fdp-o#FAIRDataPoint> <https://w3id.org/fdp/fdp-o#MetadataService> <http://www.w3.org/ns/dcat#DataService> <https://schema.org/DataCatalog> <http://www.re3data.org/schema/3-0#dataCatalog> <http://www.w3.org/ns/dcat#Catalog> <https://schema.org/Dataset> <http://www.w3.org/ns/dcat#Dataset> <https://schema.org/DataDownload> <http://www.w3.org/ns/dcat#Distribution> } VALUES ?pred {<https://w3id.org/fdp/fdp-o#metadataIssued> <http://rdf.biosemantics.org/ontologies/fdp-o#metadataIssued>} ?s a ?type . ?s ?pred ?val . # the main subject will have the metadata issued property }") types = [] links = [] link = '' repo.query(query) do |result| warn result.inspect if %w[http://www.re3data.org/schema/3-0#Repository https://w3id.org/fdp/fdp-o#FAIRDataPoint https://w3id.org/fdp/fdp-o#MetadataService http://www.w3.org/ns/dcat#DataService].include?(result[:type].to_s) types << 'https://schema.org/CreativeWork' types << result[:type].to_s elsif %w[http://www.re3data.org/schema/3-0#dataCatalog http://www.w3.org/ns/dcat#Catalog].include?(result[:type].to_s) types << 'https://schema.org/DataCatalog' types << result[:type].to_s elsif %w[http://www.w3.org/ns/dcat#Dataset].include?(result[:type].to_s) types << 'https://schema.org/Dataset' types << result[:type].to_s elsif %w[http://www.w3.org/ns/dcat#Distribution].include?(result[:type].to_s) types << 'https://schema.org/DataDownload' types << result[:type].to_s else types << 'https://schema.org/CreativeWork' end types.each do |type| links << [type, [%w[rel type]]] end link = LinkHeader.new(links).to_html warn "LINK: #{link}" break end link end |
#proxy ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fsp/proxies.rb', line 27 def proxy self.html = Fsp::Proxies::WebUtils.fetch( url: url, headers: { 'Accept' => 'text/html' } ) ttl = Fsp::Proxies::WebUtils.fetch( url: url, headers: { 'Accept' => 'text/turtle' } ) warn 'no turtle' unless ttl return self unless ttl repo = RDF::Repository.new RDF::Reader.for(:turtle).new(StringIO.new(ttl)) do |reader| reader.each_statement do |statement| repo << statement # warn statement.to_s end end self.cite_as = get_cite_as(repo: repo) # returns html links self.items = get_items(repo: repo) self.describedby = get_described_by(repo: repo) self.types = get_types(repo: repo) end |
#to_html ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fsp/proxies.rb', line 165 def to_html() html = self.html # warn "HTML " + html match = html.match(/(.*?)(>)(<link)(.*)/) # warn "MATCH " + match.inspect.to_s pre = match[1]+match[2] post = match[3]+ match[4] final = pre + self.cite_as + self.types + self.describedby + self.items + post final end |