fpdn / docs /gazette.md
fil's picture
something readable
1be7f91
|
raw
history blame
1.58 kB

Gazette

import { DuckDBClient } from "npm:@observablehq/duckdb";
const db = DuckDBClient.of({ presse: FileAttachment("data/presse.parquet") });

This page allows you to explore the 3 million newspapers by title. I called it “Gazette” because I was surprised that most of the corpus in the earlier years had a title containing this word.

Type in words such as “jeune”, “révolution”, “république”, “soir”, “fille”, “femme”, “paysan”, “ouvrier”, “social”, etc., to see different historical trends.

const search = view(
  Inputs.text({ type: "search", value: "gazette", submit: true })
);
display(
  Plot.plot({
    x: { nice: true },
    y: {
      label: `Share of titles matching ${search}`,
      tickFormat: "%",
    },
    marks: [
      Plot.areaY(gazette, {
        x: "year",
        y: (d) => d.matches / d.total,
        fillOpacity: 0.2,
      }),
      Plot.lineY(gazette, {
        x: "year",
        y: (d) => d.matches / d.total,
      }),
    ],
  })
);

The query uses the REGEXP_MATCHES operator to count occurrences; you can query for example “socialis[tm]e” to match both “socialiste” and “socialisme”. The 'i' flag makes it ignore case.

const gazette = db.query(
  `SELECT year
       , SUM(CASE WHEN REGEXP_MATCHES(title, ?, 'i') THEN 1 ELSE 0 END)::int matches
       , COUNT(*) total
    FROM presse
   WHERE year > '1000'
GROUP BY year
ORDER BY year
`,
  [search]
);