Skip to main content

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 quickstart

Build the wrapper object using the connect() factory:

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru')

Then, retrieve records or counts using get().

get(terms, generate=False, **params)

PARAMETERS:

  • terms: a string, or list of strings, to search for.
  • startDate: lower year boundary for the search.
  • endDate: upper year boundary for the search.
  • codes: string paper codes to restrict the search. Can be found in the URL of a Gallica periodical's page.
  • grouping: 'year', 'month', or 'all'.
    • year: returns a count of occurrences for each year in the range.
    • month: returns a count of occurrences per month in the range.
    • all: fetches metadata (a Record object) for each occurrence.
  • generate: if True, returns a generator object. Otherwise, returns a list of results.
    • If you're using the 'all' grouping, a generator can help reduce memory usage for large requests. Still working out the behavior.
  • linkTerm: a string that restricts the search to occurrences within its proximity.
  • linkDistance: proximity distance, in words.
  • numRecords: limit number of records to return.

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())

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gallicagetter-0.0.5.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

gallicagetter-0.0.5-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file gallicagetter-0.0.5.tar.gz.

File metadata

  • Download URL: gallicagetter-0.0.5.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for gallicagetter-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ac9a2936664c436fe3caf3789ecb769a66414796bb4fdff9fa13b8b2fb02a0bc
MD5 c48bd3f05df9984d8459401350c4bc46
BLAKE2b-256 04c6b3f6b6b429d09879aec4018d8182a074f9c732aed9c22f687d25a96ead32

See more details on using hashes here.

File details

Details for the file gallicagetter-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for gallicagetter-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 85f4dde0a224766c6d1ff24c9c1fb7676eca63c893dbd79249759c37ed551841
MD5 02a46cc7ce44aefffa5854a6210457f5
BLAKE2b-256 f258aedb7440c796debc2ff8b1c95d5080c90fc048525eaf791f7f3618028423

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page