%global _empty_manifest_terminate_build 0 Name: python-apimapper Version: 0.7.9 Release: 1 Summary: API Mapper License: MIT URL: https://github.com/acdh-oeaw/apimapper Source0: https://mirrors.aliyun.com/pypi/web/packages/68/c6/eab4525895270166631c93dcf55687b5bd0b37e5f83be5b2445fd2488628/apimapper-0.7.9.tar.gz BuildArch: noarch Requires: python3-markdown Requires: python3-requests %description # API Wrapper ## Install package * from PyPi: pip install apimapper * from source: pip install -e . ## Unit Testing >pytest ## Usage * See https://github.com/acdh-oeaw/apimapper/blob/develop/demo/APIMapper%20Demo.ipynb * Multiple APIs (GND and VIAF) mapped to a common JSON schema VIAF only returns VIAF ID - which is contructed into a url using a "rule" ``` from apimapper import APIMapper from apimapper import config GND_PERSON_MAP = {config.DIRECT: {'uri': 'id', 'label': 'label'}} 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'}}}} GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} VIAF_PERSON_SOURCE = {config.URL: 'http://www.viaf.org/viaf/AutoSuggest', config.QUERY_FIELD: 'query'} gnd = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) viaf = APIMapper(VIAF_PERSON_SOURCE, VIAF_PERSON_MAP) apis = [gnd, viaf] results = [] for api in apis: res = api.fetch_results('Pratchett') results.extend(res) print(results) ``` * Using mapping rules Splitting the GND label field into meaningful subparts ``` from apimapper import APIMapper from apimapper import config GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} GND_PERSON_MAP = {config.DIRECT: {'label': 'label', 'uri': 'id'}, config.RULES: {'source': {config.RULE: '"GND"'}, 'label_name': {config.RULE: '"{p1}".split("|")[0].strip()', config.FIELDS: {'p1': 'label'}}, 'label_year': {config.RULE: '"{p1}".split("|")[1].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else ""', config.FIELDS: {'p1': 'label'}}, 'label_profession': {config.RULE: '"{p1}".split("|")[2].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else "{p1}".split("|")[1].strip()', config.FIELDS: {'p1': 'label'}}}} api = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) res = api.fetch_results('Rosalind Franklin') ``` * More example usage in apimapper/demo %package -n python3-apimapper Summary: API Mapper Provides: python-apimapper BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-apimapper # API Wrapper ## Install package * from PyPi: pip install apimapper * from source: pip install -e . ## Unit Testing >pytest ## Usage * See https://github.com/acdh-oeaw/apimapper/blob/develop/demo/APIMapper%20Demo.ipynb * Multiple APIs (GND and VIAF) mapped to a common JSON schema VIAF only returns VIAF ID - which is contructed into a url using a "rule" ``` from apimapper import APIMapper from apimapper import config GND_PERSON_MAP = {config.DIRECT: {'uri': 'id', 'label': 'label'}} 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'}}}} GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} VIAF_PERSON_SOURCE = {config.URL: 'http://www.viaf.org/viaf/AutoSuggest', config.QUERY_FIELD: 'query'} gnd = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) viaf = APIMapper(VIAF_PERSON_SOURCE, VIAF_PERSON_MAP) apis = [gnd, viaf] results = [] for api in apis: res = api.fetch_results('Pratchett') results.extend(res) print(results) ``` * Using mapping rules Splitting the GND label field into meaningful subparts ``` from apimapper import APIMapper from apimapper import config GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} GND_PERSON_MAP = {config.DIRECT: {'label': 'label', 'uri': 'id'}, config.RULES: {'source': {config.RULE: '"GND"'}, 'label_name': {config.RULE: '"{p1}".split("|")[0].strip()', config.FIELDS: {'p1': 'label'}}, 'label_year': {config.RULE: '"{p1}".split("|")[1].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else ""', config.FIELDS: {'p1': 'label'}}, 'label_profession': {config.RULE: '"{p1}".split("|")[2].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else "{p1}".split("|")[1].strip()', config.FIELDS: {'p1': 'label'}}}} api = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) res = api.fetch_results('Rosalind Franklin') ``` * More example usage in apimapper/demo %package help Summary: Development documents and examples for apimapper Provides: python3-apimapper-doc %description help # API Wrapper ## Install package * from PyPi: pip install apimapper * from source: pip install -e . ## Unit Testing >pytest ## Usage * See https://github.com/acdh-oeaw/apimapper/blob/develop/demo/APIMapper%20Demo.ipynb * Multiple APIs (GND and VIAF) mapped to a common JSON schema VIAF only returns VIAF ID - which is contructed into a url using a "rule" ``` from apimapper import APIMapper from apimapper import config GND_PERSON_MAP = {config.DIRECT: {'uri': 'id', 'label': 'label'}} 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'}}}} GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} VIAF_PERSON_SOURCE = {config.URL: 'http://www.viaf.org/viaf/AutoSuggest', config.QUERY_FIELD: 'query'} gnd = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) viaf = APIMapper(VIAF_PERSON_SOURCE, VIAF_PERSON_MAP) apis = [gnd, viaf] results = [] for api in apis: res = api.fetch_results('Pratchett') results.extend(res) print(results) ``` * Using mapping rules Splitting the GND label field into meaningful subparts ``` from apimapper import APIMapper from apimapper import config GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search', config.QUERY_FIELD: 'q', config.PAYLOAD: {'format':'json:suggest', 'filter': 'type:Person'}} GND_PERSON_MAP = {config.DIRECT: {'label': 'label', 'uri': 'id'}, config.RULES: {'source': {config.RULE: '"GND"'}, 'label_name': {config.RULE: '"{p1}".split("|")[0].strip()', config.FIELDS: {'p1': 'label'}}, 'label_year': {config.RULE: '"{p1}".split("|")[1].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else ""', config.FIELDS: {'p1': 'label'}}, 'label_profession': {config.RULE: '"{p1}".split("|")[2].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else "{p1}".split("|")[1].strip()', config.FIELDS: {'p1': 'label'}}}} api = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP) res = api.fetch_results('Rosalind Franklin') ``` * More example usage in apimapper/demo %prep %autosetup -n apimapper-0.7.9 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-apimapper -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Tue Jun 20 2023 Python_Bot - 0.7.9-1 - Package Spec generated