-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmtcher.py
73 lines (44 loc) · 1.74 KB
/
mtcher.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
import json
from collections import OrderedDict
json_file = 'map.json'
json_data=open(json_file)
j = json.load(json_data,object_pairs_hook=OrderedDict)
j_array = j['map']['product']['lbu']['locale']['concepts']['concept'] + j['map']['product']['lbu']['locale']['fields']['field'] + j['map']['product']['lbu']['locale']['references']['reference'] + j['map']['product']['lbu']['locale']['tasks']['task'] + j['map']['product']['lbu']['locale']['topics']['topic']
#print len(j_array)
#j_j = j_array[0]
#print j_j['@group']
def add_single_or_array(s):
ret=''
if isinstance(s,OrderedDict):
if '#text' in s:
ret = ret + s['#text']
if '#tail' in s:
ret = ret +' '+ s['#tail']
return ret
else:
for arr in s:
#print arr
ret = ret + add_single_or_array(arr)
return ret
#uni_code_text = ''.join(i for i in row['comments'] if ord(i)<128)
def constructfull(innerjson):
if isinstance(innerjson, basestring):
return innerjson
else:
ns=''
if '#text' in innerjson:
ns = ns + innerjson['#text']
for keys in innerjson:
if keys != '#text':
k = innerjson[keys]
ns = ns + ' '+add_single_or_array(k)
return ns
def get_abstract( text ):
for val in j_array:
if val['title'] == text:
return val['abstract']
#p = get_abstract('What is a results list?')
#Tutorial: Getting Started with Lexis Advance\u00ae
for val in j_array:
if (val['abstract']):
print constructfull(val['abstract'])