# AGENTS.md: how to get an answer out of this catalog

This is an unofficial static STAC mirror of 東京都オープンデータカタログ, a CKAN
site. It holds metadata only. Every asset href points at the publisher's own
server. 9,698 Items (datasets), 83,821 assets (files),
95 Collections (organisations).

## Start with the tables, not the tree

Do not open Items one by one to answer a question across datasets. Query:

- `https://stac.yuiseki.net/tokyo-ckan/items.parquet`: one row per dataset. GeoParquet, with the footprint.
- `https://stac.yuiseki.net/tokyo-ckan/assets.parquet`: one row per file, with its format, media type, the
  period in its name, and its column names when CKAN knows them.

```sql
-- datasets from 港区 with a CSV that has a latitude column
select a.item_id, a.title, a.href
  from 'https://stac.yuiseki.net/tokyo-ckan/assets.parquet' a
 where a.collection = 't131032' and a.format = 'CSV'
   and list_contains(a.columns, '緯度');
```

Fetch with curl, requests or DuckDB. Cloudflare in front of this host has
answered `Python-urllib` with 403 before; send a User-Agent of your own.

## Comparing publishers: start from a family

Questions like "which of 文京区, 台東区 and 千代田区 has the most libraries"
need the same kind of list from each publisher. 43 names are used by
5 or more organisations; these are families, and each Item in one carries
`tokyo:family`. 23 of them are デジタル庁's 自治体標準オープンデータセット
(`tokyo:national_standard` is the number in its definition books, 01 公共施設一覧
and so on; ゴミ集積所一覧 and 観光ポイント are one character off the national names, and
their columns show they are 30 and 31). The others, such as スポーツ施設一覧 and 公立図書館情報, were
registered across Tokyo in batches without a national definition.

A shared name is a claim; the columns are the evidence. The first row of each
member's first CSV was read, and:

- `tokyo:family_layout_match` is true when the header equals the family's
  most common one, false when it differs, null when it could not be read
  (no CSV, a dead link, or a zip named .csv).

The match is exact, so it is strict. National families have more than one
layout in use because the definition books have versions (a later one adds
法人番号 as the second column) and a second, データモデル型 form whose columns
carry a prefix (投票所_全国地方公共団体コード). A false here often means "an
older or newer layout of the same thing", not "a different thing": compare
the headers before discarding a member.

`https://stac.yuiseki.net/tokyo-ckan/families/summary.csv` (and `families/index.json`, the same with the
dominant layout's column names) has one row per family:

| column | meaning |
|---|---|
| headers_checked | members whose first CSV header was read |
| headers_unread | members with no CSV, a dead link, or a zip named .csv |
| dominant_layout_count | members whose header equals the most common one exactly |
| dominant_layout_share | dominant_layout_count / headers_checked; unread members are in neither |
| unique_layouts | how many distinct headers the checked members use |
| standard_dataset_no | the national definition-book number, if any |

dominant_layout_share measures observed header convergence within a family,
not compliance with an external standard or semantic equivalence. A share of
1.00 means every readable member has the same column names; it does not say
those columns mean the same thing, or that they follow the definition book.
Read it before comparing: a family with a low share, or many unique layouts,
cannot be compared by concatenating files.

```sql
select organization_title, title, family_layout_match, ckan_url
  from 'https://stac.yuiseki.net/tokyo-ckan/items.parquet'
 where family = '公立図書館情報'
   and collection in ('t131016', 't131059', 't131067');
```

What a family does not settle. The same name can hold different things:
千代田区's 公共施設一覧 is close to a property register (public toilets,
storehouses, staff housing), while other wards list the facilities residents
use. Some members list facilities outside the publisher's area (sports
grounds on the 荒川 and 江戸川 banks, a ward's lodge in 軽井沢). Where a family
member is missing, the publisher may publish the same thing split by kind
under other names: 台東区 publishes one dataset per kind of facility, and no
公共施設一覧. Absence from a family is not absence of data.

## Fields that are derived, and how far to trust them

CKAN has no field for where a dataset is or what period it covers. STAC
requires both, so both are derived, and the derivation is named on every Item.

`tokyo:datetime_basis`, in the order tried:

| basis | Items | what the time is |
|---|---|---|
| resource-name | 2,955 | periods named in the file names: 令和4年度 is 2022-04-01 to 2023-03-31 in Tokyo |
| dataset-title | 2,156 | the same, from the dataset title |
| resource-created | 4,569 | the `created` date the publisher gave the files. Sometimes the date of the data (港区's photographs are dated by year), sometimes the date of upload |
| catalog-record | 18 | when the record was created in CKAN. Says nothing about the data |

Only `resource-name` and `dataset-title` are about the data. Filter on the
basis before using the time for anything that matters. Assets carry their own
`start_datetime`/`end_datetime` when their name names a period, so a dataset
with one file per year can be narrowed to the year you want.

`created` and `updated` on an Item are the CKAN record's times, as STAC
defines them. `updated` was rewritten for nearly every dataset when the
catalog moved in 2025; it is not when the data changed.

`tokyo:footprint_basis`:

| basis | Items | geometry |
|---|---|---|
| municipality | 5,477 | rectangles around the publishing ward, city, town or village |
| prefecture | 4,221 | rectangles around the whole of Tokyo, islands included |

The footprint is where the data can be, not where it is. A 港区 dataset may
list facilities outside 港区; a bureau's dataset may be about one building. The
whole-of-Tokyo geometry is a MultiPolygon of separate rectangles because one
rectangle would run from 沖ノ鳥島 (20N) to 奥多摩: a query on the sea between
the islands does not match, but a `bbox` test does, since `bbox` is one box.
Prefer the geometry.

## Other things that are not what they look like

- `ckan:size` on an asset is the catalog's own figure. It is rounded down to
  a KiB and is sometimes 1. It is not a measured size; `file:size` is left out
  until one is measured.
- `tokyo:format` is the publisher's label, normalised. The asset `type` follows
  the file name when there is one, so the two disagree for files labelled XLS
  that are .xlsx, or labelled KML that are zips. The `type` is what you will get.
- `table:columns` appears only on files CKAN loaded into its DataStore
  (11,664 in this build). Most of them are statistical tables. A file
  without it may still have columns; CKAN just does not know them.
- `tokyo:update_frequency` is the publisher's words (170 spellings). The class
  in `tokyo:update_frequency_class` is for filtering, and `other` means the
  words did not fit a class, not that they were unreadable.
- Licences: CC-BY-4.0 9,695, other 2, CC-BY-NC-ND-4.0 1. Each Item links its licence. Individual files can still
  carry third-party rights the record does not mention; check the publisher's
  page (`rel: related`) before redistributing.

## When nothing matches

The catalog holds only what is registered in 東京都オープンデータカタログ.
Many wards publish more on their own sites. No match here means not registered
here, not that the data does not exist.
