Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdtt 336 the external terminology of a vocabularium contains a lot of duplicates. introduce a new table #70

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions packages/oslo-generator-html/lib/templates/voc2.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="{{ language }}" lang="{{ language }}" dir="ltr" typeof="bibo:Document " about="" property="dcterms:language" content="{{ language }}" prefix="dcterms: http://purl.org/dc/terms/ bibo: http://purl.org/ontology/bibo/ schema: http://schema.org/ w3p:
http://www.w3.org/2001/02pd/rec54#" xmlns="http://www.w3.org/1999/xhtml">
http://www.w3.org/2001/02pd/rec54#" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{{ data.metadata.title }}</title>
<meta charset='utf-8'/>
Expand Down Expand Up @@ -494,35 +494,32 @@
met hun Nederlandstalige labels en definities.</p>
</div>
{% if data.externalProperties %}
{% for external in data.externalProperties %}
<div class="region region--no-space-top">
<h3 class="h4" id="{{ external.vocabularyLabel[language] }}">
<em>{{ external.vocabularyLabel[language] }}</em>
</h3>
<table class="definition">
<tbody>
<div class="region region--no-space-top">
<table class="definition">
<tbody>
<tr>
<th>Label</th>
<th>Domein</th>
<th>Definitie</th>
<th>Gebruik</th>
</tr>
{% for external in data.externalProperties %}
<tr>
<th>URI</th>
<td id="{{ external.vocabularyLabel[language] }}">
<strong>
<a href="{{ external.id }}" data-toggle="tooltip" data-content="{{ external.id }}">{{ external.vocabularyLabel[language] }}</a>
</strong>
</td>
<td>
<code>{{ external.id }}</code>
<code>{{ external.domain }}</code>
</td>
<td>{{ external.vocabularyDefinition[language] }}</td>
<td>{{ external.vocabularyUsageNote[language] }}</td>
</tr>
{% if external.vocabularyDefinition[language] %}
<tr>
<th>Definitie</th>
<td>{{ external.vocabularyDefinition[language] }}</td>
</tr>
{% endif %}
{% if external.vocabularyUsageNote[language] %}
<tr>
<th>Gebruik</th>
<td>{{ external.vocabularyUsageNote[language] }}</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="region region--no-space-top">
<p>In dit vocabularium zijn geen externe termen hergebruikt.</p>
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-generator-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oslo-flanders/html-generator",
"version": "0.0.17-alpha.0",
"version": "0.0.18-alpha.0",
"description": "Generates an HTML file using an OSLO webuniversum config",
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-generator-html#readme",
Expand Down
5 changes: 3 additions & 2 deletions packages/oslo-generator-json-webuniversum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ The service is executed from the CLI and expects the following parameters:
| `--output` | Name of the output file | No, default `webuniversum-config.json` | |
| `--language` | The language in which the config must be generated | :heavy_check_mark: | |
| `--applyFiltering` | Wether or not to apply filters on the generated output. The filters are used for the OSLO-frontend application(s) | No, default `true` | `true` or `false` |
| `--publicationEnvironment` | The base URI of environment where the document will be published | :heavy_check_mark: | |

## Usage

