Package: pydracor
pydracorpydracor is a Python package which provides access to theDraCor 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.ClassesDraCorBase class used to represent Drama Corpus entity.
DraCor consists of Corpora.CorpusA 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.PlayA class used to represent a Play of a Corpus.
Play consists of Characters.CharacterA class used to represent a Character of a Play.Code examplesImport all classes>>>frompydracorimport*DracorInitialize aDraCorinstance>>>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")CorpusInitialize aCorpusinstance>>>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.years_written()>>>corpus.years_premiered()>>>corpus.years_normalized()List of metadata for all plays in a corpus>>>corpus.metadata()Filter Plays of a CorpusFilters are equivalent to the django filtersPossible relations:eq/ne/gt/ge/lt/le/contains/icontains/exact/iexact/inPossible fields: all the attributes that theCorpusinstance contains>>>corpus.filter(year_written__eq=1913,network_size__lt=20)>>>corpus.filter(year_printed__lt=1850,source__icontains='lib.ru',year_premiered__gt=1845)>>>corpus.filter(id__in=frozenset(f"rus000{num:03d}"fornuminrange(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='Бабель')PlayInitialize aPlayinstanceIfplay_idis not None,play_nameandplay_titleare not consideredIfplay_idis NoneANDplay_nameis not None,play_titleis not consideredIfplay_idis NoneANDplay_nameis None,play_titleshould not be None, otherwiseValueErroris raisedIfplay_idis 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_characters()Get X of a play>>>play.num_of_male_characters>>>play.num_of_female_characters>>>play.num_of_unknown_characters>>>play.tei>>>play.csv>>>play.gexfGet 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()CharacterInitialize aCharacterinstance>>>character=Character('yakov','rus000138')>>>character=Character('kraft','rus000137')...Summary in a dictionary>>>character.summary()Summary in a string>>>str(character)WikidataInitialize aWikidatainstance>>>wikidata=Wikidata()Get author information by WikidataID>>>author_info=Wikidata.get_author_info_by_id("Q34628")Get Wikidata Mix'n'match information as CSV>>>wikidata_mixnmatch=Wikidata.mixnmatch()Installation$pipinstallpydracorTodoswrite more methodswrite more testsLicenseMIT