Skip to content

Commit d3f1b2b

Browse files
committed
Updated files of wegenenverkeer vocabularies + extracting more terms + added extra logging for elastic
1 parent a2eef54 commit d3f1b2b

File tree

5 files changed

+37
-94
lines changed

5 files changed

+37
-94
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/abstracten/ontwerpdocument/v29/html-nj.json
2-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/implementatieelement/ontwerpdocument/v29/html-nj.json
3-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/installatie/ontwerpdocument/v29/html-nj.json
4-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/levelofgeometry/ontwerpdocument/v29/html-nj.json
5-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/levenscyclus/ontwerpdocument/v29/html-nj.json
6-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/onderdeel/ontwerpdocument/v29/html-nj.json
7-
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/proefenmeting/ontwerpdocument/v29/html-nj.json
1+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/abstracten/ontwerpdocument/1.0.0/html-nj.json
2+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/implementatieelement/ontwerpdocument/1.0.0/html-nj.json
3+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/installatie/ontwerpdocument/1.0.0/html-nj.json
4+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/levenscyclus/ontwerpdocument/1.0.0/html-nj.json
5+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/onderdeel/ontwerpdocument/1.0.0/html-nj.json
6+
https://raw.githubusercontent.com/Informatievlaanderen/OSLO-Generated/wegenenverkeer/report/doc/vocabularium/wegenenverkeer/proefenmeting/ontwerpdocument/1.0.0/html-nj.json

lib/Elastic.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Client} from '@elastic/elasticsearch';
22
const config = require('../config.json');
3+
const hash = require('object-hash');
34

45
export class Elastic {
56

@@ -10,13 +11,13 @@ export class Elastic {
1011
this.checkElasticStatus()
1112
}
1213

13-
1414
async indexData(document, index) {
15-
const body = document.flatMap(doc => [{index: {_index: index, _id: doc.id}}, doc]);
15+
const body = document.flatMap(object => [{index: { _index: index, _id: this.createhash(object)}}, object]);
1616
const {body: bulkResponse} = await this.client.bulk({refresh: true, body});
1717

1818
if (bulkResponse.errors) {
19-
const erroredDocuments = []
19+
console.log(`[Elasticsearch]: some errors occurred while adding the data:`)
20+
const erroredDocuments = [];
2021
// The items array has the same order of the dataset we just indexed.
2122
// The presence of the `error` key indicates that the operation
2223
// that we did for the document has failed.
@@ -35,6 +36,8 @@ export class Elastic {
3536
}
3637
})
3738
console.log(erroredDocuments)
39+
} else {
40+
console.log(`[Elasticsearch]: insert number of terms is: ${bulkResponse.items.length}`);
3841
}
3942
}
4043

@@ -128,7 +131,7 @@ export class Elastic {
128131
private async checkIndexStatus(index: string) {
129132
return this.client.indices.exists({index: index})
130133
}
131-
134+
132135
/* Mapping functions */
133136

134137
private getVocabularyMapping() {
@@ -166,5 +169,9 @@ export class Elastic {
166169
}
167170
}
168171

172+
private createhash(object){
173+
return hash(object);
174+
}
175+
169176

170177
}

lib/Vocabulary.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import {VocabularyTerm} from "./Term";
33
export class Vocabulary {
44

55
static createDocument(data){
6-
//const name = data.metadata.uri;
6+
const domain = data.metadata.uri;
77
let terms = [];
8-
// Get classes and properties from the vocabulary
8+
9+
// Get classes, properties and external terms from the vocabulary
910
for(let object of data.classes){
1011
terms.push(new VocabularyTerm({
1112
prefLabel: object.name['nl'],
1213
id: object.uri,
1314
definition: object.description['nl'],
14-
context: data.metadata.uri
15+
context: domain
1516
}));
1617
}
1718

@@ -20,7 +21,16 @@ export class Vocabulary {
2021
prefLabel: object.name['nl'],
2122
id: object.uri,
2223
definition: object.description['nl'],
23-
context: data.metadata.uri
24+
context: domain
25+
}));
26+
}
27+
28+
for(let object of data.external_terms){
29+
terms.push(new VocabularyTerm({
30+
prefLabel: object.name['nl'],
31+
id: object.uri,
32+
definition: object.description['nl'],
33+
context: domain
2434
}));
2535
}
2636

package-lock.json

Lines changed: 5 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"commander": "^5.1.0",
2424
"fs": "0.0.1-security",
2525
"node-fetch": "^2.6.1",
26+
"object-hash": "^2.1.1",
2627
"readline": "^1.3.0",
2728
"util": "^0.12.3"
2829
},

0 commit comments

Comments
 (0)