Commit 64467d43 authored by Konstantin Schulz's avatar Konstantin Schulz

fixed enum handling for vocabulary corpora

parent 8a57d015
Pipeline #11862 passed with stages
in 2 minutes and 52 seconds
......@@ -66,8 +66,7 @@
<select [(ngModel)]="vocService.currentReferenceVocabulary"
name="currentReferenceVocabulary"
(change)="vocService.updateReferenceRange(); hasVocChanged = true">
<option *ngFor="let key of ObjectKeys(vocService.refVocMap)"
[value]=VocabularyCorpus[key]>
<option *ngFor="let key of ObjectKeys(vocService.refVocMap)" [value]=key>
{{ VocabularyCorpusTranslation[key] | translate}}
({{vocService.refVocMap[key].totalCount}}
{{'VOCABULARY_ITEMS' | translate}})
......
......@@ -9,13 +9,14 @@ import {TranslateTestingModule} from '../translate-testing/translate-testing.mod
import {FormsModule} from '@angular/forms';
import {IonicModule} from '@ionic/angular';
import {APP_BASE_HREF} from '@angular/common';
import {ExerciseType, MoodleExerciseType, SortingCategory, VocabularyCorpus} from '../models/enum';
import {ExerciseType, MoodleExerciseType, SortingCategory} from '../models/enum';
import MockMC from '../models/mockMC';
import {ApplicationState} from '../models/applicationState';
import {ExerciseMC} from '../models/exerciseMC';
import Spy = jasmine.Spy;
import configMC from '../../configMC';
import {UpdateInfo} from '../models/updateInfo';
import {VocabularyMC} from '../../../openapi';
describe('ExerciseListPage', () => {
let exerciseListPage: ExerciseListPage;
......@@ -73,7 +74,7 @@ describe('ExerciseListPage', () => {
exerciseListPage.getExerciseList().then(() => {
}, () => {
expect(requestSpy).toHaveBeenCalledTimes(1);
exerciseListPage.vocService.currentReferenceVocabulary = VocabularyCorpus.agldt;
exerciseListPage.vocService.currentReferenceVocabulary = VocabularyMC.Agldt;
exerciseListPage.helperService.applicationState.next(new ApplicationState({exerciseList: []}));
requestSpy.and.returnValue(Promise.resolve([]));
exerciseListPage.getExerciseList().then(() => {
......
......@@ -9,7 +9,6 @@ import {
ExerciseTypeTranslation,
MoodleExerciseType,
SortingCategory,
VocabularyCorpus,
VocabularyCorpusTranslation
} from '../models/enum';
import {TranslateService} from '@ngx-translate/core';
......@@ -20,7 +19,7 @@ import configMC from '../../configMC';
import {UpdateInfo} from '../models/updateInfo';
import {take} from 'rxjs/operators';
import {ApplicationState} from '../models/applicationState';
import {AnnisResponse} from '../../../openapi';
import {AnnisResponse, VocabularyMC} from '../../../openapi';
@Component({
selector: 'app-exercise-list',
......@@ -55,7 +54,6 @@ export class ExerciseListPage implements OnInit {
[SortingCategory.vocDesc]: 'matching_degree',
};
public sortingCategoriesVocCheck: Set<SortingCategory> = new Set([SortingCategory.vocAsc, SortingCategory.vocDesc]);
public VocabularyCorpus = VocabularyCorpus;
public VocabularyCorpusTranslation = VocabularyCorpusTranslation;
constructor(public navCtrl: NavController,
......@@ -97,7 +95,7 @@ export class ExerciseListPage implements OnInit {
const lastUpdateTime: number = force ? 0 : (state.exerciseList.length ? updateInfo.exerciseList : 0);
params = params.set('last_update_time', lastUpdateTime.toString());
if (this.vocService.currentReferenceVocabulary) {
params = params.set('vocabulary', VocabularyCorpus[this.vocService.currentReferenceVocabulary]);
params = params.set('vocabulary', this.vocService.currentReferenceVocabulary);
params = params.set('frequency_upper_bound', this.vocService.frequencyUpperBound.toString());
}
this.helperService.makeGetRequest(this.http, this.toastCtrl, url, params).then((exercises: ExerciseMC[]) => {
......@@ -175,7 +173,7 @@ export class ExerciseListPage implements OnInit {
toggleVocCorpus(): void {
this.showVocabularyCorpus = !this.showVocabularyCorpus;
if (this.showVocabularyCorpus && !this.vocService.currentReferenceVocabulary) {
this.vocService.currentReferenceVocabulary = VocabularyCorpus.bws;
this.vocService.currentReferenceVocabulary = VocabularyMC.Bws;
this.hasVocChanged = true;
}
const iRowElement: HTMLIonRowElement = document.querySelector('#vocCorpus');
......
......@@ -185,13 +185,6 @@ export enum TestType {
list = 'list' as any,
}
export enum VocabularyCorpus {
agldt = 'agldt' as any,
bws = 'bws' as any,
proiel = 'proiel' as any,
viva = 'viva' as any,
}
export enum VocabularyCorpusTranslation {
agldt = 'VOCABULARY_REFERENCE_CORPUS_AGLDT' as any,
bws = 'VOCABULARY_REFERENCE_CORPUS_BWS' as any,
......
......@@ -43,16 +43,16 @@
<!-- This is preferable compared to a button click event, because the browser knows from the
beginning that it is going to be a download (instead of an ordinary link or click). -->
<ion-col>
<a href="{{urlBase + FileType[FileType.Docx] + solutionIndicesString}}" download>
<a href="{{urlBase + FileType.Docx + solutionIndicesString}}" download>
{{ 'FILE_TYPE_DOCX' | translate }}</a>
</ion-col>
<ion-col>
<a href="{{urlBase + FileType[FileType.Pdf] + solutionIndicesString}}"
<a href="{{urlBase + FileType.Pdf + solutionIndicesString}}"
download>{{ 'FILE_TYPE_PDF' | translate }}</a>
</ion-col>
<!-- TODO: ADD MOODLE SUPPORT FOR MARK WORDS EXERCISES -->
<ion-col *ngIf="corpusService.exercise.type !== ExerciseType.markWords">
<a href="{{urlBase + FileType[FileType.Xml] + solutionIndicesString}}" download>{{ 'FILE_TYPE_XML' |
<a href="{{urlBase + FileType.Xml + solutionIndicesString}}" download>{{ 'FILE_TYPE_XML' |
translate }}</a>
</ion-col>
<ion-col>
......
......@@ -82,12 +82,12 @@
{{ 'TEXT_COMPLEXITY_DOCUMENTATION' | translate }}
</ion-row>
<ion-row>
<a (click)="generateDownloadLink(FileType[FileType.Docx])" style="padding:0.5em;">
<a (click)="generateDownloadLink(FileType.Docx)" style="padding:0.5em;">
{{ 'GENERATE_FILE_DOCX' | translate }}
</a>
</ion-row>
<ion-row>
<a (click)="generateDownloadLink(FileType[FileType.Pdf])" style="padding:0.5em;">
<a (click)="generateDownloadLink(FileType.Pdf)" style="padding:0.5em;">
{{ 'GENERATE_FILE_PDF' | translate }}
</a>
</ion-row>
......
......@@ -8,9 +8,9 @@ import {RouterModule} from '@angular/router';
import {TranslateTestingModule} from '../translate-testing/translate-testing.module';
import {FormsModule} from '@angular/forms';
import {APP_BASE_HREF} from '@angular/common';
import {VocabularyCorpus} from '../models/enum';
import Spy = jasmine.Spy;
import MockMC from '../models/mockMC';
import {VocabularyMC} from '../../../openapi';
describe('ShowTextPage', () => {
let showTextPage: ShowTextPage;
......@@ -80,6 +80,6 @@ describe('ShowTextPage', () => {
it('should be initialized', () => {
showTextPage.vocService.currentReferenceVocabulary = null;
showTextPage.ngOnInit();
expect(showTextPage.vocService.currentReferenceVocabulary).toBe(VocabularyCorpus.bws);
expect(showTextPage.vocService.currentReferenceVocabulary).toBe(VocabularyMC.Bws);
});
});
......@@ -6,12 +6,11 @@ import {VocabularyService} from 'src/app/vocabulary.service';
import {ExerciseService} from 'src/app/exercise.service';
import {HelperService} from 'src/app/helper.service';
import {TranslateService} from '@ngx-translate/core';
import {VocabularyCorpus} from '../models/enum';
import {HttpClient} from '@angular/common/http';
import {CorpusMC} from '../models/corpusMC';
import {take} from 'rxjs/operators';
import configMC from '../../configMC';
import { FileType } from 'openapi';
import {FileType, VocabularyMC} from 'openapi';
@Component({
selector: 'app-show-text',
......@@ -98,6 +97,6 @@ export class ShowTextPage implements OnInit {
ngOnInit(): void {
this.urlBase = configMC.backendBaseUrl + configMC.backendApiFilePath;
this.vocService.currentReferenceVocabulary = this.vocService.currentReferenceVocabulary || VocabularyCorpus.bws;
this.vocService.currentReferenceVocabulary = this.vocService.currentReferenceVocabulary || VocabularyMC.Bws;
}
}
......@@ -45,7 +45,7 @@
<h4>{{ 'VOCABULARY_REFERENCE_CORPUS' | translate }}</h4>
<select [(ngModel)]="vocService.currentReferenceVocabulary" name="currentReferenceVocabulary"
(change)="vocService.updateReferenceRange()">
<option *ngFor="let key of ObjectKeys(vocService.refVocMap)" [value]=VocabularyCorpus[key]>
<option *ngFor="let key of ObjectKeys(vocService.refVocMap)" [value]=key>
{{ VocabularyCorpusTranslation[key] | translate}} ({{vocService.refVocMap[key].totalCount}}
{{'VOCABULARY_ITEMS' | translate}})
</option>
......
import {NavController, ToastController} from '@ionic/angular';
import {Component} from '@angular/core';
import {VocabularyCorpus, VocabularyCorpusTranslation} from 'src/app/models/enum';
import {VocabularyCorpusTranslation} from 'src/app/models/enum';
import {VocabularyService} from 'src/app/vocabulary.service';
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
import {TranslateService} from '@ngx-translate/core';
......@@ -19,7 +19,6 @@ import {Sentence} from '../../../openapi';
})
export class VocabularyCheckPage {
ObjectKeys = Object.keys;
VocabularyCorpus = VocabularyCorpus;
VocabularyCorpusTranslation = VocabularyCorpusTranslation;
public adaptPassages = true;
public currentRankingUnits: Sentence[][];
......
......@@ -4,9 +4,8 @@ import {VocabularyService} from './vocabulary.service';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {IonicStorageModule} from '@ionic/storage';
import {TranslateTestingModule} from './translate-testing/translate-testing.module';
import {VocabularyCorpus} from './models/enum';
import {HttpErrorResponse} from '@angular/common/http';
import {AnnisResponse, Sentence} from '../../openapi';
import {HttpErrorResponse, HttpParams} from '@angular/common/http';
import {AnnisResponse, Sentence, VocabularyForm, VocabularyMC} from '../../openapi';
import Spy = jasmine.Spy;
describe('VocabularyService', () => {
......@@ -38,6 +37,11 @@ describe('VocabularyService', () => {
getSpy.and.returnValue(Promise.resolve([]));
const sentences: Sentence[] = await vocabularyService.getMatchingSentences('');
expect(sentences.length).toBe(0);
const params: HttpParams = getSpy.calls.argsFor(0)[3];
const vfObj: object = {};
params.keys().forEach((key: string) => vfObj[key] = params.get(key));
const vf: VocabularyForm = vfObj as VocabularyForm;
expect(vf.vocabulary).toBe(VocabularyMC.Bws);
const postSpy: Spy = spyOn(vocabularyService.helperService, 'makePostRequest').and.returnValue(Promise.resolve({}));
const result: AnnisResponse = await vocabularyService.getOOVwords('');
expect(result.graph_data).toBeFalsy();
......@@ -60,10 +64,10 @@ describe('VocabularyService', () => {
it('should update the reference range', () => {
vocabularyService.frequencyUpperBound = 0;
vocabularyService.ngOnInit();
vocabularyService.currentReferenceVocabulary = VocabularyCorpus.agldt;
vocabularyService.currentReferenceVocabulary = VocabularyMC.Agldt;
vocabularyService.updateReferenceRange();
expect(vocabularyService.frequencyUpperBound).toBe(500);
vocabularyService.currentReferenceVocabulary = VocabularyCorpus.viva;
vocabularyService.currentReferenceVocabulary = VocabularyMC.Viva;
vocabularyService.updateReferenceRange();
expect(vocabularyService.frequencyUpperBound).toBe(1164);
});
......
/* tslint:disable:no-string-literal */
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
import {Injectable, OnInit} from '@angular/core';
import {VocabularyCorpus} from 'src/app/models/enum';
import {Vocabulary} from 'src/app/models/vocabulary';
import {HelperService} from 'src/app/helper.service';
import {TestResultMC} from 'src/app/models/testResultMC';
......@@ -14,7 +13,7 @@ import {VocabularyMC} from '../../openapi';
providedIn: 'root'
})
export class VocabularyService implements OnInit {
currentReferenceVocabulary: VocabularyCorpus = VocabularyCorpus.bws;
currentReferenceVocabulary: VocabularyMC = VocabularyMC.Bws;
currentSentences: Sentence[] = [];
currentTestResults: { [exerciseIndex: number]: TestResultMC } = {};
desiredSentenceCount = 10;
......@@ -32,69 +31,69 @@ export class VocabularyService implements OnInit {
return this.refVocMap[this.currentReferenceVocabulary];
}
getOOVwords(queryUrn: string): Promise<AnnisResponse> {
return new Promise(((resolve, reject) => {
getMatchingSentences(queryUrn: string): Promise<Sentence[]> {
return new Promise((resolve, reject) => {
const url: string = configMC.backendBaseUrl + configMC.backendApiVocabularyPath;
const vf: VocabularyForm = {
frequency_upper_bound: this.frequencyUpperBound,
query_urn: queryUrn,
vocabulary: VocabularyMC[this.currentReferenceVocabulary]
vocabulary: this.currentReferenceVocabulary
};
const formData: FormData = new FormData();
Object.keys(vf).forEach((key: string) => formData.append(key, vf[key]));
this.helperService.makePostRequest(this.http, this.toastCtrl, url, formData).then((result: AnnisResponse) => {
let params: HttpParams = new HttpParams();
Object.keys(vf).forEach((key: string) => {
params = params.set(key, vf[key]);
});
this.helperService.makeGetRequest(this.http, this.toastCtrl, url, params).then((result: Sentence[]) => {
return resolve(result);
}, (error: HttpErrorResponse) => {
return reject(error);
});
}));
});
}
getMean(sentences: Sentence[]): number {
return sentences.map(x => x.matching_degree).reduce((a, b) => a + b) / sentences.length;
}
getPossibleSubCount(): number {
return this.getCurrentReferenceVocabulary().possibleSubcounts[0];
}
getMatchingSentences(queryUrn: string): Promise<Sentence[]> {
return new Promise((resolve, reject) => {
getOOVwords(queryUrn: string): Promise<AnnisResponse> {
return new Promise(((resolve, reject) => {
const url: string = configMC.backendBaseUrl + configMC.backendApiVocabularyPath;
const vf: VocabularyForm = {
frequency_upper_bound: this.frequencyUpperBound,
query_urn: queryUrn,
vocabulary: VocabularyMC[this.currentReferenceVocabulary]
vocabulary: this.currentReferenceVocabulary
};
let params: HttpParams = new HttpParams();
Object.keys(vf).forEach((key: string) => {
params = params.set(key, vf[key]);
});
this.helperService.makeGetRequest(this.http, this.toastCtrl, url, params).then((result: Sentence[]) => {
const formData: FormData = new FormData();
Object.keys(vf).forEach((key: string) => formData.append(key, vf[key]));
this.helperService.makePostRequest(this.http, this.toastCtrl, url, formData).then((result: AnnisResponse) => {
return resolve(result);
}, (error: HttpErrorResponse) => {
return reject(error);
});
});
}));
}
getPossibleSubCount(): number {
return this.getCurrentReferenceVocabulary().possibleSubcounts[0];
}
ngOnInit(): void {
this.refVocMap[VocabularyCorpus.agldt] = new Vocabulary({
this.refVocMap[VocabularyMC.Agldt] = new Vocabulary({
hasFrequencyOrder: true,
totalCount: 7182,
possibleSubcounts: []
});
this.refVocMap[VocabularyCorpus.bws] = new Vocabulary({
this.refVocMap[VocabularyMC.Bws] = new Vocabulary({
hasFrequencyOrder: false,
totalCount: 1276,
possibleSubcounts: [500, 1276]
});
this.refVocMap[VocabularyCorpus.proiel] = new Vocabulary({
this.refVocMap[VocabularyMC.Proiel] = new Vocabulary({
hasFrequencyOrder: true,
totalCount: 16402,
possibleSubcounts: []
});
this.refVocMap[VocabularyCorpus.viva] = new Vocabulary({
this.refVocMap[VocabularyMC.Viva] = new Vocabulary({
hasFrequencyOrder: false,
totalCount: 1164,
possibleSubcounts: [1164]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment