Skip to content

Commit

Permalink
changed gg2rdf console.logs to log to file instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nleanba committed Feb 29, 2024
1 parent 55bb8cf commit 329f29a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/action_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ async function run() {
gg2rdf(
`${config.workDir}/repo/source/${file}`,
`${config.workDir}/tmpttl/${file.slice(0, -4)}.ttl`,
log,
);
log("gg2rdf succesful");
log("gg2rdf successful");
} catch (error) {
log("gg2rdf failed:");
log(error);
Expand Down
12 changes: 6 additions & 6 deletions src/gg2rdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (import.meta.main) {
gg2rdf(flags.input, flags.output);
}

export function gg2rdf(inputPath: string, outputPath: string) {
export function gg2rdf(inputPath: string, outputPath: string, log: (msg: string) => void = console.log) {
const document = new DOMParser().parseFromString(
Deno.readTextFileSync(inputPath).replaceAll(/(<\/?)mods:/g, "$1MODS"),
"text/xml",
Expand All @@ -63,7 +63,7 @@ export function gg2rdf(inputPath: string, outputPath: string) {
// this is the <document> surrounding everything. doc != document
const doc = document.querySelector("document") as Element;
const id = doc.getAttribute("docId");
// console.log("document id :", id);
log(`starting gg2rdf on document id: ${id}`);

// saving properties, as they might be collated from multiple ELements
const taxonConcepts: Subject[] = [];
Expand All @@ -83,7 +83,7 @@ export function gg2rdf(inputPath: string, outputPath: string) {
taxonConcepts.forEach(outputSubject);
taxonNames.forEach(outputSubject);
} catch (error) {
console.error(error);
log(error);
output(
"# There was some Error in gg2rdf\n" +
("# " + error).replace(/\n/g, "\n# "),
Expand Down Expand Up @@ -171,7 +171,7 @@ export function gg2rdf(inputPath: string, outputPath: string) {
);
}
if (!taxon.getAttribute("kingdom")) {
console.warn(
log(
"Warning: treatment taxon is missing ancestor kingdom, defaulting to 'Animalia'",
);
output(
Expand Down Expand Up @@ -371,7 +371,7 @@ export function gg2rdf(inputPath: string, outputPath: string) {
});

if (cTaxonAuthority === "INVALID") {
console.warn(`Error: Invalid Authority for ${uri}`);
log(`Error: Invalid Authority for ${uri}`);
return;
}

Expand Down Expand Up @@ -630,7 +630,7 @@ export function gg2rdf(inputPath: string, outputPath: string) {
const parent = makeTaxonName(taxon, nextRankLimit);
if (parent && parent !== uri) s.addProperty("trt:hasParentName", parent);
} else {
console.warn(`Warning: Could not determine parent name of ${uri}`);
log(`Warning: Could not determine parent name of ${uri}`);
s.addProperty("# Warning:", "Could not determine parent name");
}

Expand Down

0 comments on commit 329f29a

Please sign in to comment.