Skip to content

Commit

Permalink
Updated data response model
Browse files Browse the repository at this point in the history
  • Loading branch information
sahalali committed Jul 2, 2024
1 parent b9c4c72 commit d2956cd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/constant/recon-queries.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ SELECT DISTINCT
?name
?type
?type_label
?disambiguatingDescription
?disambiguatingDescription_en
?disambiguatingDescription_fr
?description
?description_en
?description_fr
WHERE
{
values ?query { "QUERY_PLACE_HOLDER" }
Expand All @@ -41,11 +41,11 @@ WHERE
BIND(COALESCE(?type_label_en, ?type_label_raw, "") as ?type_label)
# DISAMBIGUATING DESCRIPTION
OPTIONAL { ?entity schema:disambiguatingDescription ?disambiguatingDescription_en. FILTER( LANG(?disambiguatingDescription_en) = "en") }
OPTIONAL { ?entity schema:disambiguatingDescription ?disambiguatingDescription_fr. FILTER( LANG(?disambiguatingDescription_fr) = "fr")}
OPTIONAL { ?entity schema:disambiguatingDescription ?disambiguatingDescription. FILTER ( LANG(?disambiguatingDescription) = "")}
OPTIONAL { ?entity schema:disambiguatingDescription ?description_en. FILTER( LANG(?description_en) = "en") }
OPTIONAL { ?entity schema:disambiguatingDescription ?description_fr. FILTER( LANG(?description_fr) = "fr")}
OPTIONAL { ?entity schema:disambiguatingDescription ?description. FILTER ( LANG(?description) = "")}
} group by ?entity ?score ?name_en ?name_fr ?name ?type ?type_label ?disambiguatingDescription_en ?disambiguatingDescription_fr ?disambiguatingDescription
} group by ?entity ?score ?name_en ?name_fr ?name ?type ?type_label ?description_en ?description_fr ?description
`

};
15 changes: 9 additions & 6 deletions src/dto/recon.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ class ReconciliationType {
name: string;
}

export class MultilingualString {
export class MultilingualValues {
@ApiProperty()
en: string;
str: string;
@ApiProperty()
fr: string;
@ApiProperty()
none: string;
lang?: string;
}

class MultilingualString {
@ApiProperty({ type: [MultilingualValues] })
values: MultilingualValues[];
}

export class ReconciliationResponse {
Expand All @@ -22,7 +25,7 @@ export class ReconciliationResponse {
@ApiProperty({ type: [MultilingualString] })
name: MultilingualString;
@ApiProperty({ type: [MultilingualString] })
disambiguatingDescription: MultilingualString;
description: MultilingualString;
@ApiProperty({ type: [ReconciliationType] })
type: ReconciliationType[];
@ApiProperty()
Expand Down
6 changes: 6 additions & 0 deletions src/enum/reconciliation-types.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ export enum ReconciliationTypesEnum {
PLACE = "schema:Place",
PERSON = "schema:Person",
ORGANIZATION = "schema:Organization"
}


export enum LanguageTagEnum {
ENGLISH = "en",
FRENCH = "fr"
}
53 changes: 41 additions & 12 deletions src/helper/reconciliation-service.helper.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
import { MultilingualString, ReconciliationResponse } from "../dto";
import { MultilingualValues, ReconciliationResponse } from "../dto";
import { LanguageTagEnum } from "../enum";
import { GRAPHDB_INDEX } from "../config";

export class ReconciliationServiceHelper {

static formatReconciliationResponse(query: string, sparqlResponse: any): ReconciliationResponse[] {

return sparqlResponse?.results?.bindings?.map((binding: any) => {
const nameValues: MultilingualValues[] = [];
const descriptionValues: MultilingualValues[] = [];

const result = new ReconciliationResponse();
result.id = binding["entity"].value;
result.disambiguatingDescription = new MultilingualString();
result.disambiguatingDescription.none = binding["disambiguatingDescription"]?.value;
result.disambiguatingDescription.en = binding["disambiguatingDescription_en"]?.value;
result.disambiguatingDescription.fr = binding["disambiguatingDescription_fr"]?.value;
result.name = new MultilingualString();
result.name.none = binding["name"]?.value;
result.name.en = binding["name_en"]?.value;
result.name.fr = binding["name_fr"]?.value;
const uri = binding["entity"].value;
result.id = uri?.split("http://kg.artsdata.ca/resource/").pop();

//NAME
const name = binding["name"]?.value;
const nameEn = binding["name_en"]?.value;
const nameFr = binding["name_fr"]?.value;
if (nameEn) {
nameValues.push({ str: nameEn, lang: LanguageTagEnum.ENGLISH });
}
if (nameFr) {
nameValues.push({ str: nameFr, lang: LanguageTagEnum.FRENCH });
}
if (name && !nameEn || !nameFr) {
nameValues.push({ str: name });
}
result.name = { values: nameValues };

//DESCRIPTION
const description = binding["description"]?.value;
const descriptionEn = binding["description_en"]?.value;
const descriptionFr = binding["description_fr"]?.value;
if (descriptionEn) {
descriptionValues.push({ str: descriptionEn, lang: LanguageTagEnum.ENGLISH });
}
if (descriptionFr) {
descriptionValues.push({ str: descriptionFr, lang: LanguageTagEnum.FRENCH });
}
if (description && !descriptionEn && !descriptionFr) {
descriptionValues.push({ str: description });
}
result.description = { values: descriptionValues };

//SCORE
result.score = binding["score"]?.value;
//TODO match is incorrect when query contains accent characters

//TODO match is incorrect when query contains accented characters
result.match = binding["name"]?.value.toLowerCase() === query.toLowerCase();
result.type = [{ id: binding["type"]?.value, name: binding["typeLabel"]?.value }];
result.type = [{ id: binding["type"]?.value, name: binding["type_label"]?.value }];
return result;
});

Expand Down

0 comments on commit d2956cd

Please sign in to comment.