| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import {Injectable} from '@angular/core';
- import {Subject} from 'rxjs';
- import {AdjusterEventService} from './adjuster-event.service';
- @Injectable({providedIn: 'root'})
- export class AdjusterPresetsService {
- activeProblem: Problem;
- activeRole: Role;
- activeSchema: Schema;
- schemaChanges: Subject<Schema> = new Subject();
- problemChanges: Subject<Problem> = new Subject();
- ontology;
- roles: Role[] = [];
- schemas: Schema[] = [];
- constructor(public adjusterEventService: AdjusterEventService) {
- this.adjusterEventService.ontologyLoads.subscribe((ontology) => {
- this.ontology = ontology;
- this.loadRoles();
- this.loadSchemas();
- this.problemChanges.next(this.activeProblem ?? null);
- })
- }
- applyProblem(problem: Problem) {
- console.log(problem);
- this.problemChanges.next(problem);
- }
- changeSchema(schema: Schema) {
- console.log(schema);
- this.schemaChanges.next(schema);
- }
- getActiveRoleProblems(): Array<Problem> {
- return this.activeRole?.problems ?? [];
- }
- getActiveSchemaGroups(): Array<DatasetGroup> {
- return this.activeSchema.groups ?? [];
- }
- getGroupDatasets(groupID: string): Array<Dataset> {
- return this.ontology
- .find((subject) => subject['@id'] == groupID)["http://www.semanticweb.org/attractiveness/hasDataset"]
- ?.map((entity) => {
- const datasetEntity = this.ontology.find((subject) => subject['@id'] == entity['@id']);
- return {
- id: datasetEntity["@id"],
- labels: datasetEntity["http://www.w3.org/2000/01/rdf-schema#label"], //TODO: i18n this!
- desc: '',
- included: true
- }
- }) ?? [];
- }
- getLabelInLang(labels: Label[], lang: string) {
- return labels.find((labelEntity) => labelEntity['@language'] == lang)?.['@value'] ?? labels[0]['@value'];
- }
- loadRoles() {
- this.roles = this.ontology
- .filter((subject) => subject['@type']?.includes("http://www.semanticweb.org/attractiveness/Role"))
- .map((subject) => {
- return {
- id: subject['@id'],
- labels: subject["http://www.w3.org/2000/01/rdf-schema#label"],
- problems: subject["http://www.semanticweb.org/attractiveness/solvesProblem"].map(
- (problem) => {
- const problemEntity = this.ontology.find((subject) => subject['@id'] == problem['@id']);
- return {
- id: problem['@id'],
- labels: problemEntity?.["http://www.w3.org/2000/01/rdf-schema#label"],
- requiredDatasets: problemEntity?.["http://www.semanticweb.org/attractiveness/requiresDataset"].map((dataset) => dataset['@id'])
- }
- }
- )
- }
- });
- this.activeRole = this.roles[0];
- this.activeProblem = this.roles[0].problems[0];
- }
- loadSchemas() {
- this.schemas = this.ontology
- .filter((subject) => subject['@type']?.includes("http://www.semanticweb.org/attractiveness/ClassificationSchema"))
- .map((subject) => {
- return {
- id: subject['@id'],
- labels: subject["http://www.w3.org/2000/01/rdf-schema#label"],
- groups: subject["http://www.semanticweb.org/attractiveness/consistsOf"].map(
- (group) => {
- return {
- id: group['@id'],
- labels: this.ontology.find((subject) => subject['@id'] == group['@id'])?.["http://www.w3.org/2000/01/rdf-schema#label"]
- }
- }
- )
- }
- });
- this.activeSchema = this.schemas[0];
- this.schemaChanges.next(this.activeSchema);
- }
- pickProblem(role) {
- this.activeProblem = role.problems[0] ?? null;
- }
- }
- export type Dataset = {
- id: string;
- labels: Label[];
- desc: string;
- included: boolean;
- }
- export type DatasetGroup = {
- id: string;
- labels?: Label[];
- };
- export type Factor = {
- id: string;
- labels: Label[];
- weight: number;
- datasets: Dataset[];
- };
- export type Label = {
- "@value": string
- "@language"?: string,
- };
- export type Problem = {
- id: string;
- labels?: Label[];
- requiredDatasets: string[]
- };
- export type Role = {
- id: string;
- labels?: Label[];
- problems?: Problem[];
- };
- export type Schema = {
- id: string,
- labels?: Label[];
- groups?: DatasetGroup[];
- };
|