File size: 1,576 Bytes
1be7f91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Gazette

```js echo
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.

```js
const search = view(
  Inputs.text({ type: "search", value: "gazette", submit: true })
);
```

```js echo
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](https://duckdb.org/docs/archive/0.9.2/sql/functions/patternmatching) 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.

```js echo
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]
);
```