Skip to content

Commit

Permalink
add --only-default-graph option to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ajuvercr committed Feb 26, 2024
1 parent ef87eb2 commit 8b6da41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
7 changes: 7 additions & 0 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let ordered: Ordered = "none";
let quiet: boolean = false;
let verbose: boolean = false;
let save: string | undefined;
let onlyDefaultGraph: boolean = false;
let loose: boolean = false;

program
Expand All @@ -32,6 +33,10 @@ program
"--no-shape",
"don't extract members with a shape (only use cbd and named graphs)",
)
.option(
"--only-default-graph",
"extract members only from the default graph and the member graph",
)
.option(
"-s, --save <path>",
"filepath to the save state file to use, used both to resume and to update",
Expand All @@ -58,6 +63,7 @@ program
quiet = program.quiet;
verbose = program.verbose;
loose = program.loose;
onlyDefaultGraph = program.onlyDefaultGraph;
});

program.parse(process.argv);
Expand All @@ -75,6 +81,7 @@ async function main() {
fetcher: { maxFetched: 2, concurrentRequests: 10 },
urlIsView: urlIsView,
shapeFile,
onlyDefaultGraph,
}),
undefined,
undefined,
Expand Down
37 changes: 19 additions & 18 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ async function getInfo(
ldesId: Term,
store: RdfStore,
dereferencer: RdfDereferencer,
noShape: boolean,
shapeConfig?: ShapeConfig,
shapeFile?: string,
config: Config,
): Promise<LDESInfo> {
const logger = log.extend("getShape");

if (shapeFile) {
const shapeId = shapeFile.startsWith("http")
? shapeFile
: "file://" + shapeFile;
if (config.shapeFile) {
const shapeId = config.shapeFile.startsWith("http")
? config.shapeFile
: "file://" + config.shapeFile;

const resp = await rdfDereference.dereference(shapeFile, {
const resp = await rdfDereference.dereference(config.shapeFile, {
localFiles: true,
});
const quads = await streamToArray(resp.data);
shapeConfig = {
config.shape = {
quads: quads,
shapeId: namedNode(shapeId),
};
}

let shapeIds = noShape ? [] : getObjects(store, ldesId, TREE.terms.shape);
let shapeIds = config.noShape
? []
: getObjects(store, ldesId, TREE.terms.shape);
let timestampPaths = getObjects(store, ldesId, LDES.terms.timestampPath);
let isVersionOfPaths = getObjects(store, ldesId, LDES.terms.versionOfPath);

Expand All @@ -84,7 +84,7 @@ async function getInfo(
);

if (
!noShape &&
!config.noShape &&
(shapeIds.length === 0 ||
timestampPaths.length === 0 ||
isVersionOfPaths.length === 0)
Expand Down Expand Up @@ -127,18 +127,21 @@ async function getInfo(
}

let shapeConfigStore = RdfStore.createDefault();
if (shapeConfig) {
for (let quad of shapeConfig.quads) {
if (config.shape) {
for (let quad of config.shape.quads) {
shapeConfigStore.addQuad(quad);
}
}

return {
extractor: new CBDShapeExtractor(
shapeConfig ? shapeConfigStore : store,
config.shape ? shapeConfigStore : store,
dereferencer,
{
cbdDefaultGraph: config.onlyDefaultGraph,
},
),
shape: shapeConfig ? shapeConfig.shapeId : shapeIds[0],
shape: config.shape ? config.shape.shapeId : shapeIds[0],
timestampPath: timestampPaths[0],
isVersionOfPath: isVersionOfPaths[0],
};
Expand Down Expand Up @@ -254,9 +257,7 @@ export class Client {
ldesId,
root.data,
this.dereferencer,
this.config.noShape,
this.config.shape,
this.config.shapeFile,
this.config,
);

const state = this.stateFactory.build<Set<string>>(
Expand Down
1 change: 1 addition & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Config {
after?: Date;
shape?: ShapeConfig;
shapeFile?: string;
onlyDefaultGraph?: boolean;

// Add flag to indicate in order (default true)
// Make sure that slower pages to first emit the first members
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ldes-client",
"description": "This package provides common tooling to work with LDESes.",
"version": "0.0.6",
"version": "0.0.7",
"main": "dist/lib/client.js",
"bin": {
"ldes-client": "dist/bin/cli.js"
Expand Down

0 comments on commit 8b6da41

Please sign in to comment.