refactoring some code and fixing typos

This commit is contained in:
Elias Papanikitas
2024-03-05 18:04:52 +01:00
parent 4827f1bb9b
commit 8fa52c7c55
4 changed files with 255 additions and 185 deletions

View File

@@ -240,9 +240,9 @@ export async function getAllAbbKboOrganizations() {
<http://schema.org/telephone> ?phone ;
<http://schema.org/contactType> ?contactType ;
<http://xmlns.com/foaf/0.1/page> ?website ;
<http://www.w3.org/ns/locn#address> ?adress .
<http://www.w3.org/ns/locn#address> ?address .
?adress <http://www.w3.org/ns/locn#fullAddress> ?fullAddress.
?address <http://www.w3.org/ns/locn#fullAddress> ?fullAddress.
}
OPTIONAL{
@@ -367,7 +367,7 @@ export async function createNewKboOrg(kboOrg, kboId) {
kboOrg.changeTime
)}`
}
if(kboOrg.kboId){
if(kboId){
updateStr += `; <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
kboId
)}`
@@ -393,60 +393,81 @@ export async function createNewKboOrg(kboOrg, kboId) {
}
export async function updateKboOrg(newKboInfo, identifiers) {
//update Adress
//update address
let updateStr = `
DELETE{
GRAPH ?g{
?adressUri a <http://www.w3.org/ns/locn#Address> ;
DELETE{
GRAPH ?g{
?adressUri a <http://www.w3.org/ns/locn#Address> ;
<http://www.w3.org/ns/locn#fullAddress> ?fulladdress .
}
INSERT{
graph ?g{
?adressUri a <http://www.w3.org/ns/locn#Address>
`;
if(newKboInfo.formattedAddress){
updateStr += `
;
<http://www.w3.org/ns/locn#fullAddress> ${sparqlEscapeString(
newKboInfo.formattedAddress
)}
`;
}
updateStr += `
.
}
}
`;
updateStr += `
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?adressUri a <http://www.w3.org/ns/locn#Address> ;
<http://www.w3.org/ns/locn#fullAddress> ?fulladdress .
}
}
INSERT{
graph ?g{
?adressUri a <http://www.w3.org/ns/locn#Address> ;
<http://www.w3.org/ns/locn#fullAddress> ${sparqlEscapeString(
newKboInfo.formattedAddress
)} .
}
}
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?adressUri a <http://www.w3.org/ns/locn#Address> ;
<http://www.w3.org/ns/locn#fullAddress> ?fulladdress .
FILTER(?adressUri = ${sparqlEscapeUri(identifiers.addressUri)})
}
}
FILTER(?adressUri = ${sparqlEscapeUri(identifiers.addressUri)})
}
}
`;
await update(updateStr);
//update ContactPoint
updateStr = `
DELETE{
GRAPH ?g{
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ?email ;
<http://schema.org/telephone> ?phone ;
<http://xmlns.com/foaf/0.1/page> ?website .
}
DELETE{
GRAPH ?g{
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ?email ;
<http://schema.org/telephone> ?phone ;
<http://xmlns.com/foaf/0.1/page> ?website .
}
}
INSERT{
graph ?g{
?contact a <http://schema.org/ContactPoint>
`;
if(newKboInfo.email){
updateStr += `; <http://schema.org/email> ${sparqlEscapeString(
newKboInfo.email
)}`
}
INSERT{
graph ?g{
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ${sparqlEscapeString(
newKboInfo.email
)} ;
<http://schema.org/telephone> ${sparqlEscapeString(
newKboInfo.phone
)} ;
<http://xmlns.com/foaf/0.1/page> ${sparqlEscapeString(
newKboInfo.website
)} .
if(newKboInfo.phone){
updateStr += `; <http://schema.org/telephone> ${sparqlEscapeString(
newKboInfo.phone
)}`
}
if(newKboInfo.phone){
updateStr += `; <http://xmlns.com/foaf/0.1/page> ${sparqlEscapeString(
newKboInfo.website
)}`
}
updateStr += `
.
}
}
`;
updateStr += `
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
@@ -465,61 +486,103 @@ export async function updateKboOrg(newKboInfo, identifiers) {
//update kboUnit
updateStr = `
DELETE{
GRAPH ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
}
}INSERT{
graph ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ${sparqlEscapeString(
newKboInfo.rechtsvorm
)} ;
<http://mu.semte.ch/vocabularies/ext/shortName> ${sparqlEscapeString(
newKboInfo.shortName
)} ;
<http://mu.semte.ch/vocabularies/ext/startDate> ${sparqlEscapeString(
newKboInfo.startDate
)} ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ${sparqlEscapeString(
newKboInfo.organisationName
)} ;
<http://www.w3.org/2004/02/skos/core#altLabel> ${sparqlEscapeString(
newKboInfo.formalName
)} ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ${sparqlEscapeString(
newKboInfo.changeTime
)} ;
<http://www.w3.org/ns/regorg#orgStatus> ${sparqlEscapeUri(
newKboInfo.activeState
)} .
}
}
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)})
}
}
DELETE{
GRAPH ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
}
}
INSERT{
graph ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid>
`;
if(newKboInfo.rechtsvorm){
updateStr += `
;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ${sparqlEscapeString(
newKboInfo.rechtsvorm
)}
`;
}
if(newKboInfo.shortName){
updateStr += `
;
<http://mu.semte.ch/vocabularies/ext/shortName> ${sparqlEscapeString(
newKboInfo.shortName
)}
`;
}
if(newKboInfo.startDate){
updateStr += `
;
<http://mu.semte.ch/vocabularies/ext/startDate> ${sparqlEscapeString(
newKboInfo.startDate
)}
`;
}
if(newKboInfo.organisationName){
updateStr += `
;
<http://www.w3.org/2004/02/skos/core#prefLabel> ${sparqlEscapeString(
newKboInfo.organisationName
)}
`;
}
if(newKboInfo.formalName){
updateStr += `
;
<http://www.w3.org/2004/02/skos/core#altLabel> ${sparqlEscapeString(
newKboInfo.formalName
)}
`;
}
if(newKboInfo.changeTime){
updateStr += `
;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ${sparqlEscapeString(
newKboInfo.changeTime
)}
`;
}
if(newKboInfo.activeState){
updateStr += `
;
<http://www.w3.org/ns/regorg#orgStatus> ${sparqlEscapeUri(
newKboInfo.activeState
)}
`;
}
updateStr += `
.
}
}
`;
updateStr += `
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)})
}
}
`;
await update(updateStr);
}