```bash
oslo-webuniversum-json-generator --input report.jsonld --language nl
oslo-webuniversum-json-generator --input report.jsonld --language nl --applyFiltering false
oslo-webuniversum-json-generator --input report.jsonld --language nl --publicationEnvironment https://data.vlaanderen.be
oslo-webuniversum-json-generator --input report.jsonld --language nl --applyFiltering false --publicationEnvironment https://data.vlaanderen.be
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isInPublicationEnvironment,
isScoped,
sortWebuniversumObjects,
isInPublication,
} from './utils/utils';

@injectable()
Expand All @@ -38,7 +39,7 @@ export class JsonWebuniversumGenerationService implements IService {
@inject(ServiceIdentifier.Logger) logger: Logger,
@inject(ServiceIdentifier.Configuration)
configuration: JsonWebuniversumGenerationServiceConfiguration,
@inject(ServiceIdentifier.QuadStore) store: QuadStore,
@inject(ServiceIdentifier.QuadStore) store: QuadStore
) {
this.logger = logger;
this.configuration = configuration;
Expand Down Expand Up @@ -66,72 +67,76 @@ export class JsonWebuniversumGenerationService implements IService {
classes.forEach((classObject: WebuniversumObject) =>
sortWebuniversumObjects(
classObject.properties || [],
this.configuration.language,
),
this.configuration.language
)
);

sortWebuniversumObjects(dataTypes, this.configuration.language);
dataTypes.forEach((datatypeObject: WebuniversumObject) =>
sortWebuniversumObjects(
datatypeObject.properties || [],
this.configuration.language,
),
this.configuration.language
)
);

const baseURI = this.getBaseURI();
let template: any = { baseURI };

// Filter entitities
if (this.configuration.applyFiltering) {
const inPackageClasses = filterWebuniversumObjects(classes, isInPackage);
const inPackageClasses = filterWebuniversumObjects(classes, [
isInPackage,
]);
const inPublicationEnvironmentClasses = filterWebuniversumObjects(
classes,
isInPublicationEnvironment,
[isInPublicationEnvironment]
);

const inPackageDataTypes = filterWebuniversumObjects(
dataTypes,
const inPackageDataTypes = filterWebuniversumObjects(dataTypes, [
isInPackage,
);
const scopedDataTypes = filterWebuniversumObjects(dataTypes, isScoped);
]);
const scopedDataTypes = filterWebuniversumObjects(dataTypes, [isScoped]);

const externalProperties = [...classes, ...dataTypes].flatMap((c) =>
filterWebuniversumObjects(c.properties || [], isExternal),
filterWebuniversumObjects(c.properties || [], [
isExternal,
() => !isInPublication(c, this.configuration.publicationEnvironment),
])
);

const inPackageProperties = [...classes, ...dataTypes].flatMap((c) =>
filterWebuniversumObjects(c.properties || [], isInPackage),
filterWebuniversumObjects(c.properties || [], [isInPackage])
);

template = {
...template,
entities: sortWebuniversumObjects(
[...inPackageClasses, ...inPublicationEnvironmentClasses],
this.configuration.language,
this.configuration.language
),
inPackageClasses: sortWebuniversumObjects(
inPackageClasses,
this.configuration.language,
this.configuration.language
),
inPackageDataTypes: sortWebuniversumObjects(
inPackageDataTypes,
this.configuration.language,
this.configuration.language
),
scopedDataTypes: sortWebuniversumObjects(
scopedDataTypes,
this.configuration.language,
this.configuration.language
),
externalProperties: sortWebuniversumObjects(
externalProperties,
this.configuration.language,
this.configuration.language
),
inPackageProperties: sortWebuniversumObjects(
inPackageProperties,
this.configuration.language,
this.configuration.language
),
inPackageMerged: sortWebuniversumObjects(
[...inPackageDataTypes, ...inPackageClasses],
this.configuration.language,
this.configuration.language
),
};
} else {
Expand All @@ -141,12 +146,12 @@ export class JsonWebuniversumGenerationService implements IService {
await writeFile(
this.configuration.output,
JSON.stringify(template, null, 2),
'utf-8',
'utf-8'
);
}

private filterByRangeListedInDocument(
rangeAssignedURI: string,
rangeAssignedURI: string
): string | undefined {
const inPackageUri: string | undefined = [
...this.store.getClassIds(),
Expand All @@ -155,7 +160,7 @@ export class JsonWebuniversumGenerationService implements IService {
.map((classId) => this.store.getAssignedUri(classId)?.value)
.find(
(value) =>
value === rangeAssignedURI && value.startsWith(this.getBaseURI()),
value === rangeAssignedURI && value.startsWith(this.getBaseURI())
);

return inPackageUri;
Expand Down Expand Up @@ -183,55 +188,55 @@ export class JsonWebuniversumGenerationService implements IService {

private async generateEntityData(
entity: RDF.NamedNode,
includeProperties: boolean = true,
includeProperties: boolean = true
): Promise<WebuniversumObject> {
const assignedURI: RDF.NamedNode | undefined =
this.store.getAssignedUri(entity);
if (!assignedURI) {
throw new Error(
`Unable to find the assigned URI for entity ${entity.value}.`,
`Unable to find the assigned URI for entity ${entity.value}.`
);
}

const fetchProperty = (
fetchFunction: (
subjectId: RDF.NamedNode,
store: QuadStore,
language: string,
language: string
) => RDF.Literal | undefined,
subject: RDF.NamedNode,
subject: RDF.NamedNode
) => fetchFunction(subject, this.store, this.configuration.language)?.value;

const vocabularyLabel: string | undefined = fetchProperty(
getVocabularyLabel,
entity,
entity
);
const applicationProfileLabel: string | undefined = fetchProperty(
getApplicationProfileLabel,
entity,
entity
);
const vocabularyDefinition: string | undefined = fetchProperty(
getVocabularyDefinition,
entity,
entity
);
const applicationProfileDefinition: string | undefined = fetchProperty(
getApplicationProfileDefinition,
entity,
entity
);
const vocabularyUsageNote: string | undefined = fetchProperty(
getVocabularyUsageNote,
entity,
entity
);
const applicationProfileUsageNote: string | undefined = fetchProperty(
getApplicationProfileUsageNote,
entity,
entity
);

const parentsIds: RDF.NamedNode[] = includeProperties
? this.store.getParentsOfClass(entity)
: this.store.getParentOfProperty(entity) !== undefined
? [this.store.getParentOfProperty(entity)!]
: [];
? [this.store.getParentOfProperty(entity)!]
: [];
const parentObjects: Pick<
WebuniversumObject,
'id' | 'vocabularyLabel' | 'applicationProfileLabel'
Expand Down Expand Up @@ -287,8 +292,8 @@ export class JsonWebuniversumGenerationService implements IService {
this.addPropertySpecificInformation(
<RDF.NamedNode>property,
<WebuniversumProperty>propertyObject,
assignedURI,
),
assignedURI
)
)
);
});
Expand All @@ -306,7 +311,7 @@ export class JsonWebuniversumGenerationService implements IService {
private addPropertySpecificInformation(
subject: RDF.NamedNode,
propertyObject: WebuniversumProperty,
domainId: RDF.NamedNode,
domainId: RDF.NamedNode
): WebuniversumProperty {
propertyObject.domain = domainId.value;

Expand All @@ -319,27 +324,27 @@ export class JsonWebuniversumGenerationService implements IService {
this.store.getAssignedUri(range);
if (!rangeAssignedURI) {
throw new Error(
`Unable to find the assigned URI for range ${range.value} of attribute ${subject.value}.`,
`Unable to find the assigned URI for range ${range.value} of attribute ${subject.value}.`
);
}

propertyObject.range = {
id: rangeAssignedURI.value,
listedInDocument: !!this.filterByRangeListedInDocument(
rangeAssignedURI.value,
rangeAssignedURI.value
),
};

const rangeVocabularyLabel: RDF.Literal | undefined = getVocabularyLabel(
range,
this.store,
this.configuration.language,
this.configuration.language
);
const rangeApplicationProfileLabel: RDF.Literal | undefined =
getApplicationProfileLabel(
range,
this.store,
this.configuration.language,
this.configuration.language
);
rangeVocabularyLabel &&
(propertyObject.range.vocabularyLabel = {
Expand Down Expand Up @@ -368,7 +373,7 @@ export class JsonWebuniversumGenerationService implements IService {
}

private createParentObject(
subject: RDF.NamedNode,
subject: RDF.NamedNode
): Pick<
WebuniversumObject,
'id' | 'vocabularyLabel' | 'applicationProfileLabel'
Expand All @@ -378,20 +383,20 @@ export class JsonWebuniversumGenerationService implements IService {

if (!parentAssignedURI) {
throw new Error(
`Unable to find the assigned URI for class ${subject.value} which acts as a parent.`,
`Unable to find the assigned URI for class ${subject.value} which acts as a parent.`
);
}

const parentVocabularyLabel: RDF.Literal | undefined = getVocabularyLabel(
subject,
this.store,
this.configuration.language,
this.configuration.language
);
const parentApplicationProfileLabel: RDF.Literal | undefined =
getApplicationProfileLabel(
subject,
this.store,
this.configuration.language,
this.configuration.language
);

return {
Expand Down
Loading
Loading