forked from UUDigitalHumanitieslab/HistoLexic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
histolexic.py
74 lines (56 loc) · 2.07 KB
/
histolexic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This is a basic standalone version of the HistoLexic demontstrator in Python
# Uses the requests package (http://docs.python-requests.org/en/latest/)
import requests
BASE_URL = 'http://lexiconservice.inl.nl/lexicon/'
LEMMA_URL = 'get_lemma'
WORDFORM_URL = 'get_wordforms'
EXPAND_URL = 'expand'
def find_lemma(wordform):
print '====='
print 'Finding lemmata of ' + wordform
search_term = dict()
search_term['database'] = 'lexicon_service_db'
search_term['wordform'] = wordform
#search_term['year_from'] = 1600
#search_term['year_to'] = 2000
#search_term['pos'] = 'VRB'
r = requests.get(BASE_URL + LEMMA_URL, params=search_term, headers={'Accept': 'application/json'})
print 'url: ' + r.url
print 'lemmata: '
for j in r.json()['lemmata_list']:
for l in j['found_lemmata']:
print l['lemma'] + ' - ' + l['pos'] + ', ',
def find_wordform(lemma):
print ''
print '====='
print 'Finding wordforms of ' + lemma
search_term = dict()
search_term['database'] = 'lexicon_service_db'
search_term['lemma'] = lemma
#search_term['year_from'] = 1900
#search_term['year_to'] = 2000
#search_term['pos'] = 'VRB'
r = requests.get(BASE_URL + WORDFORM_URL, params=search_term, headers={'Accept': 'application/json'})
print 'url: ' + r.url
print 'wordforms:'
for j in r.json()['wordforms_list']:
print ', '.join(j['found_wordforms'])
def expand(wordform):
print '====='
print 'Expanding wordform ' + wordform
search_term = dict()
search_term['database'] = 'lexicon_service_db'
search_term['wordform'] = wordform
#search_term['year_from'] = 1600
#search_term['year_to'] = 2000
#search_term['pos'] = 'VRB'
r = requests.get(BASE_URL + EXPAND_URL, params=search_term, headers={'Accept': 'application/json'})
print 'url: ' + r.url
print r.request.headers
print 'wordforms:'
for j in r.json()['wordforms_list']:
print ', '.join(j['found_wordforms'])
if __name__ == "__main__":
find_lemma('bank')
find_wordform('bank')
expand('bank')