Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove “__all” from query in SPARQL #270

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ export const getSubjectClasses = (subjectClasses?: string[]) => {
};

export const getFilterPredicates = (predicates?: string[]) => {
if (!predicates?.length) {
const filteredPredicates = predicates?.filter(p => p !== "__all") || [];
if (!filteredPredicates.length) {
return "";
}

let filterByAttributes = "";
filterByAttributes += "FILTER (?predicate IN (";
predicates.forEach((p, i) => {
filteredPredicates.forEach((p, i) => {
filterByAttributes += `<${p}>`;
if (i < predicates.length - 1) {
if (i < filteredPredicates.length - 1) {
filterByAttributes += ", ";
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ describe("SPARQL > keywordSearchTemplate", () => {
);
});

it("Should return a template for searched attributes without the __all predicate", () => {
const template = keywordSearchTemplate({
subjectClasses: ["air:airport"],
searchTerm: "JFK",
predicates: ["air:city", "air:code", "__all"],
exactMatch: true,
});

expect(removeExtraWhitespace(template)).toBe(
removeExtraWhitespace(`
SELECT ?subject ?pred ?value ?class {
?subject ?pred ?value {
SELECT DISTINCT ?subject ?class {
?subject a ?class ; ?predicate ?value .
FILTER (?predicate IN (<air:city>, <air:code>))
kmcginnes marked this conversation as resolved.
Show resolved Hide resolved
FILTER (?class IN (<air:airport>))
FILTER (?value = "JFK")
}
LIMIT 10 OFFSET 0
}
FILTER(isLiteral(?value))
}
`)
);
});

it("Should return a template for the ID token attribute exactly matching the search term", () => {
const template = keywordSearchTemplate({
subjectClasses: ["air:airport"],
Expand Down
Loading