Closed github-actions[bot] closed 1 month ago
This issue has been reviewed and marked as 'ready'. The description has been updated with testable acceptance criteria, and relevant library documents ([], 0 in total) have been added as comments.
Add offline input support to --find-capital-of with tests and docs
Objective
Extend the existing
--find-capital-of
CLI command to support offline querying of a pre-generated OWL JSON ontology file via a new--input <path>
option. Users should be able to skip the live fetch and ontology build when an input file is provided.Acceptance Criteria
CLI Parsing
--find-capital-of <countryCode>
is provided without--input
, behavior remains unchanged (fetch and build ontology).--find-capital-of <countryCode> --input <ontology.json>
is provided:<ontology.json>
usingfs.promises.readFile
.Error: Failed to read or parse input file <path>
.ontology.individuals
array, the command throws an error:Error: Invalid ontology format in <path>
.--input <path>
and--output <path>
are provided, the tool writes the result to the output file.Offline Query Logic
ontology.individuals
for entries withsubject === <countryCode>
andpredicate === 'hasCapital'
.Error: Country code <countryCode> not found in input ontology.
Tests
fs.promises.readFile
to return a sample ontology JSON containing at least onehasCapital
triple and verify:main(["--find-capital-of","USA","--input","ontology.json"])
printsWashington D.C.
and returns{ country: 'USA', capital: 'Washington D.C.' }
.fs.promises.readFile
andfs.promises.writeFile
for offline mode with--output
and verify the output file contents and returned object.ontology.individuals
or parse error) and expect descriptive errors.Documentation
README.md
:Verification Steps
npm test
to ensure all tests (existing and new) pass.node src/lib/main.js --find-capital-of USA --input sample-ontology.json
printsWashington D.C.
node src/lib/main.js --find-capital-of USA --input sample-ontology.json --output out.json
writes{ "country":"USA","capital":"Washington D.C." }
toout.json
.--input
path or malformed file yields a clear error message.