Commit a83ead48 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Fixed selection of literals by language

parent 830419382dbe
......@@ -71,6 +71,20 @@ export interface MetaProperty {
load(entity: RdfEntity, languages: Language[], resolver: ObjectResolver): any;
}
/**
* A literal node associated to a rank
*/
interface RankedLiteral {
/**
* The literal
*/
literal: $rdf.Literal;
/**
* The associated rank
*/
rank: number;
}
/**
* Represents the meta data about a data property
*/
......@@ -119,22 +133,28 @@ export class MetaPropertyData implements MetaProperty {
let literals = entity.getValuesForS(this.uri);
literals = literals.filter((node: $rdf.Node) => node.termType == "Literal");
if (literals.length == 0) return this.isVector ? [] : null;
let matching = literals
.filter((literal: $rdf.Literal) => {
.map((literal: $rdf.Literal) => {
for (var l = 0; l != languages.length; l++) {
if (
literal.lang == languages[l].iso639_1 ||
literal.lang == languages[l].iso639_2
)
return true;
return { literal: literal, rank: l } as RankedLiteral;
}
return false;
return { literal: literal, rank: languages.length } as RankedLiteral;
})
.map((literal: $rdf.Literal) => literal.value);
if (matching.length != 0) return this.isVector ? matching : matching[0];
return this.isVector
? literals.map((literal: $rdf.Literal) => literal.value)
: literals[0].value;
.sort((a: RankedLiteral, b: RankedLiteral) => a.rank - b.rank);
if (!this.isVector) return matching[0].literal.value;
return matching
.map(
(rl: RankedLiteral) =>
rl.rank == matching[0].rank ? rl.literal.value : null
)
.filter((value: string) => value != null);
}
}
......
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