Skip to content

Commit

Permalink
Fix sanitazing + better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Mar 11, 2024
1 parent da9ff43 commit 8d36c31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/SPARQLIngest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export async function sparqlIngest(

// Variable that will hold the full query to be executed
let query;
let queryType;

if (config.changeSemantics) {
if (transactionMembers.length > 0) {
Expand All @@ -128,10 +129,13 @@ export async function sparqlIngest(
// Assemble corresponding SPARQL UPDATE query
if (ctv.object.value === config.changeSemantics.createValue) {
query = CREATE(store, ng);
queryType = "CREATE";
} else if (ctv.object.value === config.changeSemantics.updateValue) {
query = UPDATE(store, ng);
queryType = "UPDATE";
} else if (ctv.object.value === config.changeSemantics.deleteValue) {
query = DELETE(store, [memberIRI.value], config.memberShapes, ng);
queryType = "DELETE";
} else {
throw new Error(`[sparqlIngest] Unrecognized change type value: ${ctv.object.value}`);
}
Expand Down Expand Up @@ -159,6 +163,7 @@ export async function sparqlIngest(
}

await Promise.all(outputPromises);
console.log(`[sparqlIngest] Executed ${queryType} on remote SPARQL server ${config.graphStoreUrl}`);
}
} else {
throw new Error(`[sparqlIngest] No member IRI found in received RDF data: \n${rawQuads}`);
Expand Down
6 changes: 4 additions & 2 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Store, DataFactory as DF } from "n3";

export function sanitizeQuads(store: Store): void {
for (const q of store.getQuads(null, null, null, null)) {
if (q.object.termType === "Literal") {
if (/\+\d+/.test(q.object.value)) {
// There is an issue with triples like <a> <b> +30.
// Virtuoso doesn't accept the implicit integer type including the + sign.
if (q.object.termType === "Literal" && q.object.datatype.value === XSD.integer) {
if (/\+\d+/.test(q.object.value) && q.object.value.startsWith("+")) {
store.removeQuad(q);
store.addQuad(q.subject, q.predicate, DF.literal(q.object.value.substring(1), DF.namedNode(XSD.integer)), q.graph);
}
Expand Down

0 comments on commit 8d36c31

Please sign in to comment.