Commit bacb481a authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

improved the citation system, it now works smoothly for larger amounts of data

parent 3ae9f9e7
{
"name": "mcClient",
"version": "0.2.2",
"version": "0.2.3",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
......
......@@ -20,6 +20,11 @@
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col>
<button ion-button block (click)="showText()">{{ "SHOW" | translate }}</button>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-label>
......@@ -39,27 +44,43 @@
</ion-row>
<ion-row>
<ion-col>
<ion-input [(ngModel)]="corpusProvider.currentTextRange.start" list="citationLevels"
name="textRangeStart" (ionChange)="showFurtherReferences($event.value).then()"
<ion-input (ionChange)="showFurtherReferences($event).then()" (ionFocus)="showStartList = true"
(ionBlur)="showStartList = false" [(ngModel)]="corpusProvider.currentTextRange.start"
placeholder="{{ '0' + (corpusProvider.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default] ? '' : (corpusProvider.currentCorpus.citation_level_3 === CitationLevel[CitationLevel.default] ? '.0' : '.0.0'))}}"></ion-input>
</ion-col>
<ion-col>
<ion-input [(ngModel)]="corpusProvider.currentTextRange.end" list="citationLevels"
name="textRangeEnd" (ionChange)="showFurtherReferences($event.value).then()"
<ion-input (ionChange)="showFurtherReferences($event).then()" (ionFocus)="showEndList = true"
list="citationLevels" (ionBlur)="showEndList = false"
[(ngModel)]="corpusProvider.currentTextRange.end"
placeholder="{{ '0' + (corpusProvider.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default] ? '' : (corpusProvider.currentCorpus.citation_level_3 === CitationLevel[CitationLevel.default] ? '.0' : '.0.0'))}}"></ion-input>
</ion-col>
<datalist id="citationLevels">
<option *ngFor="let key of currentlyAvailableCitations" [value]="key"></option>
</datalist>
</ion-row>
<ion-row>
<ion-col></ion-col>
<ion-col>
<button type="button" ion-button icon-only (click)="corpusProvider.currentTextRange.end = corpusProvider.currentTextRange.start">
<button type="button" ion-button icon-only
(click)="corpusProvider.currentTextRange.end = corpusProvider.currentTextRange.start">
<ion-icon name="copy"></ion-icon>
</button>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<ion-grid *ngIf="showStartList">
<ion-row *ngFor="let citation of currentlyAvailableCitations">
<ion-col>
<!--TODO: ADD A CLICK EVENT TO SELECT THE CHOSEN VALUE AS A START/END STRING; WORK AROUND THE PROBLEM THAT THE ionBlur EVENT MAKES THIS LIST DISAPPEAR JUST BEFORE THE CLICK EVENT CAN TRIGGER-->
<div>{{citation}}</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-col>
<ion-col>
<ion-grid *ngIf="showEndList">
<ion-row *ngFor="let citation of currentlyAvailableCitations">
<ion-col>
<div>{{citation}}</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-col>
</ion-row>
</ion-grid>
<button ion-button block (click)="showText()">{{ "SHOW" | translate }}</button>
</ion-content>
......@@ -7,6 +7,7 @@ import {TextRange} from "../../models/textRange";
import {TranslateService} from "@ngx-translate/core";
import {Citation} from "../../models/citation";
import {FeedbackPage} from "../feedback/feedback";
import {BaseInput} from "ionic-angular/es2015/util/base-input";
/**
* Generated class for the CorpusDetailPage page.
......@@ -30,6 +31,9 @@ export class CorpusDetailPage {
currentlyAvailableCitations: string[] = [];
public citationValuesStart: number[];
public citationValuesEnd: number[];
public isTextRangeCheckRunning: boolean = false;
public showStartList = false;
public showEndList = false;
constructor(public navCtrl: NavController, public navParams: NavParams,
public corpusProvider: CorpusProvider,
......@@ -38,13 +42,12 @@ export class CorpusDetailPage {
this.currentlyAvailableCitations = [];
this.corpusProvider.currentTextRange = new TextRange({start: "", end: ""});
if (Object.keys(this.corpusProvider.currentCorpus.citations).length === 0) {
this.addReferences(this.corpusProvider.currentCorpus.citation_level_1).then();
this.addReferences(this.corpusProvider.currentCorpus.citation_level_1).then(() => {
this.initPage();
});
}
else {
this.currentlyAvailableCitations = Object.keys(this.corpusProvider.currentCorpus.citations);
if (this.corpusProvider.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default]) {
this.initReffDisplay();
}
this.initPage();
}
this.translateService.get("INVALID_TEXT_RANGE").subscribe((value) => {
this.invalidTextRangeString = value;
......@@ -107,9 +110,6 @@ export class CorpusDetailPage {
if (relevantCitationLabels.length === 0) {
this.corpusProvider.currentCorpus.citations[citation.label] = citation;
this.currentlyAvailableCitations.push(citation.label);
if (targetCitationLevel === this.corpusProvider.currentCorpus.citation_level_1 && this.corpusProvider.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default]) {
this.initReffDisplay();
}
}
else if (relevantCitationLabels.length === 1) {
this.corpusProvider.currentCorpus.citations[relevantCitationLabels[0]].subcitations[citation.label] = citation;
......@@ -136,42 +136,74 @@ export class CorpusDetailPage {
return;
}
}
else if (citationLabelsStart.length < 2 || citationLabelsEnd.length < 2) {
resolve(false);
return;
}
if (this.corpusProvider.currentCorpus.citation_level_3 === CitationLevel[CitationLevel.default]) {
if (citationLabelsStart.length !== 2 || citationLabelsEnd.length !== 2) {
else {
if (citationLabelsStart.length < 2 || citationLabelsEnd.length < 2) {
resolve(false);
return;
}
}
else if (citationLabelsStart.length !== 3 || citationLabelsEnd.length !== 3) {
resolve(false);
return;
else {
if (this.corpusProvider.currentCorpus.citation_level_3 === CitationLevel[CitationLevel.default]) {
if (citationLabelsStart.length !== 2 || citationLabelsEnd.length !== 2) {
resolve(false);
return;
}
}
else if (citationLabelsStart.length !== 3 || citationLabelsEnd.length !== 3) {
resolve(false);
return;
}
}
}
this.citationValuesEnd = [];
this.citationValuesStart = [];
this.addMissingCitations(citationLabelsStart, citationLabelsEnd).then(() => {
let citationValuesStart: number[] = this.citationValuesStart;
let citationValuesEnd: number[] = this.citationValuesEnd;
let a = citationValuesStart.some((value, index, array) => {
return array[index] > citationValuesEnd[index];
});
resolve(!a);
if (citationValuesStart[0] < citationValuesEnd[0]) {
resolve(true);
}
else if (citationValuesStart[0] === citationValuesEnd[0]) {
if (citationValuesStart.length > 1) {
if (citationValuesStart[1] < citationValuesEnd[1]) {
resolve(true);
}
else if (this.citationValuesStart[1] === citationValuesEnd[1]) {
if (citationValuesStart.length > 2) {
resolve(citationValuesStart[2] <= citationValuesEnd[2]);
}
else {
resolve(true);
}
}
else {
resolve(false);
}
}
else {
resolve(true);
}
}
else {
resolve(false);
}
});
});
}
private initReffDisplay() {
let randomLabel: string = this.corpusProvider.currentCorpus.citations[Object.keys(this.corpusProvider.currentCorpus.citations)[0]].label;
this.corpusProvider.currentTextRange.start = this.corpusProvider.currentTextRange.end = randomLabel;
private initPage() {
this.currentlyAvailableCitations = Object.keys(this.corpusProvider.currentCorpus.citations);
if (this.corpusProvider.currentCorpus.citation_level_2 === CitationLevel[CitationLevel.default]) {
let randomLabel: string = this.corpusProvider.currentCorpus.citations[Object.keys(this.corpusProvider.currentCorpus.citations)[0]].label;
this.corpusProvider.currentTextRange.start = this.corpusProvider.currentTextRange.end = randomLabel;
}
}
public mapCitationLabelsToValues(label: string, index: number, citationLabels: string[], valueList: number[]) {
return new Promise(resolve => {
if (index === 0) {
valueList.push(this.corpusProvider.currentCorpus.citations[label].value);
resolve();
}
else if (index === 1) {
if (Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[index - 1]].subcitations).length === 0) {
......@@ -182,6 +214,7 @@ export class CorpusDetailPage {
}
else {
valueList.push(this.corpusProvider.currentCorpus.citations[citationLabels[index - 1]].subcitations[label].value);
resolve();
}
}
else if (index === 2) {
......@@ -193,13 +226,14 @@ export class CorpusDetailPage {
}
else {
valueList.push(this.corpusProvider.currentCorpus.citations[citationLabels[index - 2]].subcitations[citationLabels[index - 1]].subcitations[label].value);
resolve();
}
}
resolve();
});
}
async showFurtherReferences(value: string) {
async showFurtherReferences(event: BaseInput<string>) {
let value: string = event.value;
if (!value) {
return;
}
......@@ -207,42 +241,21 @@ export class CorpusDetailPage {
if (dotCount > 0 && value.endsWith(".")) {
// remove empty elements from the split array
let citationLabels: string[] = value.split(".").filter(x => x);
if (citationLabels.length > 0) {
if (citationLabels.length === 1 && this.corpusProvider.currentCorpus.citation_level_2 !== CitationLevel[CitationLevel.default]) {
this.currentlyAvailableCitations = [];
if (Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations).length === 0) {
this.addReferences(this.corpusProvider.currentCorpus.citation_level_2, [citationLabels[0]]).then();
}
else {
Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations).forEach(key => {
let newLabel: string = citationLabels[0].concat(".", key);
this.currentlyAvailableCitations.push(newLabel);
});
}
}
else if (citationLabels.length === 2 && this.corpusProvider.currentCorpus.citation_level_3 !== CitationLevel[CitationLevel.default]) {
this.currentlyAvailableCitations = [];
while (!this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]]) {
await new Promise(resolve => setTimeout(resolve, 50));
}
if (Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]].subcitations).length === 0) {
this.addReferences(this.corpusProvider.currentCorpus.citation_level_3, [citationLabels[0], citationLabels[1]]).then();
}
else {
Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]].subcitations).forEach(key => {
let newLabel: string = citationLabels[0].concat(".", citationLabels[1], ".", key);
this.currentlyAvailableCitations.push(newLabel);
});
}
}
if (citationLabels.length > 0 && this.corpusProvider.currentCorpus.citations[citationLabels[0]]) {
this.updateReferences(citationLabels).then();
}
}
}
showText() {
if (this.isTextRangeCheckRunning) {
return;
}
let citationLabelsStart: string[] = this.corpusProvider.currentTextRange.start.split(".").filter(x => x);
let citationLabelsEnd: string[] = this.corpusProvider.currentTextRange.end.split(".").filter(x => x);
this.isTextRangeCheckRunning = true;
this.checkTextRange(citationLabelsStart, citationLabelsEnd).then((isTextRangeCorrect: boolean) => {
this.isTextRangeCheckRunning = false;
if (!isTextRangeCorrect) {
let toast = this.toastCtrl.create({
message: this.invalidTextRangeString,
......@@ -258,4 +271,42 @@ export class CorpusDetailPage {
this.navCtrl.push(ShowTextPage).then();
});
}
updateReferences(citationLabels: string[]) {
return new Promise(resolve => {
if (citationLabels.length === 1 && this.corpusProvider.currentCorpus.citation_level_2 !== CitationLevel[CitationLevel.default]) {
this.currentlyAvailableCitations = [];
if (Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations).length === 0) {
this.addReferences(this.corpusProvider.currentCorpus.citation_level_2, [citationLabels[0]]).then(() => {
resolve();
});
}
else {
Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations).forEach(key => {
let newLabel: string = citationLabels[0].concat(".", key);
this.currentlyAvailableCitations.push(newLabel);
});
resolve();
}
}
else if (citationLabels.length === 2 && this.corpusProvider.currentCorpus.citation_level_3 !== CitationLevel[CitationLevel.default]) {
this.currentlyAvailableCitations = [];
if (!this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]]) {
resolve();
}
if (Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]].subcitations).length === 0) {
this.addReferences(this.corpusProvider.currentCorpus.citation_level_3, [citationLabels[0], citationLabels[1]]).then(() => {
resolve();
});
}
else {
Object.keys(this.corpusProvider.currentCorpus.citations[citationLabels[0]].subcitations[citationLabels[1]].subcitations).forEach(key => {
let newLabel: string = citationLabels[0].concat(".", citationLabels[1], ".", key);
this.currentlyAvailableCitations.push(newLabel);
});
resolve();
}
}
});
}
}
......@@ -6,7 +6,6 @@ import {ExerciseProvider} from "../../providers/exercise/exercise";
import {TranslateService} from "@ngx-translate/core";
import {FeedbackPage} from "../feedback/feedback";
import {CorpusProvider} from "../../providers/corpus/corpus";
import {VocabularyCheckPage} from "../vocabulary-check/vocabulary-check";
@Component({
selector: 'page-home',
......@@ -32,8 +31,7 @@ export class HomePage {
this.navCtrl.push(AuthorPage).then();
}
async test() {
this.navCtrl.push(VocabularyCheckPage).then();
test() {
}
refreshCorpora() {
......@@ -46,6 +44,5 @@ export class HomePage {
position: 'top'
});
toast.present().then();
let a = new Date().getTime()
}
}
......@@ -97,10 +97,10 @@ export class ShowTextPage {
if (this.exerciseProvider.exercise.type === ExerciseType.matching) {
this.exerciseProvider.exercise.queryItems = [new QueryMC({
phenomenon: Phenomenon.partOfSpeech,
values: [PartOfSpeechValue.adjective],
values: [Object.keys(this.exerciseProvider.phenomenonMap[Phenomenon.partOfSpeech][2])[0]],
}), new QueryMC({
phenomenon: Phenomenon.partOfSpeech,
values: [PartOfSpeechValue.adjective],
values: [Object.keys(this.exerciseProvider.phenomenonMap[Phenomenon.partOfSpeech][2])[0]],
})];
}
else if (this.exerciseProvider.exercise.queryItems.length > 1) {
......@@ -120,6 +120,8 @@ export class ShowTextPage {
existingValue = this.exerciseProvider.phenomenonMap[Phenomenon.partOfSpeech][2][pos];
this.exerciseProvider.phenomenonMap[Phenomenon.partOfSpeech][2][pos] = (existingValue ? existingValue : 0) + 1;
});
// init the display with a (almost) random value
this.exerciseProvider.exercise.queryItems[0].values = [Object.keys(this.exerciseProvider.phenomenonMap[Phenomenon.partOfSpeech][2])[0]];
let pointingLinks: LinkMC[] = ar.graph.links.filter(x => x.annis_component_type === "Pointing");
pointingLinks.forEach((link: LinkMC) => {
let dep: DependencyValue = this.corpusProvider.dependencyMap[link.udep_deprel];
......
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