Skip to content

Commit

Permalink
add expand adid
Browse files Browse the repository at this point in the history
  • Loading branch information
saumier committed Oct 26, 2023
1 parent 3a2470d commit 7825a25
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
13 changes: 12 additions & 1 deletion frame/lavitrine_frame.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"disambiguatingDescription" :{
"@container": "@language"
},
"definition" :{
"@id": "skos:definition",
"@container": "@language"
},
"startDateTime": {
"@id": "startDate",
"@type": "xsd:dateTime"
Expand Down Expand Up @@ -115,7 +119,14 @@
"image": {},
"location": {},
"name": {},
"performer": {},
"performer": {
"@type": ["Person","Organization"],
"@omitDefault": true,
"@explicit": true,
"name": {},
"sameAs": {},
"url":{}
},
"organizer": {},
"url": {},
"subEvent": {
Expand Down
15 changes: 10 additions & 5 deletions src/sparql/expand_artsdata_uris.sparql
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
PREFIX adr: <http://kg.artsdata.ca/resource/>
PREFIX schema: <http://schema.org/>
construct {
adr:K11-22 ?p ?o ;
?uri ?p ?o ;
schema:address ?address .
?address ?address_pred ?address_obj .
} where {
values ?uri { <uri_list_placeholder> }

graph ?g {
adr:K11-22 ?p ?o ;
schema:address ?address .
?address ?address_pred ?address_obj .
}
?uri ?p ?o .
OPTIONAL {
?uri schema:address ?address .
?address ?address_pred ?address_obj .
}
filter(!isBLANK(?o))
}
}
17 changes: 16 additions & 1 deletion src/utils/artsdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
require 'json/ld'

class ArtsdataPipeline
attr_accessor :sparql_client, :graph, :framed_graph, :report
attr_accessor :sparql_client, :graph, :framed_graph, :report, :adid
def initialize
@sparql_client = SPARQL::Client.new("http://db.artsdata.ca/repositories/artsdata")
@graph = RDF::Graph.new
@adid = []
end

# loads triples from a file or SPARQL endpoint
Expand All @@ -34,8 +35,10 @@ def load(**args)
add_to_graph(result)
if @graph.count == previous_count || i > 10
puts "Done loading."
puts @adid.inspect
break
end

puts "Graph has #{@graph.count} triples"
previous_count = @graph.count
i += 1
Expand All @@ -44,6 +47,16 @@ def load(**args)
result = sparql_client.query(sparql)
add_to_graph(result)
end

# dereference Arstdata IDs
if @adid.count > 0
uri_list = ""
@adid.each { |uri| uri_list += " <#{uri}> " }
sparql = File.read("./sparql/expand_artsdata_uris.sparql").gsub("<uri_list_placeholder>", uri_list)
result = sparql_client.query(sparql)
add_to_graph(result)
end

end


Expand Down Expand Up @@ -80,6 +93,8 @@ def report(file)
def add_to_graph(result)
result.each_statement do |statement|
# check if ADID and add to list for second step dereference
@adid << statement.object.value if statement.object.uri? && statement.object.value.start_with?("http://kg.artsdata.ca/resource/")
@adid.uniq!
@graph << statement
end
end
Expand Down

0 comments on commit 7825a25

Please sign in to comment.