Skip to content

Commit

Permalink
Merge 9b601ee into 8845cb0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Oct 29, 2018
2 parents 8845cb0 + 9b601ee commit ddb2441
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
27 changes: 12 additions & 15 deletions lib/qa/authorities/getty/ulan.rb
Expand Up @@ -15,25 +15,22 @@ def sparql(q) # rubocop:disable Metrics/MethodLength
search = untaint(q)
# if more than one term is supplied, check both preferred and alt labels
if search.include?(' ')
ex = "("
search.split(' ').each do |i|
ex += "regex(CONCAT(?name, ' ', ?alt), \"#{i}\",\"i\" ) && "
clauses = search.split(' ').collect do |i|
%((regex(?name, "#{i}", "i") || regex(?alt, "#{i}", "i")))
end
ex = ex[0..ex.length - 4]
ex += ")"
ex = "(#{clauses.join(' && ')})"
else
ex = "regex(?name, \"#{search}\", \"i\")"
ex = %(regex(?name, "#{search}", "i"))
end
# The full text index matches on fields besides the term, so we filter to ensure the match is in the term.
sparql = "SELECT DISTINCT ?s ?name ?bio {
?s a skos:Concept; luc:term \"#{search}\";
skos:inScheme <http://vocab.getty.edu/ulan/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
skos:altLabel ?alt .
FILTER #{ex} .
} ORDER BY ?name"
sparql
%(SELECT DISTINCT ?s ?name ?bio {
?s a skos:Concept; luc:term "#{search}";
skos:inScheme <http://vocab.getty.edu/ulan/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
skos:altLabel ?alt .
FILTER #{ex} .
} ORDER BY ?name).gsub(/[\s\n]+/, " ")
end

def untaint(q)
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/authorities/getty/ulan_spec.rb
Expand Up @@ -77,19 +77,19 @@
foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
skos:altLabel ?alt .
FILTER regex(?name, "search_term", "i") .
} ORDER BY ?name' }
} ORDER BY ?name'.gsub(/[\s\n]+/, ' ') }
end
context "using a two subject terms" do
subject { authority.sparql('search term') }
it {
is_expected.to eq "SELECT DISTINCT ?s ?name ?bio {
?s a skos:Concept; luc:term \"search term\";
is_expected.to eq %(SELECT DISTINCT ?s ?name ?bio {
?s a skos:Concept; luc:term "search term";
skos:inScheme <http://vocab.getty.edu/ulan/> ;
gvp:prefLabelGVP [skosxl:literalForm ?name] ;
foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
skos:altLabel ?alt .
FILTER (regex(CONCAT(?name, ' ', ?alt), \"search\",\"i\" ) && regex(CONCAT(?name, ' ', ?alt), \"term\",\"i\" ) ) .
} ORDER BY ?name" }
FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) .
} ORDER BY ?name).gsub(/[\s\n]+/, ' ') }
end
end
end

0 comments on commit ddb2441

Please sign in to comment.