Commit 32e97c8f authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

fixed the annisResponse model

parent 3ae42866
{
"name": "mc_frontend",
"version": "0.9.9",
"version": "1.0.0",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
......
......@@ -236,7 +236,7 @@ export class CorpusService {
processAnnisResponse(ar: AnnisResponse, saveToCache: boolean = true) {
Object.keys(this.phenomenonMap).forEach(key => this.phenomenonMap[key][2] = {});
this.phenomenonMap[Phenomenon.lemma][0] = {};
ar.graph.nodes.forEach((node: NodeMC) => {
ar.nodes.forEach((node: NodeMC) => {
let existingValue = this.phenomenonMap[Phenomenon.lemma][2][node.udep_lemma];
this.phenomenonMap[Phenomenon.lemma][2][node.udep_lemma] = (existingValue ? existingValue : 0) + 1;
this.phenomenonMap[Phenomenon.lemma][0][node.udep_lemma] = node.udep_lemma;
......@@ -258,7 +258,7 @@ export class CorpusService {
});
// init the display with a (almost) random value
this.exercise.queryItems[0].values = [Object.keys(this.phenomenonMap[Phenomenon.partOfSpeech][2])[0]];
const pointingLinks: LinkMC[] = ar.graph.links.filter(x => x.annis_component_type === 'Pointing');
const pointingLinks: LinkMC[] = ar.links.filter(x => x.annis_component_type === 'Pointing');
pointingLinks.forEach((link: LinkMC) => {
const dep: DependencyValue = HelperService.dependencyMap[link.udep_deprel];
if (dep) {
......@@ -267,13 +267,13 @@ export class CorpusService {
}
});
// need to add root dependencies manually because they are tricky to handle
const nodeIds: string[] = ar.graph.nodes.map(x => x.id);
const nodeIds: string[] = ar.nodes.map(x => x.id);
const nodesWithDependencySet: Set<string> = new Set<string>(pointingLinks.map(x => x.target));
const rootNodeIds: string[] = nodeIds.filter(x => !nodesWithDependencySet.has(x));
this.phenomenonMap[Phenomenon.dependency][2][DependencyValue.root] = rootNodeIds.length;
this.adjustQueryValue(this.exercise.queryItems[0]);
// remove whitespace before punctuation
this.currentText = ar.graph.nodes.map(x => x.annis_tok).join(' ').replace(/[ ]([.,\/#!$%\^&\*;:{}=\-_`~()])/g, (x: string) => {
this.currentText = ar.nodes.map(x => x.annis_tok).join(' ').replace(/[ ]([.,\/#!$%\^&\*;:{}=\-_`~()])/g, (x: string) => {
return x.trim();
});
this.annisResponse = ar;
......@@ -330,7 +330,7 @@ export class CorpusService {
this.currentCorpus = HelperService.mostRecentSetup.currentCorpus;
this.currentTextRange = HelperService.mostRecentSetup.currentTextRange;
this.isTextRangeCorrect = true;
if (this.annisResponse && Object.keys(this.annisResponse.graph).length) {
if (this.annisResponse && this.annisResponse.nodes.length) {
this.processAnnisResponse(this.annisResponse, false);
}
// check if the data is already present
......
import {Graph} from 'src/app/models/graph';
/* tslint:disable:variable-name */
import {Solution} from 'src/app/models/solution';
import {LinkMC} from 'src/app/models/linkMC';
import {NodeMC} from 'src/app/models/nodeMC';
export class AnnisResponse {
public directed: boolean;
public exercise_id: string;
public graph: Graph;
public links: LinkMC[];
public multigraph: boolean;
public nodes: NodeMC[];
public solutions: Solution[];
public uri: string;
/** @dynamic*/
constructor(init?: Partial<AnnisResponse>) {
Object.assign(this, init);
}
......
import {LinkMC} from 'src/app/models/linkMC';
import {NodeMC} from 'src/app/models/nodeMC';
export class Graph {
public directed: boolean;
public graph: object;
public links: LinkMC[];
public multigraph: boolean;
public nodes: NodeMC[];
constructor(init?: Partial<Graph>) {
Object.assign(this, init);
}
}
/* tslint:disable:variable-name */
export class LinkMC {
public annis_component_name: string;
public annis_component_type: string;
......
......@@ -68,14 +68,15 @@ export class PreviewPage implements OnDestroy {
this.corpusService.annisResponse.solutions = ar.solutions;
this.processSolutions(ar.solutions);
this.corpusService.annisResponse.uri = ar.uri;
this.corpusService.annisResponse.graph = this.corpusService.currentUrn.startsWith('urn:') ?
this.corpusService.annisResponse.graph : ar.graph;
const isUrn: boolean = this.corpusService.currentUrn.startsWith('urn:');
this.corpusService.annisResponse.nodes = isUrn ? this.corpusService.annisResponse.nodes : ar.nodes;
this.corpusService.annisResponse.links = isUrn ? this.corpusService.annisResponse.links : ar.links;
}
processSolutions(solutions: Solution[]) {
const isCloze: boolean = this.corpusService.exercise.type === ExerciseType.cloze;
if (this.exerciseService.excludeOOV) {
const nodeIdSet: Set<string> = new Set(this.corpusService.annisResponse.graph.nodes.filter(
const nodeIdSet: Set<string> = new Set(this.corpusService.annisResponse.nodes.filter(
x => !x.is_oov).map(x => x.id));
solutions = this.corpusService.annisResponse.solutions.filter(
x => nodeIdSet.has(x.target.salt_id) && (isCloze || nodeIdSet.has(x.value.salt_id)));
......
......@@ -32,8 +32,8 @@ export class RankingPage {
HelperService.isLoading = true;
this.vocService.getVocabularyCheck(this.corpusService.currentUrn, true).subscribe((ar: AnnisResponse) => {
HelperService.isLoading = false;
const urnStart: string = ar.graph.nodes[0].id.split('/')[1];
const urnEnd: string = ar.graph.nodes.slice(-1)[0].id.split('/')[1];
const urnStart: string = ar.nodes[0].id.split('/')[1];
const urnEnd: string = ar.nodes.slice(-1)[0].id.split('/')[1];
this.corpusService.currentUrn = urnStart.concat('-', urnEnd.split(':').slice(-1)[0]);
this.corpusService.processAnnisResponse(ar);
HelperService.goToShowTextPage(this.navCtrl, true);
......
......@@ -65,7 +65,7 @@
<ion-col class="text">
<div *ngIf="highlightOOV; else noOOV">
<!-- do not add whitespace/newline etc. between the span elements! -->
<span *ngFor="let node of corpusService.annisResponse.graph.nodes; index as i"><span class="tok"
<span *ngFor="let node of corpusService.annisResponse.nodes; index as i"><span class="tok"
[class.oov]="node.is_oov">{{node.annis_tok}}</span>{{ getWhiteSpace(i) }}</span>
</div>
<ng-template #noOOV>
......
......@@ -70,8 +70,8 @@ export class ShowTextPage {
}
getWhiteSpace(index: number) {
if (this.corpusService.annisResponse.graph.nodes[index + 1]) {
if ('.,\\/#!$%\\^&\\*;:{}=\\-_`~()'.indexOf(this.corpusService.annisResponse.graph.nodes[index + 1].annis_tok) > -1) {
if (this.corpusService.annisResponse.nodes[index + 1]) {
if ('.,\\/#!$%\\^&\\*;:{}=\\-_`~()'.indexOf(this.corpusService.annisResponse.nodes[index + 1].annis_tok) > -1) {
return '';
}
return ' ';
......
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