Skip to content

Commit

Permalink
minimizeSimplifiedSparqlResults: recover previous minimize behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlath committed Mar 15, 2024
1 parent 26f6578 commit 24671e0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/helpers/simplify_sparql_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export function simplifySparqlResults (input: SparqlResults | string) {
}

export function minimizeSimplifiedSparqlResults (simplifySparqlResults: SimplifiedSparqlResults) {
return simplifySparqlResults
.map(simplifySparqlResult => {
const values = Object.values(simplifySparqlResult)
if (values.length > 1) throw new Error('too many variables: SPARQL result can not be minimzed')
return values[0] as (SparqlValueRaw | undefined)
})
// filtering-out bnodes
.filter((result): result is SparqlValueRaw => result != null)
simplifySparqlResults = simplifySparqlResults.filter(result => Object.keys(result).length > 0)
const canBeMinimized = simplifySparqlResults.every(result => Object.keys(result).length === 1)
if (canBeMinimized) {
return simplifySparqlResults.map(result => Object.values(result)[0]) as SparqlValueRaw[]
} else {
return simplifySparqlResults
}
}

function parseValue (valueObj?: SparqlValueObj) {
Expand Down

0 comments on commit 24671e0

Please sign in to comment.