Skip to content

Instantly share code, notes, and snippets.

@JaimieMurdock
Last active March 31, 2016 00:24
Show Gist options
  • Save JaimieMurdock/89b943bed88b69ab5a503f8bd03b6979 to your computer and use it in GitHub Desktop.
Save JaimieMurdock/89b943bed88b69ab5a503f8bd03b6979 to your computer and use it in GitHub Desktop.
InPhO SEP-Wikipedia Crosswalk
#!/usr/bin/env python
import codecs
import json
import urllib.request
import sys
# 1. Get Data from InPhO API
# https://inpho.cogs.indiana.edu/docs/
# select datatype from ['entity', 'idea', 'thinker']
datatype = 'entity'
INPHO_URL = 'https://inpho.cogs.indiana.edu/{}.json'.format(datatype)
print("Fetching InPhO data from " + INPHO_URL, file=sys.stderr)
with urllib.request.urlopen(INPHO_URL) as response:
reader = codecs.getreader('utf8')
inpho = json.load(reader(response))
inpho = inpho['responseData']['results']
# build dictionary from sep articles to wiki pages,
# and wiki pages to sep articles
print("Building SEP-Wiki maps", file=sys.stderr)
sep_wiki = dict()
wiki_sep = dict()
for entity in inpho:
if entity.get('sep_dir') and entity.get('wiki'):
sep_wiki[entity['sep_dir']] = entity['wiki']
wiki_sep[entity['wiki']] = entity['sep_dir']
if __name__ == '__main__':
SEP_URL = 'http://plato.stanford.edu/entries/{}/'
WIKI_URL = 'https://en.wikipedia.org/wiki/{}'
for sep, wiki in sep_wiki.items():
print(','.join([sep,wiki,SEP_URL.format(sep),WIKI_URL.format(wiki)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment