Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// if subQuery projection variable is different from default we need to make sure that
// the result is still available under default variable (?subject)
if (projectionVar.substring(1) !== SEMANTIC_SEARCH_VARIABLES.PROJECTION_ALIAS_VAR) {
baseQuery.where.push({
expression: projectionVar as SparqlJs.Term,
type: 'bind',
variable: ('?' + SEMANTIC_SEARCH_VARIABLES.PROJECTION_ALIAS_VAR) as SparqlJs.Term,
});
}
// override limit only when query doesn't already have one
if (!baseQuery.limit && this.context.baseConfig.limit) {
baseQuery.limit = context.baseConfig.limit;
}
const queryWithBindings = SparqlClient.setBindings(baseQuery, this.context.bindings);
// if context is set for result visualization we also need to
// rewrite the query to take into account virtual relations
if (_.has(context.bindings, RESULT_VARIABLES.CONTEXT_RELATION_VAR)) {
this.bindRelationPattern(queryWithBindings, context.bindings);
}
return SparqlUtil.serializeQuery(
generateQueryForMultipleDatasets(
queryWithBindings, context.selectedDatasets, context.baseConfig.datasetsConfig
)
);
}
);
);
facetsQuery.where.unshift(...baseQuery.where);
facetsQuery.where = facetsQuery.where.concat(
this.generateQueryClause(
baseQuery, this.excludeClauseForRelation(conjuncts, relation.iri)
)
);
// If we have a threshold for the number of displayed facet values,
// we introduce a limit into the query to retrieve only (threshold + 1) results
if (isResourceQuery && this.config.config.facetValuesThreshold > 0) {
facetsQuery.limit = this.config.config.facetValuesThreshold + 1;
}
const query =
SparqlClient.setBindings(
facetsQuery, _.assign({
[FACET_VARIABLES.RELATION_VAR]: relation.iri,
[FACET_VARIABLES.RANGE_VAR]: relation.hasRange.iri,
}, {
[SEMANTIC_SEARCH_VARIABLES.SELECTED_ALIGNMENT]:
this.context.selectedAlignment.map(a => a.iri).getOrElse(undefined),
})
);
const federatedQuery =
generateQueryForMultipleDatasets(
query, this.context.selectedDatasets, this.context.baseConfig.datasetsConfig
);
return SparqlClient.select(federatedQuery, {context: this.context.semanticContext});
}
(field: ArgumentsFieldDefinition, repository: string) => {
const query = SparqlUtil.parseQuerySync(field.selectPattern);
const askQuery: SparqlJs.AskQuery = {
prefixes: query.prefixes,
type: 'query',
queryType: 'ASK',
where: query.where,
};
return SparqlClient.ask(
SparqlClient.setBindings(
askQuery, {'subject': this.props.record}
),
{context: {repository: repository}}
);
}
function generateNonFederatedPatternForDataset(
dataset: Dataset, whereClause: Array, config?: DatasetsConfig
): SparqlJs.Pattern {
const datasetPattern =
Maybe.fromNullable(config).chain(
c => Maybe.fromNullable(c.datasetPattern)
).getOrElse(DATASET_PATTERN);
const patterns =
SparqlUtil.parsePatterns(datasetPattern).concat(whereClause);
const parametrizedPatterns =
SparqlClient.setBindings(
{
prefixes: {},
type: 'query',
queryType: 'SELECT',
variables: ['*'],
where: patterns,
},
{__dataset__: dataset.iri}
).where;
return {
type: 'group',
patterns: parametrizedPatterns,
};
}
createMetadata(
metadataQuery: string,
metadataIri: Rdf.Iri
): Kefir.Property {
if (!metadataQuery) {
return Kefir.constant([]);
}
let query = parseQuerySync(metadataQuery);
query = SparqlClient.setBindings(query, {
metadataIri
});
return SparqlClient.construct(query);
}
if (patternConfig.kind === 'place') {
if (disjunct.kind === Model.SpatialDisjunctKinds.Distance) {
queryPattern = patternConfig.distanceQueryPattern;
} else if (disjunct.kind === Model.SpatialDisjunctKinds.BoundingBox) {
queryPattern = patternConfig.boundingBoxQueryPattern;
}
} else {
queryPattern = patternConfig.queryPattern;
}
const parsedPattern = parseQueryPattern(queryPattern, projectionVariable);
const parameters =
_.assign(
getGenericVariables(domain, conjunct),
disjunctToVariables(config, patternConfig, conjunct)(disjunct)
);
return SparqlClient.setBindings(parsedPattern, parameters);
}
isWorkflowExist(
resourceIri: Rdf.Iri
): Kefir.Property {
const queryStr = `ASK {
?workflow a ?type .
?workflow ?predicate ?subject .
}`;
let query = parseQuerySync(queryStr);
query = SparqlClient.setBindings(query, {
subject: resourceIri,
type: VocabWorkflow.WorkflowInstantiation,
predicate: VocabWorkflow.subject,
});
return SparqlClient.ask(query);
}
}
function propSetForArgumentsBelief(belief: ArgumentsFieldBelief): Kefir.Property {
const query =
buildQueryForArgumentsBelief(
SparqlUtil.parseQuerySync(belief.field.insertPattern)
);
return SparqlClient.construct(
SparqlClient.setBindings(query, {'subject': belief.target})
);
}