Skip to content

Commit

Permalink
Add front-anchoring to Getty SPARQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed May 2, 2024
1 parent 8ff6701 commit 5c392ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/authoritex/getty/aat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ defmodule Authoritex.Getty.AAT do
skos:inScheme <http://vocab.getty.edu/aat/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] .
FILTER (#{sparql_search_filter(q)}) .
} LIMIT #{max_results}
} ORDER BY #{sparql_order_clause(q)} LIMIT #{max_results}
"""
end
end

defp sparql_order_clause(q) do
~s{DESC(IF(REGEX(?name, "^#{q}$", "i"), 2, IF(REGEX(?name, "^#{q}", "i"), 1, 0)))}
end

defp sparql_search_filter(q) do
String.split(q)
|> Enum.map_join(" && ", &~s{regex(?name, "#{&1}", "i")})
Expand Down
2 changes: 1 addition & 1 deletion lib/authoritex/getty/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Authoritex.Getty.Base do
{:error, 404}

{:ok, [%{replaced_by: replaced_by}] = result} when replaced_by != "" ->
Logger.warn("#{id} is obsolete. Fetching replacement term #{replaced_by}.")
Logger.warning("#{id} is obsolete. Fetching replacement term #{replaced_by}.")
fetch(replaced_by)

{:ok, [result]} ->
Expand Down
6 changes: 5 additions & 1 deletion lib/authoritex/getty/tgn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ defmodule Authoritex.Getty.TGN do
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
gvp:parentString ?hint .
FILTER (#{sparql_search_filter(q)}) .
} LIMIT #{max_results}
} ORDER BY #{sparql_order_clause(q)} LIMIT #{max_results}
"""
end
end

defp sparql_order_clause(q) do
~s{DESC(IF(REGEX(?name, "^#{q}$", "i"), 2, IF(REGEX(?name, "^#{q}", "i"), 1, 0)))}
end

defp sparql_search_filter(q) do
String.split(q)
|> Enum.map_join(" && ", &~s{regex(?name, "#{&1}", "i")})
Expand Down
6 changes: 5 additions & 1 deletion lib/authoritex/getty/ulan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ defmodule Authoritex.Getty.ULAN do
foaf:focus/gvp:biographyPreferred [schema:description ?hint] ;
skos:altLabel ?alt .
FILTER (#{sparql_search_filter(q)}) .
} LIMIT #{max_results}
} ORDER BY #{sparql_order_clause(q)} LIMIT #{max_results}
"""
end
end

defp sparql_order_clause(q) do
~s{DESC(IF(REGEX(?name, "^#{q}$", "i"), 2, IF(REGEX(?name, "^#{q}", "i"), 1, 0)))}
end

defp sparql_search_filter(q) do
if String.contains?(q, " ") do
String.split(q)
Expand Down

0 comments on commit 5c392ac

Please sign in to comment.