Skip to main content

pydracor

pydracor is a Python package which provides access to the DraCor API. It is based on pydracor-base which was automatically generated using OpenAPITools.

Acknowledgment:

The development of this package was supported by Computational Literary Studies Infrastructure (CLS INFRA). CLS INFRA has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 101004984.

Installation

pip install pydracor

Classes

  • DraCorAPI

    Base class used to represent the Drama Corpus entity with which Corpus and Play are created.

  • Corpus

    A class with which the corpora/{corpusname} endpoints can be requested

  • Play

    A class with which the corpora/{corpusname}/plays/{playname} endpoint can be requested

  • DTS

    A class with which the dts endpoints can be requested

  • Wikidata

    A class with which the wikidata endpoints can be requested

Code examples

Import all classes

from pydracor import DraCorAPI, Corpus, Play, Wikidata, DTS

Dracor

  • Initialize a DraCor instance

    dracor = DraCorAPI()
    
  • Initialize a local DraCor instance by setting the host

    dracor = DraCor(host="http://localhost:8088/api/v1")
    
  • Get summary as an Info object (/info)

    dracor.get_info()
    
  • Get the list of available corpora in DraCor (/info/copora) and get names

    corpora = dracor.get_corpora()
    corpora_metrics = dracor.get_corpora(include='metrics')
    corpora_names = [corpus.name for corpus in corpora]
    
  • Get the resolved id for a play (/id/{id})

    dracor.get_resolve_play_id("als000001")
    
  • Get the plays with characters by wikidata id

    dracor.get_plays_with_character_by_id("Q131412")
    

Corpus

  • Initialize a Corpus instance with the DraCor class (/corpora/{corpusname})

    corpus = dracor.get_corpus('rus')
    
  • Corpus info as dictionary

    corpus.to_dict()
    
  • Access corpus attributes, plays as a list of PlayInCorpus objects

    corpus.name
    corpus.plays
    
  • Extract all play ids from the corpus

    play_ids = [play.id for play in corpus.plays]
    
  • Filter plays: normalized year after 1800

    plays_after_1800 = [play for play in corpus.plays if play.year_normalized > 1800]
    
  • Get list of metadata for all plays in a corpus (/corpora/{corpusname}/metadata)

    metadata = corpus.metadata()
    
  • Filter plays: Number of Acts more than five

    plays_more_than_five_acts = [play for play in metadata if play.num_of_acts > 5]
    
  • Convert metadata to DataFrame

    import pandas as pd
    play_metadata_df = pd.DataFrame([play_metadata.to_dict() for play_metadata in metadata])
    
  • Get metadata as csv (/corpora/{corpus}/metadata/csv)

    metadata_csv = corpus.get_metadata_csv()
    
  • Create Play in corpus (corpora/{corpusname}/plays/{playname})

    play = corpus.get_play("gogol-revizor")
    

Play

  • Initialize a Play instance by corpus name and play name (corpora/{corpusname}/plays/{playname})

    play = dracor.get_play("ger","gengenbach-der-nollhart")
    
  • Extract summary in a dictionary

    play.to_dict()
    
  • Access Play attributes

    play.normalized_genre
    play.characters
    
  • Get and access network metrics for a single play (corpora/{corpusname}/plays/{playname}/metrics)

    metrics = play.get_metrics()
    metrics.average_degree
    
  • Get a list of characters of a play (corpora/{corpusname}/plays/{playname}/characters)

    characters = play.get_characters()
    
  • Convert character list to DataFrame

    import pandas as pd
    df = pd.DataFrame([character.to_dict() for character in characters])
    
  • Get a list of characters of a play as csv (corpora/{corpusname}/plays/{playname}/characters/csv)

    play.get_characters_csv()
    
  • Get networkdata of a play in different formats (corpora/{corpusname}/plays/{playname}/networkdata/{graphml, gexf, csv})

    play.get_networkdata("graphml")
    play.get_networkdata("gexf")
    play.get_networkdata("csv")
    
  • Get relations of a play in different formats (corpora/{corpusname}/plays/{playname}/relations/{graphml, gexf, csv})

    play.get_relations("graphml")
    play.get_relations("gexf")
    play.get_relations("csv")
    
  • Get spoken text of a play (excluding stage directions) (corpora/{corpusname}/plays/{playname}/spoken-text)

    play.get_spoken_text()
    play.get_spoken_text(sex='MALE')
    play.get_spoken_text(relation='siblings')
    
  • Get spoken text for each character of a play (corpora/{corpusname}/plays/{playname}/spoken-text-by-character)

    play.get_spoken_text_by_character()
    
  • Get stage directions of a play (corpora/{corpusname}/plays/{playname}/stage-directions)

    play.get_stage_directions()
    
  • Get stage directions and speaker text of a play (corpora/{corpusname}/plays/{playname}/stage-directions-with-speakers)

    play.get_stage_directions_with_speakers()
    

DTS (Distributed Text Services)

  • Initialize a DTS instance

    dts = DTS()
    
  • Get Entrypoint of the DraCor DTS implementation (/dts)

    dts.get_dts()
    
  • Get the list of the available collections of a corpus (/dts/collection)

    dts.get_collection("rus")
    
  • Use navigation endpoint of DTS (/dts/navigation)

    dts.get_navigation("rus000160", "body/div[1]")
    dts.get_navigation("rus000160", start="body/div[2]/div[1]", end="body/div[2]/div[2]")
    
  • Use document endpoint of DTS (/dts/document)

    dts.get_document("rus000160", "body/div[1]")
    dts.get_document("rus000160", start="body/div[2]/div[1]", end="body/div[2]/div[2]")
    

Wikidata

  • Initialize a Wikidata instance

    wikidata = Wikidata()
    
  • Get author information by WikidataID

    author_info = wikidata.get_author_info("Q34628")
    
  • Get Wikidata Mix'n'match information as CSV

    wikidata_mixnmatch = wikidata.get_mixnmatch()
    

License

MIT

Metadata

Release files for pydracor 3.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydracor 3.0.2
File Size Uploaded
pydracor-3.0.2.tar.gz 72.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydracor 3.0.2
File Interpreter ABI Platform
pydracor-3.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 81.0 kB

Release files / pydracor-3.0.2.tar.gz

Download URL pydracor-3.0.2.tar.gz
Size 72.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2ffe229db4b3b0c24772331adfc84d27bf639721df15ee3d7a28ef5b3d6289f8
BLAKE2b-256 checksum
How to use checksums
426d8557c603651678212ed5c0093a83fa568337dc1c27212a59d9e32c7f2fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / pydracor-3.0.2-py3-none-any.whl

Download URL pydracor-3.0.2-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d91ceb98bf68ef8cda8e0a55b742ddc23f788e684662dfadbeb2c764d3955bee
BLAKE2b-256 checksum
How to use checksums
cbb5d09e76bbcad086953c26ec1dcc24a47a6c5b17b2d256636c869ff4d690a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

3.0.2 This release

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

0.0.1

1 release file

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page