Documentation

ForeignApkgReader
in package

FinalYes

Reads an .apkg that LWT did not produce.

ApkgReader is the round-trip reader: it only understands LWT's own "LWT Term" notetype and matches notes back to terms by lwt- guid. A deck the user built in Anki has neither, so every note comes back empty and gets skipped — which is the gap issue #228 actually describes.

This reader makes no assumptions about field names. It reports the notetypes present so the user can map them, and returns notes with their fields intact plus the scheduling facts needed to infer how well a word is already known.

Table of Contents

Methods

notes()  : array<int, ForeignNote>
Every note using one notetype, with fields unmapped.
notetypes()  : array<int, ForeignNotetype>
Notetypes present in the file, most-used first.
cardStateByNote()  : array<int, array{interval: int, suspended: bool, new: bool}>
Collapse each note's cards into the facts the status mapping needs.
decodeModels()  : array<int, array{name: string, fields: list}>
Notetype id => name + ordered field names.
decodeTags()  : array<int, string>
noteCountsByModel()  : array<int, int>
withCollection()  : T
Extract the collection to a temp file and hand a PDO handle to $work.

Methods

notes()

Every note using one notetype, with fields unmapped.

public notes(string $apkgPath, int $notetypeId) : array<int, ForeignNote>
Parameters
$apkgPath : string
$notetypeId : int
Return values
array<int, ForeignNote>

cardStateByNote()

Collapse each note's cards into the facts the status mapping needs.

private cardStateByNote(PDO $pdo) : array<int, array{interval: int, suspended: bool, new: bool}>

A note can have several cards (forward/reverse). The strongest card wins: if the user knows the word in one direction it is worth importing as known, and a note only counts as suspended when every card is.

Parameters
$pdo : PDO
Return values
array<int, array{interval: int, suspended: bool, new: bool}>

decodeModels()

Notetype id => name + ordered field names.

private decodeModels(PDO $pdo) : array<int, array{name: string, fields: list}>
Parameters
$pdo : PDO
Return values
array<int, array{name: string, fields: list}>

decodeTags()

private decodeTags(string $tags) : array<int, string>
Parameters
$tags : string
Return values
array<int, string>

noteCountsByModel()

private noteCountsByModel(PDO $pdo) : array<int, int>
Parameters
$pdo : PDO
Return values
array<int, int>

notetype id => note count

withCollection()

Extract the collection to a temp file and hand a PDO handle to $work.

private withCollection(string $apkgPath, callable(PDO): T $work) : T
Parameters
$apkgPath : string
$work : callable(PDO): T
Tags
template
Return values
T
On this page

Search results