Skip to content

Commit

Permalink
update corpus info component with documentation API
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Jul 31, 2024
1 parent 143c7b0 commit 42e397e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
15 changes: 14 additions & 1 deletion frontend/src/app/corpus-info/corpus-info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { marked } from 'marked';
import { Observable } from 'rxjs';
import { Title } from '@angular/platform-browser';
import { pageTitle } from '../utils/app';
import { map } from 'rxjs/operators';
import * as _ from 'lodash';

@Component({
selector: 'ia-corpus-info',
Expand All @@ -30,7 +32,10 @@ export class CorpusInfoComponent implements OnInit {

setCorpus(corpus: Corpus) {
this.corpus = corpus;
this.documentation$ = this.apiService.corpusDocumentation(corpus.name);
this.documentation$ = this.corpusService.getDocumentation(corpus).pipe(
map(pages => pages.filter(page => this.includePage(corpus, page))),
map(this.sortPages)
);
this.apiService.fieldCoverage(corpus.name).then(
result => this.fieldCoverage = result
);
Expand All @@ -41,4 +46,12 @@ export class CorpusInfoComponent implements OnInit {
return marked.parse(content);
}

private sortPages(pages: CorpusDocumentationPage[]): CorpusDocumentationPage[] {
return _.sortBy(pages, 'index');
}

private includePage(corpus: Corpus, page: CorpusDocumentationPage): boolean {
return page.type !== 'Word models' || corpus.wordModelsPresent;
}

}
4 changes: 4 additions & 0 deletions frontend/src/app/models/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class Corpus {
public languages: string[],
public category: string,
public hasNamedEntities: boolean,
public documentationPageIDs: number[],
public documentContext?: DocumentContext,
public newHighlight?: boolean,
public defaultSort?: SortState,
Expand Down Expand Up @@ -150,6 +151,9 @@ export class CorpusField {
}

export interface CorpusDocumentationPage {
id: number;
corpus: string;
type: string;
content: string;
index?: number;
}
16 changes: 13 additions & 3 deletions frontend/src/app/services/corpus.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable @typescript-eslint/member-ordering */
import { Injectable } from '@angular/core';

import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Observable, combineLatest } from 'rxjs';

import { Corpus, CorpusField, DocumentContext, SortDirection, SortState } from '../models/index';
import { Corpus, CorpusDocumentationPage, CorpusField, DocumentContext, SortDirection, SortState } from '../models/index';
import { ApiRetryService } from './api-retry.service';
import { AuthService } from './auth.service';
import { findByName } from '../utils/utils';
import * as _ from 'lodash';
import { ApiService } from './api.service';

@Injectable({
providedIn: 'root',
Expand All @@ -23,7 +24,8 @@ export class CorpusService {

constructor(
private apiRetryService: ApiRetryService,
private authService: AuthService
private authService: AuthService,
private apiService: ApiService,
) {
this.parseField = this.parseField.bind(this);
}
Expand Down Expand Up @@ -70,6 +72,13 @@ export class CorpusService {
}
}

getDocumentation(corpus: Corpus): Observable<CorpusDocumentationPage[]> {
const requests = corpus.documentationPageIDs.map(
id => this.apiService.corpusDocumentationPage(id)
);
return combineLatest(requests);
}

private async parseCorpusList(data: any): Promise<Corpus[]> {
return data.map(this.parseCorpusItem);
}
Expand All @@ -90,6 +99,7 @@ export class CorpusService {
data.languages,
data.category,
data.has_named_entities,
data.documentation_pages,
this.parseDocumentContext(data.document_context, allFields),
data.new_highlight,
this.parseDefaultSort(data.default_sort, allFields),
Expand Down

0 comments on commit 42e397e

Please sign in to comment.