Skip to content

Commit

Permalink
#645 : works when date range is given
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Oct 14, 2024
1 parent 9098ae1 commit 7a444b6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
47 changes: 43 additions & 4 deletions src/sparnatural/generators/sparql/SparqlGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import WhereBuilder from "./WhereBuilder";
import SparqlFactory from "./SparqlFactory";
import { DataFactory } from 'rdf-data-factory';
import { DraggableComponentState } from "../../components/variables-section/variableorder/DraggableComponent";
import GroupWrapper from "../../components/builder-section/groupwrapper/GroupWrapper";
import ISpecificationProperty from "../../spec-providers/ISpecificationProperty";

const factory = new DataFactory();

Expand Down Expand Up @@ -136,17 +138,54 @@ export default class SparqlGenerator {
}

#varsToRDFJS(variables: Array<DraggableComponentState>): Variable[] {
return variables.map((v) => {
let variablesArray:Variable[][] = variables.map((v) => {
if(v.aggregateFunction) {
return SparqlFactory.buildAggregateFunctionExpression(
return [SparqlFactory.buildAggregateFunctionExpression(
v.aggregateFunction,
factory.variable(v.originalVariable.variable),
factory.variable(v.selectedVariable.variable)
)
)];
} else {
return factory.variable(v.selectedVariable.variable);
// find where the variable comes from
let specProperty:ISpecificationProperty = undefined;
this.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
(grpWrapper: GroupWrapper) => {
if(grpWrapper.CriteriaGroup.EndClassGroup.endClassVal.variable == v.selectedVariable.variable) {
// check if the spec tells us that begin date / end date / exact date propeties are used
let propertyType = grpWrapper.CriteriaGroup.ObjectPropertyGroup.getTypeSelected();
specProperty = this.specProvider.getProperty(propertyType);
}
}
); // end traverse

// not found as an object, we cannot read the specification property, so return as normal
if(!specProperty) {
return [ factory.variable(v.selectedVariable.variable) ];
}

if(specProperty.getBeginDateProperty() || specProperty.getEndDateProperty()) {
let result:Variable[] = []
if(specProperty.getBeginDateProperty()) {
result.push(factory.variable(v.selectedVariable.variable+"_begin"));
}
if(specProperty.getEndDateProperty()) {
result.push(factory.variable(v.selectedVariable.variable+"_end"));
}
if(specProperty.getExactDateProperty()) {
result.push(factory.variable(v.selectedVariable.variable+"_exact"));
}
return result;
} else {
// no begin or date, return as normal
return [ factory.variable(v.selectedVariable.variable) ];
}
}
});

let finalResult:Variable[] = [];
variablesArray.forEach((varArray:Variable[]) => {finalResult.push(...varArray)});
return finalResult;

}

// It will be ordered by the Provided variable
Expand Down
2 changes: 1 addition & 1 deletion src/sparnatural/generators/sparql/ValueBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export class DateTimePickerValueBuilder extends BaseValueBuilder implements Valu
factory.namedNode(beginDateProp),
factory.namedNode(endDateProp),
exactDateProp != null?factory.namedNode(exactDateProp):null,
factory.variable(this.startClassVal.variable)
factory.variable(this.endClassVal.variable)
)
];
} else {
Expand Down

0 comments on commit 7a444b6

Please sign in to comment.