<jupyter_start><jupyter_text>API Mapper Demo  Setup<jupyter_code>from apimapper import config, APIMapper
from pprint import pprint<jupyter_output><empty_output><jupyter_text>ConfigurationAPIMapper needs two parameters source (details to query the API)and mapping (correspondence between fields in the original API response and the desired fields)  SOURCE<jupyter_code>##<jupyter_output><empty_output><jupyter_text>MAPPING  Direct mapping from JSON response to desired fieldnames in wrapped response  DBPediaDirect 1-1 Mapping from a field called "results" in the response<jupyter_code>DBPEDIA_SOURCE = {config.URL: 'http://lookup.dbpedia.org/api/search/PrefixSearch?',
                  config.QUERY_FIELD: 'QueryString'}

DBPEDIA_MAP = {config.RESULT: 'results',
               config.DIRECT: {'label': 'label',
                               'uri': 'uri'}}

api = APIMapper(DBPEDIA_SOURCE, DBPEDIA_MAP)
res = api.fetch_results('Shania')
pprint(res)<jupyter_output>[{'label': 'Shania Twain', 'uri': 'http://dbpedia.org/resource/Shania_Twain'},
 {'label': 'Shania Twain (album)',
  'uri': 'http://dbpedia.org/resource/Shania_Twain_(album)'},
 {'label': 'Shania Twain discography',
  'uri': 'http://dbpedia.org/resource/Shania_Twain_discography'},
 {'label': 'Live (Shania Twain video)',
  'uri': 'http://dbpedia.org/resource/Live_(Shania_Twain_video)'},
 {'label': 'List of awards received by Shania Twain',
  'uri': 'http://dbpedia.org/resource/List_of_awards_received_by_Shania_Twain'}]<jupyter_text>GNDDirect 1-1 mapping from the response<jupyter_code>GND_PERSON_MAP = {config.DIRECT: {'uri': 'id',
                                  'label': 'label'}}
GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search',
                     config.QUERY_FIELD: 'q',
                     config.PAYLOAD: {'format':'json:suggest',
                                      'filter': 'type:Person'}}
gnd_api = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP)
res = gnd_api.fetch_results('Pratchett')
pprint(res)<jupyter_output>[{'label': '<NAME> | 1948-2015 | Journalist, Schriftsteller',
  'uri': 'https://d-nb.info/gnd/119252880'},
 {'label': '<NAME> | 1976- | Journalistin, Drehbuchautorin',
  'uri': 'https://d-nb.info/gnd/1037047303'},
 {'label': '<NAME> | [19XX]- | Anglistin, Übersetzerin',
  'uri': 'https://d-nb.info/gnd/1054048231'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/13788365X'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/15259440X'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/1164173618'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/185977111'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/1150939907'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/140745769'},
 {'label': 'Pratchett, <NAME>.', 'uri': 'https://d-nb.info/gnd/109496011X'}]<jupyter_text>Applying simple ruules on the response values  VIAF - Direct 1-1 mapping from a field called "result"- Constructing URI from the response field called VIAFID. i.e., ```{... 'result': {[... {...'displayForm':'<NAME>, 1948-2015','uri': '41318026'} ...]}}```becomes```[...{'label': '<NAME>, 1948-2015',  'uri': 'http://www.viaf.org/viaf/76382712'}, ...]```<jupyter_code>VIAF_PERSON_MAP = {config.RESULT: 'result',
                   config.FILTER: {'nametype': 'personal'},
                   config.DIRECT: {'label': 'displayForm'},
                   config.RULES: {'uri': {config.RULE: '"http://www.viaf.org/viaf/{p1}"',
                                          config.FIELDS: {'p1': 'viafid'}}}}

    
VIAF_PERSON_SOURCE =  {config.URL: 'http://www.viaf.org/viaf/AutoSuggest',
                       config.QUERY_FIELD: 'query'}
           
viaf_api = APIMapper(VIAF_PERSON_SOURCE, VIAF_PERSON_MAP, timeout=1)
res = viaf_api.fetch_results('Pratchett')
pprint(res)<jupyter_output>[{'label': '<NAME>, 1948-2015',
  'uri': 'http://www.viaf.org/viaf/76382712'},
 {'label': 'Pratchett, Rhianna', 'uri': 'http://www.viaf.org/viaf/41318026'},
 {'label': 'Pratchett, Lawrence', 'uri': 'http://www.viaf.org/viaf/37216918'},
 {'label': 'Pratchett, <NAME>', 'uri': 'http://www.viaf.org/viaf/105358095'},
 {'label': '<NAME>',
  'uri': 'http://www.viaf.org/viaf/74148449587015690502'},
 {'label': 'Pratchett, Morgan', 'uri': 'http://www.viaf.org/viaf/304310389'}]<jupyter_text>GND and VIAF for personCombined response:- URI: `GND:id, VIAF:http://www.viaf.org/viaf/AutoSuggest/{viafid}`- LABEL: `GND:label, VIAF:displayForm`<jupyter_code>results = []
for api in (gnd_api, viaf_api):            
    res = api.fetch_results('Pratchett')
    results.extend(res)

pprint(results)<jupyter_output>[{'label': '<NAME> | 1948-2015 | Journalist, Schriftsteller',
  'uri': 'https://d-nb.info/gnd/119252880'},
 {'label': '<NAME> | 1976- | Journalistin, Drehbuchautorin',
  'uri': 'https://d-nb.info/gnd/1037047303'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/13788365X'},
 {'label': '<NAME> | [19XX]- | Anglistin, Übersetzerin',
  'uri': 'https://d-nb.info/gnd/1054048231'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/15259440X'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/1164173618'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/185977111'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/1150939907'},
 {'label': '<NAME>', 'uri': 'https://d-nb.info/gnd/140745769'},
 {'label': 'Pratchett, <NAME>.', 'uri': 'https://d-nb.info/gnd/109496011X'},
 {'label': 'Pratchett, Terry, 1948-2015',
  'uri': 'http://www.viaf.org/viaf/76382712'},
 {'label': 'Pratchett, Rhianna[...]
{'fraction_non_alphanumeric': 0.2151829601310759, 'fraction_numerical': 0.061714909885308575, 'mean_word_length': 4.134579439252336, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 46, 'https://': 21, 'lorem ipsum': 0, 'www.': 11, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '530312', 'license': 'MIT', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2066, 'n_words': 349, 'path': 'demo/APIMapper Demo.ipynb', 'repo_name': 'acdh-oeaw/apimapper', 'size': '5738'}