feat!: Edit Data structure

This commit is contained in:
Lucàs
2024-10-07 13:15:16 +02:00
parent 960e7b6777
commit 510d25d9af
7 changed files with 113 additions and 131 deletions
+20 -67
View File
@@ -1,78 +1,31 @@
import { Dataset } from "../dataset";
import { Data } from "../data";
import DmnModdle from "dmn-moddle";
import { DMN_Decision, Is_DMN_Decision } from "./interfaces/DMN_Decision";
import {
DMN_DecisionTable,
Is_DMN_DecisionTable,
} from "./interfaces/DMN_DecisionTable";
import {
DMN_InputClause,
Name_of_DMN_InputClause,
} from "./interfaces/DMN_InputClause";
import { Is_DMN_DecisionTable } from "./interfaces/DMN_DecisionTable";
import { Name_of_DMN_InputClause } from "./interfaces/DMN_InputClause";
import { Name_of_DMN_OutputClause } from "./interfaces/DMN_OutputClause";
import { ModdleElement } from "./interfaces/ModdleElement";
import { DmnError } from "./error/DmnError";
import { DMN_Definitions } from "./interfaces/DMN_Definitions";
export class DMN {
static async parse(xml: string) {
static async parse(xml: string): Promise<DMN_Definitions> {
const { rootElement, warnings } = await new DmnModdle().fromXML(xml);
if (warnings.length !== 0)
console.warn(warnings.map((warning: any) => warning.message).join(" * "));
return rootElement;
return rootElement as DMN_Definitions;
}
// static async getFilter(xml: string) {
// const rootElement = await DMN.parse(xml);
//
// const filterFunction = (me: ModdleElement) =>
// Is_DMN_Decision(me) && Is_DMN_DecisionTable(me.decisionLogic);
// const everyFunction = (decision: DMN_Decision) => {
// try {
// const decision_table: DMN_DecisionTable =
// decision.decisionLogic as DMN_DecisionTable;
// let features: string[] = decision_table.input!.map(
// (input_clause: DMN_InputClause) =>
// Name_of_DMN_InputClause(input_clause)
// );
// const index: number = features
// .map((feature: string): string => feature.toUpperCase())
// .indexOf(DMN.URL);
// if (index === -1) return false;
// // Si la zone 'text' est égale à "" alors prendre 'features[0]' :
// const data_source = decision_table.input[
// index
// ].inputExpression.text.replaceAll('"', ""); // ES2021
// features = features.concat(
// decision_table.output!.map((output_clause) =>
// Name_of_DMN_OutputClause(output_clause)
// )
// );
// // A changer, il y a autant de 'Randomizer' objects que de tables de décision :
// DMN._Randomizer = new Randomizer(
// data_source,
// features /* Number of features whose type is "output", default is '1' */
// );
//
// // decision_table.rule!.forEach((rule) => {
// // features.forEach((feature, feature_index) => {
// // const column = rule.inputEntry[feature_index];
// // // A priori, nothing here since "rules" are ignored...
// // y});
// // });
// } catch (error: unknown) {
// throw new DmnError(decision, DmnError.Invalid_JSON);
// }
// };
//
// const a: boolean = rootElement.drgElement
// .filter(filterFunction)
// .every(everyFunction);
//
// try {
// if (a === false) return Promise.resolve(undefined); // DMN processing causes trouble(s)...
// } catch (error: unknown) {
// console.error(error);
// }
// }
public static getSchema(dmnDefinitions: DMN_Definitions) {
const descisions: DMN_Decision[] = dmnDefinitions.drgElement.filter(
(element) => Is_DMN_Decision(element)
);
const { input, output } = descisions
.map((decision) => decision.decisionLogic)
.filter((decisionLogic) => Is_DMN_DecisionTable(decisionLogic))[0];
// TODO generate json schema
return {
input: input?.map((input) => Name_of_DMN_InputClause(input)),
output: output?.map((output) => Name_of_DMN_OutputClause(output)),
};
}
}