Skip to content
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
32 changes: 10 additions & 22 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,16 @@ function groupNquadsBySubject(nquadsArray, sort = false) {
const grouped = {};

parser.parse(nquadsArray.join("")).forEach((quad) => {
const { subject, predicate, object } = quad;
const { subject } = quad;

let subjectKey;
if (subject.termType === "Quad") {
const nestedSubject = subject.subject.value;
const nestedPredicate = subject.predicate.value;
const nestedObject =
subject.object.termType === "Literal"
? `"${escapeLiteral(subject.object.value)}"`
: `<${escapeLiteral(subject.object.value)}>`;
? `"${subject.object.value}"`
: `<${subject.object.value}>`;
subjectKey = `<<<${nestedSubject}> <${nestedPredicate}> ${nestedObject}>>`;
} else {
subjectKey = `<${subject.value}>`;
Expand All @@ -385,12 +385,14 @@ function groupNquadsBySubject(nquadsArray, sort = false) {
grouped[subjectKey] = [];
}

const objectValue =
object.termType === "Literal"
? `"${escapeLiteral(object.value)}"`
: `<${escapeLiteral(object.value)}>`;
const writer = new N3.Writer({ format: "N-Quads" });
let quadString = "";
writer.addQuad(quad);
writer.end((error, result) => {
if (error) throw error;
quadString = result.trim();
});

const quadString = `${subjectKey} <${predicate.value}> ${objectValue} .`;
grouped[subjectKey].push(quadString);
});

Expand Down Expand Up @@ -534,20 +536,6 @@ function isEmptyObject(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object;
}

function escapeLiteral(value) {
const ESCAPE_MAP = {
'"': '\\"',
"\\": "\\\\",
"\b": "\\b",
"\f": "\\f",
"\n": "\\n",
"\r": "\\r",
"\t": "\\t",
};

return value.replace(/["\\\b\f\n\r\t]/g, (char) => ESCAPE_MAP[char]);
}

var knowledgeCollectionTools = /*#__PURE__*/Object.freeze({
__proto__: null,
calculateByteSize: calculateByteSize,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assertion-tools",
"version": "8.0.5",
"version": "8.0.6",
"description": "Common assertion tools used in ot-node and dkg.js",
"main": "index.js",
"type": "module",
Expand Down