Project

General

Profile

« Previous | Next » 

Revision 50035

made a new look

View differences:

es_connector.py
8 8
from os import path
9 9

  
10 10

  
11
def get_property():
11
pid_resolver = {
12
    "pdb": "http://www.rcsb.org/pdb/explore/explore.do?structureId=%s",
13
    "ncbi-n": "http://www.ncbi.nlm.nih.gov/gquery/?term=%s",
14
    "pmid": "http://www.ncbi.nlm.nih.gov/pubmed/%s",
15
    "pmcid": "http://www.ncbi.nlm.nih.gov/pmc/articles/%s",
16
    "pubmedid": "http://www.ncbi.nlm.nih.gov/pubmed/%s",
17
    "doi": "http://dx.doi.org/%s",
18
    "genbank": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
19
    "nuccore": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
20
    "swiss-prot": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
21
    "arrayexpress": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
22
    "biomodels": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
23
    "bmrb": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
24
    "ena": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
25
    "geo": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
26
    "ensembl": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
27
    "mgi": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
28
    "bind": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
29
    "pride": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
30
    "ddbj": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
31
    "bioproject": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
32
    "embl": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
33
    "sra": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
34
}
12 35

  
13 36

  
37
def resolveIdentifier(pid, pid_type):
38
    if pid_type!= None:
39
        if pid_type.lower() in  pid_resolver:
40
            return pid_resolver[pid_type.lower()] % pid
41
        else:
42
            if pid_type.lower() == 'openaire':
43
                return "https://www.openaire.eu/search/publication?articleId=%s"%pid.replace('oai:dnet:','')
44
            else:
45
                return "http://identifiers.org/%s:%s" % (pid_type, pid)
46
    return ""
47

  
48
def get_property():
14 49
    f = open(path.join(os.path.dirname(os.path.realpath(__file__)), '../../api.properties'))
15 50
    p = {}
16 51
    for line in f:
......
97 132
        hits = []
98 133

  
99 134
        for index_result in response.hits:
100
            hits.append(index_result.__dict__['_d_'])
135
            input_source = index_result.__dict__['_d_']
136
            fixed_titles = []
101 137

  
138
            for ids in  input_source.get('localIdentifier',[]):
139
                ds = resolveIdentifier(ids['id'], ids['type'])
140
                ids['url'] = ds
141
            for t in input_source.get('title',[]):
142
                if len(t) > 0 and t[0] == '"' and t[-1] == '"':
143
                    fixed_titles.append(t[1:-1])
144
                else:
145
                    fixed_titles.append(t)
146
            input_source['title'] = fixed_titles
147
            hits.append(input_source)
148

  
102 149
        pid_types = []
103 150
        for tag in response.aggs.all_pids.all_types.buckets:
104 151
            pid_types.append(dict(key=tag.key, count=tag.doc_count))
......
138 185
        return hits
139 186

  
140 187
    def fix_collectedFrom(self, source, relation):
188
        if relation is None:
189
            return
141 190
        relSource = relation.get('source')
142 191
        collectedFrom = relSource['collectedFrom']
143 192
        for coll in collectedFrom:
......
151 200
            res = self.client.get(index=self.index_name, doc_type='object', id=id)
152 201
            hits = []
153 202
            input_source = res['_source']
203
            fixed_titles = []
204
            for t in input_source.get('title'):
205
                if len(t) >0 and t[0]=='"' and t[-1]=='"':
206
                    fixed_titles.append(t[1:-1])
207
                else:
208
                    fixed_titles.append(t)
209
            input_source['title'] = fixed_titles
210

  
211
            for ids in  input_source.get('localIdentifier',[]):
212
                ds = resolveIdentifier(ids['id'], ids['type'])
213
                ids['url'] = ds
154 214
            related_publications = []
155 215
            related_dataset = []
156 216
            related_unknown = []
......
161 221
                    related_publications = self.related_type(id, 'publication', start)
162 222
                else:
163 223
                    related_publications = self.related_type(id, 'publication')
164
                rel_source = related_publications[0]
224
                if len(related_publications) >0 :
225
                    rel_source = related_publications[0]
226
                else:
227
                    rel_source = {}
165 228
            if input_source.get('relatedDatasets') > 0:
166 229
                if 'dataset' == type:
167 230
                    related_dataset = self.related_type(id, 'dataset', start)

Also available in: Unified diff