def _sieve(self, multiple_records):
<EOL>GnrStore = self._store<EOL>def writeAsJson(term, results):<EOL><INDENT>record = {'<STR_LIT>': term}<EOL>if len(results) > <NUM_LIT:0>:<EOL><INDENT>record['<STR_LIT>'] = results<EOL><DEDENT>return record<EOL><DEDENT>def boolResults(results, bool_li, rand=False):<EOL><INDENT>if rand:<EOL><INDENT>results = [results[<NUM_LIT:0>]]<EOL><DEDENT>elif sum(bool_li) == <NUM_LIT:1>:<EOL><INDENT>results = [results[bool_li.index(<NUM_LIT:1>)]]<EOL><DEDENT>elif sum(bool_li) == <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>else:<EOL><INDENT>results = [result for i, result in enumerate(results) if<EOL>bool_li[i]]<EOL><DEDENT>return results<EOL><DEDENT>sieved = []<EOL>ranks = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:class>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>']<EOL>for term in multiple_records:<EOL><INDENT>results = GnrStore[term]<EOL>while len(results) > <NUM_LIT:1>:<EOL><INDENT>scores = [result['<STR_LIT>'] for result in results]<EOL>bool_score = [<NUM_LIT:1> if score == max(scores) else <NUM_LIT:0> for score in<EOL>scores]<EOL>results = boolResults(results, bool_score)<EOL>if self.lowrank:<EOL><INDENT>res_ranks = [result['<STR_LIT>'].<EOL>split('<STR_LIT:|>') for result in results]<EOL>nmd_rnks = []<EOL>unnmd_rnks = []<EOL>for rs in res_ranks:<EOL><INDENT>nmd_rnks.append(min([j for j,e in enumerate(ranks) if<EOL>e in rs]))<EOL>unnmd_rnk = [j for j,e in enumerate(rs) if<EOL>e == ranks[nmd_rnks[-<NUM_LIT:1>]]][<NUM_LIT:0>]<EOL>unnmd_rnk -= len(rs)<EOL>unnmd_rnks.append(unnmd_rnk)<EOL><DEDENT>unnmd_rnks = [e if nmd_rnks[j] == min(nmd_rnks) else <NUM_LIT:0> for<EOL>j,e in enumerate(unnmd_rnks)]<EOL>bool_rank = [<NUM_LIT:1> if e == min(unnmd_rnks) else <NUM_LIT:0> for e in<EOL>unnmd_rnks]<EOL>results = boolResults(results, bool_rank)<EOL><DEDENT>results = boolResults(results, [], rand=True)<EOL><DEDENT>record = writeAsJson(term, results)<EOL>sieved.append(record)<EOL><DEDENT>return sieved<EOL>
Return json object without multiple returns per resolved name.\
Names with multiple records are reduced by finding the name in the clade of\
interest, have the highest score, have the lowest taxonomic rank (if lowrank is
true) and/or are the first item returned.