A tool for pulling word occurrence ('n-gram') data from the Gallica periodical archive.
Project description
gallicaGetter
This tool wraps a few endpoints from the Gallica API to allow multi-threaded data retrieval with support for generators. Go ahead, explore some archived French periodicals, and a few international editions too!
I developed this tool into a graphing app similar to Google's n-gram viewer for books.
I owe inspiration for part of the API integration to queries written by the team at Gallicagram.
Current endpoints are:
- 'sru' -- for a term, get the number of occurrences over a time range or fetch all the periodical issues the term appears in.
- 'content' -- occurrence context and page numbers
- 'papers' -- paper titles and publishing range data, from their Gallica codes
- 'issues' -- years published for a given paper (used internally in papers)
Installation
pip install gallicaGetter
SRU examples
Retrieve the number of occurrences of "Victor Hugo" across the Gallica archive from 1800 to 1900, by year, running 30 requests in parallel.
import gallicaGetter
sruWrapper = gallicaGetter.connect('sru', numWorkers=30)
records = sruWrapper.get(
terms="Victor Hugo",
startDate="1800",
endDate="1900",
grouping="year"
)
for record in records:
print(record.getRow())
Retrieve all issues that mention "Brazza" from 1890 to 1900.
import gallicaGetter
sruWrapper = gallicaGetter.connect('sru')
records = sruWrapper.get(
terms="Brazza",
startDate="1890",
endDate="1900",
grouping="all"
)
for record in records:
print(record.getRow())
Retrieve all occurrences of "Brazza" within 10 words of "Congo" in the paper "Le Temps" from 1890 to 1900.
import gallicaGetter
sruWrapper = gallicaGetter.connect('sru')
records = sruWrapper.get(
terms="Brazza",
startDate="1890",
endDate="1900",
linkTerm="Congo",
linkDistance=10,
grouping="all",
codes="cb34431794k"
)
for record in records:
print(record.getRow())
Retrieve all issues mentioning "Paris" in the papers "Le Temps" and "Le Figaro" from 1890 to 1900, using a generator.
import gallicaGetter
sruWrapper = gallicaGetter.connect('sru')
recordGenerator = sruWrapper.get(
terms="Paris",
startDate="1890",
endDate="1900",
grouping="all",
codes=["cb34431794k", "cb34355551z"],
generate=True
)
for i in range(10):
print(next(recordGenerator).getRow())
Get occurrence series for more than one term by passing a list.
import gallicaGetter
sruWrapper = gallicaGetter.connect('sru')
records = sruWrapper.get(
terms=["Paris", "Londres"],
startDate="1890",
endDate="1900",
grouping="year"
)
for record in records:
print(record.getRow())
Content example
This wrapper pairs best with an SRU fetch since the ark code for an issue is in the SRU response.
Retrieve text context for all occurrences of "guerre" in an issue of the Figaro.
import gallicaGetter
contentWrapper = gallicaGetter.connect('content')
data = contentWrapper.get(
ark='bpt6k270178t',
term='guerre',
)
for numOccurrences, pages in data:
print(numOccurrences, pages)
Papers example
Retrieve metadata from a Gallica periodical's code. Example for "Le Temps":
import gallicaGetter
papersWrapper = gallicaGetter.connect('papers')
metadata = papersWrapper.get('cb34431794k')
for record in metadata:
print(record.getRow())
print(record.isContinuous())
Issues example
The papers wrapper calls this internally, but it might be useful. For a paper code, retrieve all years with at least one issue archived on Gallica.
import gallicaGetter
issuesWrapper = gallicaGetter.connect('issues')
years = issuesWrapper.get('cb34431794k')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gallicagetter-0.0.4.tar.gz
.
File metadata
- Download URL: gallicagetter-0.0.4.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0325891e20a8e43e6e89d4a49c27c41b7fff3249d0a27aff43b226be959ea112 |
|
MD5 | bf8e410ac27889b5a8638c1ddd6f77c2 |
|
BLAKE2b-256 | 373bc8e466a27942d353a2e8d862f782d0528c184cd8a366a6de96a8eecfa5fc |
File details
Details for the file gallicagetter-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: gallicagetter-0.0.4-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01b556b2bb835632dce3d01f3f62ac73828ece946d768fc155b70c698039104d |
|
MD5 | ddf83f9ef9f0556d848b04d38d50a434 |
|
BLAKE2b-256 | b220d288acbae4467cc3fd5e1e88d8344d9521ffe1d98bdefc343e0b467c7fee |