Read and search public data

Within a jupyter notebook you may autocomplete methods with the <tab> key, or get help on a method hitting <shift> and <tab>

You need to execute the cell once before this works, to have the import done.

Try it yourself: automplete the crud or tgsearch API calls below, or read the API doc for the crud.read_data or search.info method.

Getting raw data from tgcrud

from tgclients import TextgridCrud

crud = TextgridCrud()

# read the XML for https://textgridrep.org/textgrid:kv2q.0
crud.read_data('textgrid:kv2q.0')
<Response [200]>

Getting raw metadata from tgsearch

from tgclients import TextgridSearchRequest

# low level tgsearch for public data, to get raw xml
llsearch = TextgridSearchRequest()
llsearch.info('textgrid:kv2q.0').content
b'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tgs:response xmlns="http://textgrid.info/namespaces/metadata/core/2010" xmlns:tg="http://textgrid.info/relation-ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:tgs="http://www.textgrid.info/namespaces/middleware/tgsearch"><tgs:result textgridUri="textgrid:kv2q.0"><object><generic><provided><title>Alice im Wunderland</title><format>text/xml</format></provided><generated><created>2012-01-04T23:17:21.978+01:00</created><lastModified>2012-01-04T23:17:21.978+01:00</lastModified><issued>2012-01-04T23:17:21.978+01:00</issued><textgridUri extRef="">textgrid:kv2q.0</textgridUri><revision>0</revision><pid pidType="handle">hdl:11858/00-1734-0000-0002-4AFD-E</pid><extent>270772</extent><dataContributor>tvitt@textgrid.de</dataContributor><project id="TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c">Digitale Bibliothek</project><availability>public</availability></generated></generic><item><rightsHolder id="">TextGrid</rightsHolder></item></object></tgs:result></tgs:response>'

Getting metadata from tgsearch using databinding

Try navigating the XML databinding with autocompletion.

See https://textgridlab.org/1.0/tgsearch-public/info/textgrid:kv2q.0/ how the XML is structured.

Try printing the format of the object.

from tgclients import TextgridSearch

# tgsearch with databinding, for public data
search = TextgridSearch()

response = search.info('textgrid:kv2q.0')

# now again, try autocompletion for navigating the databinding
title = response.result[0].object_value.generic.provided.title[0]
print(title)
Alice im Wunderland