From 9cd558202e5c540a46c7ed04a229b01029188f7e Mon Sep 17 00:00:00 2001 From: Vijeinath Tissaveerasingham Date: Thu, 3 Dec 2020 15:58:31 +0100 Subject: [PATCH] Adaptation to performedByActor --- .../advanced-search.component.html | 11 +-- .../advanced-search.component.ts | 81 +++++++++++++------ src/app/search/results/pipe/comments.pipe.ts | 61 +++++++++----- src/app/search/results/results.component.ts | 15 ++++ .../services/gravsearch-builder.service.ts | 18 ++--- src/app/services/notes.txt | 2 +- 6 files changed, 129 insertions(+), 59 deletions(-) diff --git a/src/app/search/advanced-search/advanced-search.component.html b/src/app/search/advanced-search/advanced-search.component.html index 73a18e2e..c7b941a3 100644 --- a/src/app/search/advanced-search/advanced-search.component.html +++ b/src/app/search/advanced-search/advanced-search.component.html @@ -202,11 +202,12 @@ - - - - - + + + + + + diff --git a/src/app/search/advanced-search/advanced-search.component.ts b/src/app/search/advanced-search/advanced-search.component.ts index 06abd080..c5de2d8c 100644 --- a/src/app/search/advanced-search/advanced-search.component.ts +++ b/src/app/search/advanced-search/advanced-search.component.ts @@ -204,6 +204,26 @@ export class AdvancedSearchComponent implements OnInit { } ] } + }, + { + name: "performedByActor", + priority: 1, + res: { + name: "person", + props: [ + { + name: "hasFirstName", + priority: 1, + mandatory: true, + res: null + }, + { + name: "hasLastName", + priority: 1, + res: null + } + ] + } } ] } @@ -347,6 +367,7 @@ export class AdvancedSearchComponent implements OnInit { createdDateRef: IDisplayedProperty; performedCompanyRef: IDisplayedProperty; performedVenueRef: IDisplayedProperty; + performedActorRef: IDisplayedProperty; genders: any[]; genres: any[]; @@ -369,9 +390,9 @@ export class AdvancedSearchComponent implements OnInit { } ngOnInit() { - // this.prepareActors(); - this.prepareVenues(); this.prepareCompanies(); + this.prepareVenues(); + this.prepareActors(); const genresNode = this.listService.getList("genre").nodes; this.genres = genresNode.reduce((acc, list) => this.treeTableService.flattenTree(acc, list), []); @@ -400,6 +421,7 @@ export class AdvancedSearchComponent implements OnInit { this.createdDateRef = this.myPassage.props[12].res.props[7]; this.performedCompanyRef = this.myPassage.props[12].res.props[12]; this.performedVenueRef = this.myPassage.props[12].res.props[13]; + this.performedActorRef = this.myPassage.props[12].res.props[14]; this.form = new FormGroup({ text: new FormControl("", []), @@ -419,35 +441,33 @@ export class AdvancedSearchComponent implements OnInit { }); } - prepareActors() { - this.knoraService.getActorsCount() + prepareCompanies() { + this.knoraService.getCompaniesCount() .subscribe(amount => { const maxOffset = Math.ceil(amount / 25); const requests = []; for (let offset = 0; offset < maxOffset; offset++) { - requests.push(this.knoraService.getActors(offset)); + requests.push(this.knoraService.getCompanies(offset)); } forkJoin(...requests) .subscribe((res: Array>) => { - this.actors = [] + this.companies = [] .concat(...res) - .map(actor => { - if (actor.hasLastName.length === 1) { - actor.hasLastName = actor.hasLastName[0].value; - } - if (actor.hasFirstName.length === 1) { - actor.hasFirstName = actor.hasFirstName[0].value; + .map(company => { + if (company.hasCompanyTitle.length === 1) { + company.hasCompanyTitle = company.hasCompanyTitle[0].value; + return company; } - return actor; }) - .sort((res1, res2) => this.sortActors(res1, res2)); + .sort((res1, res2) => this.sortCompanies(res1, res2)); }, error => { requests.map(a => a.unsubscribe()); }); }); + } prepareVenues() { @@ -479,33 +499,36 @@ export class AdvancedSearchComponent implements OnInit { }); } - prepareCompanies() { - this.knoraService.getCompaniesCount() + prepareActors() { + this.knoraService.getActorsCount() .subscribe(amount => { const maxOffset = Math.ceil(amount / 25); const requests = []; for (let offset = 0; offset < maxOffset; offset++) { - requests.push(this.knoraService.getCompanies(offset)); + requests.push(this.knoraService.getActors(offset)); } forkJoin(...requests) .subscribe((res: Array>) => { - this.companies = [] + this.actors = [] .concat(...res) - .map(company => { - if (company.hasCompanyTitle.length === 1) { - company.hasCompanyTitle = company.hasCompanyTitle[0].value; - return company; + .map(actor => { + if (actor.hasLastName.length === 1) { + actor.hasLastName = actor.hasLastName[0].value; } + if (actor.hasFirstName.length === 1) { + actor.hasFirstName = actor.hasFirstName[0].value; + } + return actor; }) - .sort((res1, res2) => this.sortCompanies(res1, res2)); + .sort((res1, res2) => this.sortActors(res1, res2)); + console.log(this.actors); }, error => { requests.map(a => a.unsubscribe()); }); }); - } search() { @@ -520,6 +543,7 @@ export class AdvancedSearchComponent implements OnInit { && !this.form.get("createdDate").value && !this.form.get("performedCompany").value && !this.form.get("performedVenue").value + // && !this.form.get("performedActor").value && (!this.form.get("plays").value && !this.form.get("genre").value)) { const dialogConfig = new MatDialogConfig(); @@ -624,6 +648,14 @@ export class AdvancedSearchComponent implements OnInit { this.performedVenueRef.priority = 1; } + // if (this.form.get("performedActor").value) { + // this.performedActorRef.searchVal1 = this.form.get("performedActor").value; + // this.performedActorRef.priority = 0; + // } else { + // this.performedActorRef.searchVal1 = null; + // this.performedActorRef.priority = 1; + // } + if (this.form.get("plays").value) { // Only plays means if genre is "Drama (Theatre)" this.genreRef.searchVal1 = this.listService.getIdOfNode("ALL DRAMA"); @@ -712,6 +744,7 @@ export class AdvancedSearchComponent implements OnInit { this.form.get("createdDate").reset(""); this.form.get("performedCompany").reset(""); this.form.get("performedVenue").reset(""); + // this.form.get("performedActor").reset(""); this.form.get("plays").setValue(false); } diff --git a/src/app/search/results/pipe/comments.pipe.ts b/src/app/search/results/pipe/comments.pipe.ts index b569baf1..ec4f1332 100644 --- a/src/app/search/results/pipe/comments.pipe.ts +++ b/src/app/search/results/pipe/comments.pipe.ts @@ -21,7 +21,30 @@ export class CommentsPipe implements PipeTransform { const firstPerDate = book.hasFirstPerformanceDate ? (book.hasFirstPerformanceDate[0].start === book.hasFirstPerformanceDate[0].end ? `in ${book.hasFirstPerformanceDate[0].start}` : `between ${book.hasFirstPerformanceDate[0].start} and ${book.hasFirstPerformanceDate[0].end}`) : null; const firstPrintDate = book.hasPublicationDate ? (book.hasPublicationDate[0].start === book.hasPublicationDate[0].end ? `in ${book.hasPublicationDate[0].start}` : `between ${book.hasPublicationDate[0].start} and ${book.hasPublicationDate[0].end}`) : null; const perByCom = book.performedBy ? (book.performedBy.length === 2 ? `${book.performedBy[0].hasCompanyTitle[0].value} or ${book.performedBy[1].hasCompanyTitle[0].value}` : `${book.performedBy[0].hasCompanyTitle[0].value}`) : null; - const personPerIn = null; + let perByActors = null; + if (book.performedByActor) { + const actors = book.performedByActor + .map(author => (author.hasFirstName && author.hasFirstName[0].value !== "_") ? {firstName: author.hasFirstName[0].value, lastName: author.hasLastName[0].value} : + {lastName: author.hasLastName[0].value} + ) + .sort((author1, author2) => author1.lastName < author2.lastName ? -1 : (author1.lastName > author2.lastName ? 1 : 0) + ) + .map((author) => + // Capitalize first name before string concatenation + author.firstName ? `${author.firstName.charAt(0).toUpperCase() + author.firstName.slice(1)} ${author.lastName}` : `${author.lastName.charAt(0).toUpperCase() + author.lastName.slice(1)}` + ); + + const numActors = actors.length; + const lastAuthor = actors[actors.length - 1]; + // Concatenates last two authors with "and". Ignores if there is only one author. + if (numActors > 1) { + const secondLast = actors[numActors - 2]; + actors.splice(numActors - 2, 2, `${secondLast} and ${lastAuthor}`); + } + + perByActors = actors + .join(", "); + } let perInVen = null; if (book.performedIn) { if (book.performedIn.length === 2) { @@ -40,44 +63,44 @@ export class CommentsPipe implements PipeTransform { const firstPerDateCode = firstPerDate ? "1" : "0"; const firstPrintDateCode = firstPrintDate ? "1" : "0"; const perByComCode = perByCom ? "1" : "0"; - const personPerInCode = personPerIn ? "1" : "0"; + const perByActorsCode = perByActors ? "1" : "0"; const perInVenCode = perInVen ? "1" : "0"; - const fullCode = `${firstPrintDateCode}${perInVenCode}${personPerInCode}${perByComCode}${firstPerDateCode}${genreCode}`; + const fullCode = `${firstPrintDateCode}${perInVenCode}${perByActorsCode}${perByComCode}${firstPerDateCode}${genreCode}`; const codeObject = { "000001": ``, "000011": `This ${genre} was first performed ${firstPerDate}.`, "000101": `This ${genre} was first performed by ${perByCom}.`, "000111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}.`, - "001001": `The cast of the first performance of this ${genre} included ${personPerIn}.`, - "001011": `This ${genre} was first performed ${firstPerDate}. The cast included ${personPerIn}.`, - "001101": `This ${genre} was first performed by ${perByCom}. The cast included ${personPerIn}.`, - "001111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${personPerIn}.`, + "001001": `The cast of the first performance of this ${genre} included ${perByActors}.`, + "001011": `This ${genre} was first performed ${firstPerDate}. The cast included ${perByActors}.`, + "001101": `This ${genre} was first performed by ${perByCom}. The cast included ${perByActors}.`, + "001111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${perByActors}.`, "010001": `This ${genre} was first performed at ${perInVen}.`, "010011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}.`, "010101": `This ${genre} was first performed by ${perByCom} at ${perInVen}.`, "010111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}.`, - "011001": `This ${genre} was first performed at ${perInVen}. The cast included ${personPerIn}.`, - "011011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}.`, - "011101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${personPerIn}.`, - "011111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}.`, + "011001": `This ${genre} was first performed at ${perInVen}. The cast included ${perByActors}.`, + "011011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${perByActors}.`, + "011101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${perByActors}.`, + "011111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${perByActors}.`, "100001": `This ${genre} was first printed ${firstPrintDate}`, "100011": `This ${genre} was first performed ${firstPerDate}. The text was first printed ${firstPrintDate}.`, "100101": `This ${genre} was first performed by ${perByCom}. The text was first printed ${firstPrintDate}.`, "100111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The text was first printed ${firstPrintDate}.`, - "101001": `The cast of the first performance of this ${genre} included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "101011": `This ${genre} was first performed ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "101101": `This ${genre} was first performed by ${perByCom}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "101111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, + "101001": `The cast of the first performance of this ${genre} included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "101011": `This ${genre} was first performed ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "101101": `This ${genre} was first performed by ${perByCom}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "101111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, "110001": `This ${genre} was first performed at ${perInVen}. The text was first printed ${firstPrintDate}.`, "110011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The text was first printed ${firstPrintDate}.`, "110101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The text was first printed ${firstPrintDate}.`, "110111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The text was first printed ${firstPrintDate}.`, - "111001": `This ${genre} was first performed at ${perInVen}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "111011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "111101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`, - "111111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.` + "111001": `This ${genre} was first performed at ${perInVen}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "111011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "111101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`, + "111111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.` }; return codeObject[fullCode] ? codeObject[fullCode] : ""; diff --git a/src/app/search/results/results.component.ts b/src/app/search/results/results.component.ts index 0c42f9b6..88aa61c7 100644 --- a/src/app/search/results/results.component.ts +++ b/src/app/search/results/results.component.ts @@ -339,6 +339,21 @@ export class ResultsComponent implements OnInit { } return book; }), + // Checks if book has performedByActors and requests the actors (=persons) + mergeMap((book: any) => { + if (book.performedByActor) { + return forkJoin([of(book), from(book.performedByActor) + .pipe(mergeMap((actor: any) => this.knoraService.getPassageRes(actor.id)), toArray())]); + } else { + return forkJoin([of(book), of("empty")]); + } + }), + map(([book, actors]) => { + if (actors !== "empty") { + book.performedByActor = actors; + } + return book; + }), // Requests the authors of the book mergeMap((book: any) => forkJoin([of(book), from(book.isWrittenBy) .pipe( diff --git a/src/app/services/gravsearch-builder.service.ts b/src/app/services/gravsearch-builder.service.ts index 30d7b292..094a2474 100644 --- a/src/app/services/gravsearch-builder.service.ts +++ b/src/app/services/gravsearch-builder.service.ts @@ -62,12 +62,6 @@ export class GravsearchBuilderService { type: "Resource", res: "lexia", queryStr: this.getQueryStr(GravsearchBuilderService.PERSON_VAR, "isLexiaPerson", "lexiaPerson") - }, - personPerformedIn: { - cardinality: "0-1", - type: "Resource", - res: "book", - queryStr: this.getQueryStr(GravsearchBuilderService.PERSON_VAR, "personPerformedIn", "personPerformedIn") } }; @@ -147,6 +141,12 @@ export class GravsearchBuilderService { res: "company", queryStr: this.getQueryStr(GravsearchBuilderService.BOOK_VAR, "performedBy", "performedCompany") }, + performedByActor: { + cardinality: "0-1", + type: "Resource", + res: "person", + queryStr: this.getQueryStr(GravsearchBuilderService.PERSON_VAR, "performedByActor", "actor") + }, performedIn: { cardinality: "0-n", type: "Resource", @@ -733,16 +733,14 @@ export class GravsearchBuilderService { "", "CONSTRUCT {", `${this.getFirstConstructLine(node).join("")}`, - "?person teimww:hasPersonInternalId ?personInternalId .", + "?book teimww:performedByActor ?person .", "?person teimww:hasFirstName ?firstName .", "?person teimww:hasLastName ?lastName .", "} WHERE {", `${this.getFirstWhereLine(node).join("")}`, - "?person teimww:hasPersonInternalId ?personInternalId .", + "?book teimww:performedByActor ?person .", "OPTIONAL { ?person teimww:hasFirstName ?firstName . }", "?person teimww:hasLastName ?lastName .", - // Adapt next line if direction of property is changed - "?person teimww:personPerformedIn ?book .", "}", "", `OFFSET ${offset ? offset : 0}` diff --git a/src/app/services/notes.txt b/src/app/services/notes.txt index 170738a3..d5336921 100644 --- a/src/app/services/notes.txt +++ b/src/app/services/notes.txt @@ -40,7 +40,6 @@ Person hasActiveDate 0-1 hasGender 1 isLexiaPerson (Lexia) 0-n - personPerformedIn (Book) 0-n hasPersonExtraInfo 0-1 Book @@ -58,6 +57,7 @@ Book hasBookComment 0-1 isWrittenBy (Person) 1-n performedBy (Company) 0-n + performedByActor (Person) 0-n performedIn (Venue) 0-n isLexiaBook (Lexia) 0-n hasBookExtraInfo 0-1