Hi everyone,
I’m looking for an easy way to filter/select dict in vector based on the value of one of the key.
In the example below, I need to find the title of a data, given by the first Dict of the vector (but it is not always the first…)
To find the good Dict, I need to evaluate the value of the key “propertyUri”, sometimes in association with the key “lang”:
v = [
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://nakala.fr/terms#title", "lang" => "fr", "value" => "Z1J255"),
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://nakala.fr/terms#created", "lang" => nothing, "value" => "2024-02-06")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://nakala.fr/terms#license", "lang" => nothing, "value" => "PDM")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#anyURI", "propertyUri" => "http://nakala.fr/terms#type", "lang" => nothing, "value" => "http://purl.org/coar/resource_type/c_c513")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://purl.org/dc/terms/subject", "lang" => "fr", "value" => "maitrises")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://purl.org/dc/terms/subject", "lang" => "fr", "value" => "experts")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://purl.org/dc/terms/subject", "lang" => "fr", "value" => "Paris")
Dict("typeUri" => "http://www.w3.org/2001/XMLSchema#string", "propertyUri" => "http://purl.org/dc/terms/subject", "lang" => "fr", "value" => "prosopographie")
]
For now, I’m doing like this
label = Vector()
for meta in metas
if get(meta, "propertyUri", "") === "http://nakala.fr/terms#title"
push!(label, get(meta, "value", "unknown"))
end
end
label[1]
It works, but isn’t there an easier and more effective method? Maybe with predicate like XPath, something like v[:propertyUri === “value”]?
Best,
Josselin