Skip to main content

Python package which provides access to the DraCor API.

Project description

pydracor

pydracor is a Python package which provides access to the DraCor API.

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.

Classes

  • DraCor

    Base class used to represent Drama Corpus entity. DraCor consists of Corpora.

  • Corpus

    A class used to represent a Corpus of DraCor. Corpus (als/bash/cal/fre/ger/gersh/greek/hun/ita/rom/rus/shake/span/swe/tat) consists of plays.

  • Play

    A class used to represent a Play of a Corpus. Play consists of Characters.

  • Character

    A class used to represent a Character of a Play.

Code examples

Import all classes

>>> from pydracor import *

Dracor

  • Initialize a DraCor instance
    >>> dracor = DraCor()
    
  • Summary in a dictionary
    >>> dracor.summary()
    
  • Summary in a string
    >>> str(dracor)
    
  • DraCor info in a dictionary
    >>> dracor.dracor_info()
    
  • List available corpora in DraCor
    >>> dracor.corpora()
    >>> dracor.corpora(include='metrics')
    
  • List available corpora names in DraCor
    >>> dracor.corpora_names()
    
  • List available corpora titles in DraCor
    >>> dracor.corpora_titles()
    
  • Map X to Y
    >>> dracor.corpus_name_to_repository()
    >>> dracor.corpus_name_to_title()
    >>> dracor.corpus_name_to_uri()
    >>> dracor.play_title_to_corpus_name()
    >>> dracor.play_title_to_play_id()
    >>> dracor.play_name_to_corpus_name()
    >>> dracor.play_name_to_play_id()
    >>> dracor.play_id_to_play_title()
    >>> dracor.play_id_to_play_name()
    
  • Submit SPARQL queries with query parameter
    >>> dracor.sparql("PREFIX urn: <http://fliqz.com/> SELECT *  FROM <urn:x-arq:UnionGraph> WHERE {?sub ?pred ?obj .} LIMIT 1")
    

Corpus

  • Initialize a Corpus instance

    >>> corpus = Corpus('rus')
    >>> corpus = Corpus('cal')
    ...
    
  • Summary in a dictionary

    >>> corpus.summary()
    
  • Summary in a string

    >>> str(corpus)
    
  • Authors' summary for a corpus

    >>> corpus.authors_summary()
    >>> corpus.authors_summary(num_of_authors=5)
    
  • String representation of authors_summary method

    >>> corpus.authors_summary_str()
    >>> corpus.authors_summary_str(num_of_authors=5)
    
  • Corpus info in a dictionary

    >>> corpus.corpus_info()
    
  • Get all corpus' play Xs

    >>> corpus.play_ids()
    >>> corpus.play_names()
    >>> corpus.play_titles()
    
  • Map play id to the X year

    >>> corpus.written_years()
    >>> corpus.premiere_years()
    >>> corpus.premiere_years()
    
  • List of metadata for all plays in a corpus

    >>> corpus.metadata()
    
  • Filter Plays of a Corpus

    Filters are equivalent to the django filters

    Possible relations: eq / ne / gt / ge / lt / le / contains / icontains / exact / iexact / in

    Possible fields: all the attributes that the Corpus instance contains

    >>> corpus.filter(written_year__eq=1913, network_size__lt=20)
    >>> corpus.filter(print_year__lt=1850, source__icontains='lib.ru', premiere_year__gt=1845)
    >>> corpus.filter(
        id__in=frozenset(f"rus000{num:03d}" for num in range(0, 250, 2)),
        subtitle__icontains='комедия',
        author__name__contains='Крылов'
    )
    >>> corpus.filter(name__contains='mysl')
    >>> corpus.filter(title__exact='Мысль')
    >>> corpus.filter(
        year_normalized__in=frozenset(['1935', '1936'])
        source_url__contains='lib'
    )
    >>> corpus.filter(wikidata_id__iexact='Q1989636')
    >>> corpus.filter(networkdata_csv_url__icontains='/andreyev-ne-ubiy/')
    >>> corpus.filter(authors__name__icontains='Бабель')
    

Play

  • Initialize a Play instance

    If play_id is not None, play_name and play_title are not considered

    If play_id is None AND play_name is not None, play_title is not considered

    If play_id is None AND play_name is None, play_title should not be None, otherwise ValueError is raised

    If play_id is None, automatic corpus detection is applied

    >>> play = Play('rus000160')
    >>> play = Play(play_id='rus000160')
    >>> play = Play(play_name='ostrovsky-dohodnoe-mesto')
    >>> play = Play(play_title='Доходное место')
    
  • Summary in a dictionary

    >>> play.summary()
    
  • Summary in a string

    >>> str(play)
    
  • Play info in a dictionary

    >>> play.play_info()
    
  • Get network metrics for a single play

    >>> play.metrics()
    
  • Get a list of characters of a play

    >>> play.get_cast()
    
  • Get X of a play

    >>> play.num_of_male_characters
    >>> play.num_of_female_characters
    >>> play.num_of_unknown_characters
    >>> play.tei
    >>> play.rdf
    >>> play.csv
    >>> play.gexf
    
  • Get spoken text of a play (excluding stage directions)

    >>> play.spoken_text()
    >>> play.spoken_text(gender='MALE')
    >>> play.spoken_text(gender='FEMALE')
    >>> play.spoken_text(gender='UNKNOWN')
    
  • Get spoken text for each character of a play

    >>> play.spoken_text_by_character()
    
  • Get all stage directions of a play

    >>> play.stage_directions()
    
  • Get all stage directions of a play including speakers

    >>> play.stage_directions_with_speakers()
    

Character

  • Initialize a Character instance
    >>> character = Character('yakov', 'rus000138')
    >>> character = Character('kraft', 'rus000137')
    ...
    
  • Summary in a dictionary
    >>> character.summary()
    
  • Summary in a string
    >>> str(character)
    

Installation

$ pip install pydracor

Todos

  • write more methods
  • write more tests

License

MIT

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

pydracor-1.0.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydracor-1.0.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file pydracor-1.0.0.tar.gz.

File metadata

  • Download URL: pydracor-1.0.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pydracor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b897bf82718243c1b4a9347080e109031e55ea8c02149bb4a50d149889cf50e4
MD5 89ba8d291baf59a1c91942e68a2638ba
BLAKE2b-256 e83eb0079b6ab037f55ba6037bc6d055a0830faf19ef94c3b48954d60d682d95

See more details on using hashes here.

File details

Details for the file pydracor-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydracor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pydracor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c76a1b912a106614e8bcfc8e074c25ce121383c46dc193c6b7324d4820e9ed25
MD5 4f890b8e0f9f7e6dc3bcc3debcbee289
BLAKE2b-256 51770f2a04a11c7982442cf427d1dcd21fd30b054a54b7ceee0a6d5ad700e110

See more details on using hashes here.

Supported by

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