Skip to content

Commit c1baf6c

Browse files
authored
Merge pull request #477 from kbss-cvut/development
[3.1.1] Release
2 parents f336cde + 915154a commit c1baf6c

10 files changed

+151
-10
lines changed

NEWS.cs.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### Verze 3.1.1
2+
3+
- Opravy chyb, aktualizace knihoven.
4+
15
#### Verze 3.1.0
26

37
- Přidána možnost zvýraznit v anotátoru výskyty vybraného pojmu.

NEWS.en.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### Version 3.1.1
2+
3+
- Bug fixes, dependency updates.
4+
15
#### Version 3.1.0
26

37
- Added the possibility to highlight occurrences of the selected term in annotator.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "termit-ui",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"private": true,
55
"homepage": ".",
66
"license": "GPL-3.0-only",

src/component/genericmetadata/UnmappedProperties.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ const UnmappedProperties: React.FC<UnmappedPropertiesProps> = (
2424
</div>
2525
) : null;
2626
}
27-
const result: JSX.Element[] = [];
27+
const result: React.JSX.Element[] = [];
2828
props.properties.forEach((values, k) => {
29+
if (values.length === 0) {
30+
return;
31+
}
2932
const sortedItems = values.map((v) =>
3033
(v as { iri: string }).iri ? (v as { iri: string }).iri : (v as string)
3134
);

src/model/MultilingualString.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ export function context(propertyIri: string) {
99
};
1010
}
1111

12+
export function pluralContext(propertyIri: string) {
13+
return {
14+
"@id": propertyIri,
15+
"@container": ["@language", "@set"],
16+
};
17+
}
18+
1219
export interface MultilingualString {
1320
[key: string]: string;
1421
}

src/model/Term.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ import {
1616
import MultilingualString, {
1717
context,
1818
getLocalized,
19+
pluralContext,
1920
PluralMultilingualString,
2021
} from "./MultilingualString";
2122
import { SupportsSnapshots } from "./Snapshot";
2223
import { getLanguages, removeTranslation } from "../util/IntlUtil";
2324

2425
const ctx = {
2526
label: context(VocabularyUtils.SKOS_PREF_LABEL),
26-
altLabels: context(VocabularyUtils.SKOS_ALT_LABEL),
27-
hiddenLabels: context(VocabularyUtils.SKOS_HIDDEN_LABEL),
27+
altLabels: pluralContext(VocabularyUtils.SKOS_ALT_LABEL),
28+
hiddenLabels: pluralContext(VocabularyUtils.SKOS_HIDDEN_LABEL),
2829
definition: context(VocabularyUtils.DEFINITION),
2930
scopeNote: context(VocabularyUtils.SKOS_SCOPE_NOTE),
3031
parentTerms: VocabularyUtils.BROADER,
@@ -38,7 +39,7 @@ const ctx = {
3839
state: VocabularyUtils.HAS_TERM_STATE,
3940
glossary: VocabularyUtils.SKOS_IN_SCHEME,
4041
notations: VocabularyUtils.SKOS_NOTATION,
41-
examples: context(VocabularyUtils.SKOS_EXAMPLE),
42+
examples: pluralContext(VocabularyUtils.SKOS_EXAMPLE),
4243
types: "@type",
4344
};
4445

src/util/JsonLdUtils.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { compact, JsonLdContext, JsonLdDictionary, JsonLdInput } from "jsonld";
2+
import Utils from "./Utils";
23

34
/**
45
* Utility functions for processing JSON-LD data.
@@ -18,9 +19,36 @@ export default class JsonLdUtils {
1819
input: JsonLdInput,
1920
context: JsonLdContext
2021
): Promise<T> {
21-
return compact<T>(input, context).then((res) =>
22-
JsonLdUtils.resolveReferences<T>(res, new Map<string, object>())
23-
);
22+
return compact<T>(input, context).then((res) => {
23+
res = JsonLdUtils.removeEmptyPluralLanguageContainers<T>(res, context);
24+
return JsonLdUtils.resolveReferences<T>(res, new Map<string, object>());
25+
});
26+
}
27+
28+
/**
29+
* An empty array is added for plural language containers (context @container = @language and @set) if they are not specified
30+
* in the data. This function removes them, because otherwise they show up as unmapped properties
31+
* (e.g., instead of altLabels, the term would have attribute http://www.w3.org/2004/02/skos/core#altLabel with value []).
32+
* @param input Input object
33+
* @param context JSON-LD context definition
34+
* @private
35+
*/
36+
private static removeEmptyPluralLanguageContainers<
37+
T extends JsonLdDictionary
38+
>(input: T, context: JsonLdContext): T {
39+
Object.keys(context)
40+
.filter((k) => {
41+
return (
42+
Array.isArray(context[k]["@container"]) &&
43+
Utils.arraysAreEqual(context[k]["@container"], [
44+
"@language",
45+
"@set",
46+
]) &&
47+
Utils.sanitizeArray(input[context[k]["@id"]]).length === 0
48+
);
49+
})
50+
.forEach((k) => delete input[context[k]["@id"]]);
51+
return input;
2452
}
2553

2654
/**

src/util/Utils.ts

+23
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,29 @@ const Utils = {
340340
normalizeString(str: string) {
341341
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
342342
},
343+
344+
/**
345+
* Checks if the specified arrays are equal.
346+
* @param a Array
347+
* @param b Array
348+
*/
349+
arraysAreEqual(a: any[], b: any[]) {
350+
if (a === b) {
351+
return true;
352+
}
353+
if (a == null || b == null) {
354+
return false;
355+
}
356+
if (a.length !== b.length) {
357+
return false;
358+
}
359+
for (let i = 0; i < a.length; i++) {
360+
if (a[i] !== b[i]) {
361+
return false;
362+
}
363+
}
364+
return true;
365+
},
343366
};
344367

345368
export default Utils;

src/util/__tests__/JsonLdUtils.test.ts

+71
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import VocabularyUtils from "../VocabularyUtils";
22
import JsonLdUtils from "../JsonLdUtils";
33
import { CONTEXT as VOCABULARY_CONTEXT } from "../../model/Vocabulary";
4+
import { CONTEXT as TERM_CONTEXT, TermData } from "../../model/Term";
45

56
describe("JsonLdUtils", () => {
67
describe("resolveReferences", () => {
@@ -73,6 +74,76 @@ describe("JsonLdUtils", () => {
7374
expect(result.document.vocabulary).toEqual(result);
7475
});
7576
});
77+
78+
it("does not add empty arrays for plural language containers", () => {
79+
const input = {
80+
"@context": {
81+
types: "@type",
82+
sources: "http://purl.org/dc/terms/source",
83+
notations: "http://www.w3.org/2004/02/skos/core#notation",
84+
label: {
85+
"@id": "http://www.w3.org/2004/02/skos/core#prefLabel",
86+
"@container": "@language",
87+
},
88+
uri: "@id",
89+
subTerms: "http://www.w3.org/2004/02/skos/core#narrower",
90+
glossary: "http://www.w3.org/2004/02/skos/core#inScheme",
91+
vocabulary:
92+
"http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/je-pojmem-ze-slovníku",
93+
hiddenLabels: "http://www.w3.org/2004/02/skos/core#hiddenLabel",
94+
examples: "http://www.w3.org/2004/02/skos/core#example",
95+
related: "http://www.w3.org/2004/02/skos/core#related",
96+
relatedMatch: "http://www.w3.org/2004/02/skos/core#relatedMatch",
97+
definition: {
98+
"@id": "http://www.w3.org/2004/02/skos/core#definition",
99+
"@container": "@language",
100+
},
101+
state:
102+
"http://onto.fel.cvut.cz/ontologies/slovník/agendový/popis-dat/pojem/má-stav-pojmu",
103+
parentTerms: "http://www.w3.org/2004/02/skos/core#broader",
104+
altLabels: {
105+
"@id": "http://www.w3.org/2004/02/skos/core#altLabel",
106+
"@container": "@language",
107+
},
108+
exactMatchTerms: "http://www.w3.org/2004/02/skos/core#exactMatch",
109+
},
110+
uri: "http://onto.fel.cvut.cz/ontologies/slovnik/ml-test/pojem/lokalita",
111+
types: [
112+
"http://onto.fel.cvut.cz/ontologies/ufo/object",
113+
"http://www.w3.org/2004/02/skos/core#Concept",
114+
],
115+
label: {
116+
cs: "Lokalita",
117+
en: "Locality",
118+
},
119+
subTerms: [],
120+
notations: [],
121+
definition: {
122+
cs: "Plocha nebo soubor ploch, popřípadě část plochy, vymezená na základě převažujícího charakteru. Upraveno. Ještě přidána explicitně zmíněná testovací plocha, aby se nám přidala do definičně souvisejících pojmů.\n\nDefinice znovu upravena, abychom spustili textovou analýzu. A znovu.",
123+
en: "English definition of the term Locality is just a placeholder proving that multilingual definition works.",
124+
},
125+
sources: [],
126+
altLabels: [],
127+
hiddenLabels: [],
128+
examples: [],
129+
vocabulary: {
130+
uri: "http://onto.fel.cvut.cz/ontologies/slovnik/ml-test",
131+
},
132+
glossary: {
133+
uri: "http://onto.fel.cvut.cz/ontologies/slovnik/ml-test/glosář",
134+
},
135+
state: {
136+
uri: "http://onto.fel.cvut.cz/ontologies/application/termit/pojem/publikovaný-pojem",
137+
},
138+
};
139+
return JsonLdUtils.compactAndResolveReferences(input, TERM_CONTEXT).then(
140+
(result: TermData) => {
141+
expect(result[VocabularyUtils.SKOS_ALT_LABEL]).not.toBeDefined();
142+
expect(result[VocabularyUtils.SKOS_HIDDEN_LABEL]).not.toBeDefined();
143+
expect(result[VocabularyUtils.SKOS_EXAMPLE]).not.toBeDefined();
144+
}
145+
);
146+
});
76147
});
77148

78149
describe("compactAndResolveReferencesAsArray", () => {

0 commit comments

Comments
 (0)