Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created May 14, 2021 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/fb013357fc4a7c9412aefe58899e61c0 to your computer and use it in GitHub Desktop.
Save BruJu/fb013357fc4a7c9412aefe58899e61c0 to your computer and use it in GitHub Desktop.
Leftovers code from PREC
// === transformProperties
// TODO:
// if (asSet) {
// for (const bind of newB) {
// noList(store, bind.x);
// }
// }
function noList(store, firstNode) {
const listHeads = storeAlterer.matchAndBind(store,
[
[firstNode , rdf.type , rdf.List ],
[variable("s"), variable("p"), firstNode]
]
);
if (listHeads.length !== 1) {
console.error("noList: Not exactly one match");
return;
}
const listHead = listHeads[0];;
const l = storeAlterer.extractRecursive(
store,
firstNode,
[
[variable("(R) current"), rdf.type , rdf.List ],
[variable("(R) current"), rdf.first, variable("value") ],
[variable("(R) current"), rdf.rest , variable("(R) next")]
],
rdf.nil,
[]
);
storeAlterer.replace(store, listHeads, []);
for (const element of l) {
store.addQuad(listHead.s, listHead.p, element);
}
}
function searchUnmapped(store) {
const r = storeAlterer.matchAndBind(store,
[[variable("word"), rdf.type, prec.CreatedVocabulary]]
);
let unmapped = [];
for (let r1 of r) {
const word = r1.word;
if (store.countQuads(null, word, null) > 0
|| store.countQuads(null, rdf.predicate, word) > 0) {
unmapped.push(word);
}
}
let quads = store.getQuads();
store.removeQuads(quads);
for (const term of unmapped) {
store.addQuad(term, rdf.type, prec.CreatedVocabulary);
}
}
function _findTripleAbleRelations(requestResult) {
// 1.
const predicates = {};
for (let bindings of requestResult) {
const key = concise(bindings.p);
if (predicates[key] === undefined) {
predicates[key] = new N3.Store();
} else if (predicates[key] === "HadDuplicates") {
continue;
}
if (predicates[key].countQuads(bindings.s, bindings.p, bindings.o) >= 1) {
predicates[key] = "HadDuplicates";
} else {
predicates[key].addQuad(bindings.s, bindings.p, bindings.o);
}
}
// 2.
const result = new Set();
for (const key in predicates) {
if (predicates[key] !== "HadDuplicates") {
result.add(key);
}
}
return result;
}
/**
* Convert a term to its Graphy concise representation
* @param {*} term The term I guess?
*/
function concise(term) { return graphyFactory.term(term).concise(); }
function _listContains(pattern, searched) {
return pattern.find(e => searched.find(s => quadStar.containsTerm(e, s)) !== undefined) !== undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment