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

added support for the VIVA textbook corpus

parent 1e557eaf
......@@ -4,11 +4,13 @@ export class ConfigMC {
public static backendApiFilePath: string = "file";
public static backendApiPath: string = "/mc/api/v1.0/";
public static backendApiRawtextPath: string = "rawtext";
public static backendBaseUrl: string = "http://141.20.186.246:5000"; // 141.20.186.246 localhost
public static backendApiValidReffPath: string = "validReff";
public static backendBaseUrl: string = "http://localhost:5000"; // 141.20.186.246 localhost
public static localStorageKeyCorpora: string = "mc/corpora";
public static maxTextLength: number = 2000;
public static perseidsCTSapiBaseUrl: string = "https://cts.perseids.org/api/cts?request=";
public static perseidsCTSapiGetCapabilities: string = "GetCapabilities";
public static perseidsCTSapiGetValidReff = "GetValidReff";
public static perseidsCTSapiUrnSnippet = "&urn=";
public static perseidsCTSapiGetValidReff: string = "GetValidReff";
public static perseidsCTSapiUrnSnippet: string = "&urn=";
public static vivaURN: string = "urn:custom:latinLit:viva.lat";
}
\ No newline at end of file
export class Citation {
public level: string;
public label: string;
public value: number;
public validReff: Citation[];
constructor(init?:Partial<Citation>) {
Object.assign(this, init);
}
}
......@@ -14,12 +14,12 @@
<ion-content padding>
<ion-grid>
<ion-grid *ngIf="corpusProvider.currentCorpus.subCorpora['']; else loading">
<ion-row>
<ion-col><h1>{{ 'START' | translate }}</h1></ion-col>
<ion-col><h1>{{ 'END' | translate }}</h1></ion-col>
</ion-row>
<ion-row *ngIf="corpusProvider.currentCorpus.subCorpora['']; else loading">
<ion-row>
<ion-col>
<ion-label>
{{corpusProvider.currentCorpus.citation_level_1}}
......@@ -100,7 +100,7 @@
<ion-row>
<ion-col></ion-col>
<ion-col>
<button type="button" ion-button icon-only (click)="copyStartToEnd()">
<button type="button" ion-button icon-only (click)="copyStartToEnd().then()">
<ion-icon name="copy"></ion-icon>
</button>
</ion-col>
......
......@@ -6,6 +6,7 @@ import {CitationLevel} from "../../models/enum";
import {ShowTextPage} from "../show-text/show-text";
import {TextRange} from "../../models/textRange";
import {TranslateService} from "@ngx-translate/core";
import {Citation} from "../../models/citation";
/**
* Generated class for the CorpusDetailPage page.
......@@ -20,6 +21,7 @@ import {TranslateService} from "@ngx-translate/core";
templateUrl: 'corpus-detail.html',
})
export class CorpusDetailPage {
// TODO: rebuild the system so it works for any corpus of arbitrary citation depth
public showMultiPartText: boolean = false;
private noTextRangeChosenString: string;
public CitationLevel = CitationLevel;
......@@ -34,12 +36,20 @@ export class CorpusDetailPage {
start: ["", "", ""],
end: ["", "", ""]
});
if (!this.corpusProvider.currentCorpus.subCorpora[""]) {
this.corpusProvider.getCTSvalidReff(this.corpusProvider.currentCorpus.source_urn).subscribe((resultXML: string) => {
this.corpusProvider.xml2jsParser.parseString(resultXML, (err, result: object) => {
if (!this.corpusProvider.currentCorpus.subCorpora[""] || this.corpusProvider.currentCorpus !== this.corpusProvider.previousCorpus) {
this.corpusProvider.areCitationsComplete = false;
this.corpusProvider.getCTSvalidReff(this.corpusProvider.currentCorpus.source_urn).subscribe((result: string | object) => {
if (typeof result === "object") {
// this is a custom corpus
let textparts: object[] = result["textparts"];
this.corpusProvider.currentCitations = textparts.map(x => x["citation"]) as Citation[];
this.corpusProvider.currentCorpus.subCorpora[""] = this.corpusProvider.currentCitations.map(x => x.label);
}
else {
this.corpusProvider.xml2jsParser.parseString(result, (err, result: object) => {
this.addReferences(result, "");
}
);
});
}
});
}
this.translateService.get("NO_TEXT_RANGE_CHOSEN").subscribe((value) => {
......@@ -89,11 +99,20 @@ export class CorpusDetailPage {
if (!(urn in this.corpusProvider.currentCorpus.subCorpora)) {
// append new references and make them visible
let fullUrn: string = this.corpusProvider.currentCorpus.source_urn + ":" + urn;
this.corpusProvider.getCTSvalidReff(fullUrn).subscribe((resultXML: string) => {
this.corpusProvider.xml2jsParser.parseString(resultXML, (err, result: object) => {
this.corpusProvider.getCTSvalidReff(fullUrn).subscribe((result: string | object) => {
if (typeof result === "object") {
// this is a custom corpus
let textparts: object[] = result["textparts"];
let urnFirstPart: string = urn.split(".")[0];
let parentIndex: number = this.corpusProvider.currentCitations.findIndex(x => x.label === urnFirstPart && x.level === this.corpusProvider.currentCorpus.citation_level_1);
this.corpusProvider.currentCitations[parentIndex].validReff = textparts.map(x => x["citation"]) as Citation[];
this.corpusProvider.currentCorpus.subCorpora[urn] = this.corpusProvider.currentCitations[parentIndex].validReff.map(x => x.label);
}
else {
this.corpusProvider.xml2jsParser.parseString(result, (err, result: object) => {
this.addReferences(result, urn, ".");
}
);
});
}
});
}
// , (error: HttpErrorResponse) => {
......@@ -147,13 +166,30 @@ export class CorpusDetailPage {
}
private adjustCurrentTextRange() {
if (this.corpusProvider.currentCitations.length > 0 && !this.corpusProvider.areCitationsComplete) {
// for custom corpora: add nested citations to the already existing parent citations
let citationsWithSubCitations: Citation[] = this.corpusProvider.currentCitations.filter(x => x.hasOwnProperty("validReff"));
let nestedSubCitations: Citation[][] = citationsWithSubCitations.map(x => x.validReff);
let flattenedSubCitations: Citation[] = [].concat.apply([], nestedSubCitations);
this.corpusProvider.currentCitations = this.corpusProvider.currentCitations.concat(flattenedSubCitations);
this.corpusProvider.previousCorpus = this.corpusProvider.currentCorpus;
this.corpusProvider.areCitationsComplete = true;
}
let newUrnStart: string = "";
let newUrnEnd: string = "";
for (let i in this.corpusProvider.currentTextRange.start) {
for (let i in this.corpusProvider.currentTextRange.start) {
if (this.corpusProvider.currentTextRange.start[+i]) {
if (!this.corpusProvider.currentTextRange.end[+i]) {
this.corpusProvider.currentTextRange.end[+i] = this.corpusProvider.currentTextRange.start[+i];
}
if (this.corpusProvider.currentCitations.length > 0) {
// adjust range for custom corpus
let citationLevel: string = +i === 0 ? this.corpusProvider.currentCorpus.citation_level_1 : this.corpusProvider.currentCorpus.citation_level_2;
let relevantStartCitation: Citation = this.corpusProvider.currentCitations.find(x => x.level === citationLevel && x.label === this.corpusProvider.currentTextRange.start[+i]);
this.corpusProvider.currentTextRange.start[+i] = relevantStartCitation.value.toString();
let relevantEndCitation: Citation = this.corpusProvider.currentCitations.find(x => x.level === citationLevel && x.label === this.corpusProvider.currentTextRange.end[+i]);
this.corpusProvider.currentTextRange.end[+i] = relevantEndCitation.value.toString();
}
newUrnStart += (newUrnStart ? "." : "") + this.corpusProvider.currentTextRange.start[+i];
newUrnEnd += (newUrnEnd ? "." : "") + this.corpusProvider.currentTextRange.end[+i];
}
......
......@@ -25,8 +25,9 @@ export class HomePage {
}
test() {
let a = ["5", "6"];
let c = a.join(".");
let b = 0;
let a = ["a", "b"];
for (let i in a) {
let c = 0;
}
}
}
......@@ -10,6 +10,7 @@ import {Reply} from "../../models/reply";
import {Reff} from "../../models/reff";
import {ConfigMC} from "../../config";
import {TextRange} from "../../models/textRange";
import {Citation} from "../../models/citation";
/*
Generated class for the CorpusProvider provider.
......@@ -28,6 +29,9 @@ export class CorpusProvider {
public currentText: string = "";
public currentTextRange: TextRange = new TextRange({start: ["", "", ""], end: ["", "", ""]});
public currentLastUrnPart: string = "";
public currentCitations: Citation[] = [];
public previousCorpus: CorpusMC;
public areCitationsComplete: boolean = false;
constructor(public translate: TranslateService,
public http: HttpClient) {
......@@ -76,7 +80,11 @@ export class CorpusProvider {
}
getCTSvalidReff(urn: string) {
let fullUrl = ConfigMC.perseidsCTSapiBaseUrl + ConfigMC.perseidsCTSapiGetValidReff + ConfigMC.perseidsCTSapiUrnSnippet + urn;
if (urn.includes(ConfigMC.vivaURN)){
let fullUrl: string = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiValidReffPath;
return this.http.get(fullUrl, {params: {"urn": urn}});
}
let fullUrl: string = ConfigMC.perseidsCTSapiBaseUrl + ConfigMC.perseidsCTSapiGetValidReff + ConfigMC.perseidsCTSapiUrnSnippet + urn;
return this.http.get(fullUrl, {responseType: 'text'});
}
......
Supports Markdown
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