@kecan0406/aninames 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/client/format.d.ts +1 -0
- package/lib/client/format.js +7 -3
- package/lib/client/names.d.ts +1 -0
- package/lib/client/names.js +14 -1
- package/lib/model.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Built sizes: `core.sqlite` 610 MB, `kowiki.sqlite` 25 MB, `unlicensed.sqlite` 83
|
|
|
56
56
|
| `<layer>/<table>/<hash>.json.gz` | about 32 KB of JSON rows sorted by key (16 KB for `entity`), named by the first 48 bits of the SHA-256 of the file |
|
|
57
57
|
| `NOTICE.md`, `index.html` | each layer's sources and terms |
|
|
58
58
|
|
|
59
|
-
The key tables are `flat` (folded names), `latin` (romaji keys), `sound` (sound keys across kana, Hangul and romaji), `part` (name tokens) and `initial` (Korean initials); their rows are `[key, entity number, name weight, flags, popularity, standing, bonus]`. `tag` holds the same rows for Danbooru tags, keyed by the tag folded like a name without its qualifier and weighted by the tag's posts. `home` holds them for the copyright tag each character comes from, weighted by the character's own posts; a `core` row whose character the `unlicensed` layer gives another home carries flag 64, which a client that reads `unlicensed` skips. `entity` rows, keyed by entity number (which follows the entity ids' order), carry the id, names, Danbooru tags, works, family, the ids other databases give one entity in that layer (TMDB's `tmdb:tv/…` and `tmdb:movie/…`, IGDB's `igdb:…` and Steam's `steam:…` among them, read from Wikidata)
|
|
59
|
+
The key tables are `flat` (folded names), `latin` (romaji keys), `sound` (sound keys across kana, Hangul and romaji), `part` (name tokens) and `initial` (Korean initials); their rows are `[key, entity number, name weight, flags, popularity, standing, bonus]`. `tag` holds the same rows for Danbooru tags, keyed by the tag folded like a name without its qualifier and weighted by the tag's posts. `home` holds them for the copyright tag each character comes from, weighted by the character's own posts; a `core` row whose character the `unlicensed` layer gives another home carries flag 64, which a client that reads `unlicensed` skips. `entity` rows, keyed by entity number (which follows the entity ids' order), carry the id, names, Danbooru tags, works, family, the ids other databases give one entity in that layer (TMDB's `tmdb:tv/…` and `tmdb:movie/…`, IGDB's `igdb:…` and Steam's `steam:…` among them, read from Wikidata), a character's home tag and a work's countries of origin (Wikidata P495, as ISO 3166-1 alpha-2 codes such as `JP`). Layers stay in separate files; the only values a file carries from other layers are derived numbers and flags (popularity, family standing, adult, which layers know the entity).
|
|
60
60
|
|
|
61
61
|
On the 10-04 build: 19,167 files, 149 MB gzip'd, a manifest of 236 KB gzip'd. `mise run compare` searches the probe sample (4,370 queries) both ways: the files find the entity first 87% of the time, SQLite 86% (FTS substring search is not in the files; typo search reads the rows around the query's position instead). A cold query needs a median of 2 rounds (p90 3), 31 files (p90 78) and 287 KB (p90 584 KB).
|
|
62
62
|
|
|
@@ -71,7 +71,7 @@ const [first] = await names.search('봇치', { limit: 10, signal })
|
|
|
71
71
|
const works = await names.lookup(first?.works ?? [])
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
`search` returns `Found` cards (`id`, `kind`, `label`, `names` with their `lang` and `kind`, `danbooru` tags with the most posts first, `works`, `refs`, `home`, the copyright tag a character comes from, `score`, `adult`); `search(query, { kind, limit, adult: false })` narrows it, `lookup(ids)` returns the cards of given ids in one round, and `tagged(tag, { kind, adult })` the cards of the entities that carry a Danbooru tag, most posts first, whatever its case, punctuation or qualifier (`soul-eater`, `soul_eater` and `soul_eater_(series)` find the same works); `prefix: true` also finds the tags that start with it. `cast(tag, { adult, prefix, limit })` returns the characters whose home is that tag, most posts first. `cachedSource` keeps the files it fetched forever (their names are hashes of their contents), revalidates the manifest with its ETag or Last-Modified once a day (`maxAge`), answers from the cache when offline, refetches the manifest when the site has moved on to a new build, and deletes files a new manifest no longer names. `fileSource(dir)` reads a local `dist/site`.
|
|
74
|
+
`search` returns `Found` cards (`id`, `kind`, `label`, `names` with their `lang` and `kind`, `danbooru` tags with the most posts first, `works`, `refs`, `home`, the copyright tag a character comes from, `origin`, the countries a work comes from, `score`, `adult`); `search(query, { kind, limit, adult: false })` narrows it, `lookup(ids)` returns the cards of given ids in one round, and `tagged(tag, { kind, adult })` the cards of the entities that carry a Danbooru tag, most posts first, whatever its case, punctuation or qualifier (`soul-eater`, `soul_eater` and `soul_eater_(series)` find the same works); `prefix: true` also finds the tags that start with it. `cast(tag, { adult, prefix, limit })` returns the characters whose home is that tag, most posts first. `cachedSource` keeps the files it fetched forever (their names are hashes of their contents), revalidates the manifest with its ETag or Last-Modified once a day (`maxAge`), answers from the cache when offline, refetches the manifest when the site has moved on to a new build, and deletes files a new manifest no longer names. `fileSource(dir)` reads a local `dist/site`.
|
|
75
75
|
|
|
76
76
|
## Development
|
|
77
77
|
|
package/lib/client/format.d.ts
CHANGED
package/lib/client/format.js
CHANGED
|
@@ -192,10 +192,11 @@ const tagOf = (value) => Array.isArray(value) && typeof value[0] === 'string' &&
|
|
|
192
192
|
const workOf = (value) => Array.isArray(value) && isCount(value[0]) && typeof value[1] === 'string' ? [value[0], value[1]] : undefined;
|
|
193
193
|
const eidOf = (value) => (isCount(value) ? value : undefined);
|
|
194
194
|
const refOf = (value) => typeof value === 'string' && value.indexOf(':') > 0 ? value : undefined;
|
|
195
|
+
const countryOf = (value) => typeof value === 'string' && /^[A-Z]{2}$/.test(value) ? value : undefined;
|
|
195
196
|
function entityRow(value) {
|
|
196
197
|
if (!Array.isArray(value) || value.length < 10)
|
|
197
198
|
return undefined;
|
|
198
|
-
const [eid, id, rawNames, rawTags, rawWorks, rawReach, rank, standing, extra, adult, rawRefs = [], home = null] = value;
|
|
199
|
+
const [eid, id, rawNames, rawTags, rawWorks, rawReach, rank, standing, extra, adult, rawRefs = [], home = null, rawOrigin = [],] = value;
|
|
199
200
|
if (!isCount(eid) || typeof id !== 'string')
|
|
200
201
|
return undefined;
|
|
201
202
|
const kind = id.startsWith('w/') ? 'work' : id.startsWith('c/') ? 'character' : undefined;
|
|
@@ -206,9 +207,12 @@ function entityRow(value) {
|
|
|
206
207
|
const works = list(rawWorks, workOf);
|
|
207
208
|
const reach = list(rawReach, eidOf);
|
|
208
209
|
const refs = list(rawRefs, refOf);
|
|
209
|
-
|
|
210
|
+
const origin = list(rawOrigin, countryOf);
|
|
211
|
+
if (!names || !danbooru || !works || !reach || !refs || !origin)
|
|
210
212
|
return undefined;
|
|
211
|
-
|
|
213
|
+
if (home !== null && typeof home !== 'string')
|
|
214
|
+
return undefined;
|
|
215
|
+
return { eid, id, kind, names, danbooru, works, reach, rank, standing, extra, adult: adult === 1, refs, home, origin };
|
|
212
216
|
}
|
|
213
217
|
export function readRows(table, value) {
|
|
214
218
|
if (!Array.isArray(value))
|
package/lib/client/names.d.ts
CHANGED
package/lib/client/names.js
CHANGED
|
@@ -79,7 +79,20 @@ function card(rows, score, adult) {
|
|
|
79
79
|
const works = head.kind === 'character' ? [...new Set(rows.flatMap((row) => row.works.map(([, id]) => id)))] : [];
|
|
80
80
|
const refs = [...new Set(rows.flatMap((row) => row.refs))].sort();
|
|
81
81
|
const home = rows.findLast((row) => row.home !== null)?.home ?? null;
|
|
82
|
-
|
|
82
|
+
const origin = [...new Set(rows.flatMap((row) => row.origin))];
|
|
83
|
+
return {
|
|
84
|
+
id: head.id,
|
|
85
|
+
kind: head.kind,
|
|
86
|
+
label: label(head.id, rows),
|
|
87
|
+
names,
|
|
88
|
+
danbooru,
|
|
89
|
+
works,
|
|
90
|
+
refs,
|
|
91
|
+
home,
|
|
92
|
+
origin,
|
|
93
|
+
score,
|
|
94
|
+
adult,
|
|
95
|
+
};
|
|
83
96
|
}
|
|
84
97
|
export class Names {
|
|
85
98
|
#source;
|
package/lib/model.d.ts
CHANGED