Skip to content

Commit

Permalink
[edit] account for excess pubtators. #183
Browse files Browse the repository at this point in the history
  • Loading branch information
x0xMaximus committed Dec 7, 2016
1 parent e2acdce commit 7ecab9c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mark2cure/document/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ def run_pubtator(self):
1) Create Pubtator entries
2) Start checking for responses if pending
"""
kind_arr = ['tmChem', 'DNorm', 'GNormPlus']

# If the Document has excess Pubtators, cleanup
if self.pubtators.count() > 3:
for kind in kind_arr:
if self.pubtators.filter(kind=kind).count() > 1:
# Picks them off 1 run at a time (oldest first) until no duplicates remain
self.pubtators.filter(kind=kind).first().delete()

# If the Document is missing any Pubtator "kinds", it should get them
for missing_kind in list(set(['tmChem', 'DNorm', 'GNormPlus']) - set(self.pubtators.values_list('kind', flat=True))):
for missing_kind in list(set(kind_arr) - set(self.pubtators.values_list('kind', flat=True))):
Pubtator.objects.get_or_create(document=self, kind=missing_kind)

for pubtator in self.pubtators.filter(content__isnull=True).all():
Expand Down

0 comments on commit 7ecab9c

Please sign in to comment.