Further improve snowballing
This commit is contained in:
1 parent
65a6008c8f
commit
854cdddad5
2 files changed
+20
-6
No files matched your search
@@ -64,6 +64,7 @@ class PublicationStageFilter(admin.SimpleListFilter):
|
|||||||
return (
|
return (
|
||||||
('primary', _("primary")),
|
('primary', _("primary")),
|
||||||
('secondary', _("secondary")),
|
('secondary', _("secondary")),
|
||||||
|
('2-secondary', _("2-secondary")),
|
||||||
('tertiary', _("tertiary")),
|
('tertiary', _("tertiary")),
|
||||||
('excluded', _("excluded")),
|
('excluded', _("excluded")),
|
||||||
('-', _("-")),
|
('-', _("-")),
|
||||||
@@ -95,6 +96,14 @@ class PublicationStageFilter(admin.SimpleListFilter):
|
|||||||
referenced_by__sources__isnull=False,
|
referenced_by__sources__isnull=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.value() == '2-secondary':
|
||||||
|
ids: Set[int] = {
|
||||||
|
publication.id
|
||||||
|
for publication in queryset
|
||||||
|
if publication.stage == '2-secondary'
|
||||||
|
}
|
||||||
|
return queryset.filter(id__in=ids)
|
||||||
|
|
||||||
if self.value() == '-':
|
if self.value() == '-':
|
||||||
ids: Set[int] = {
|
ids: Set[int] = {
|
||||||
publication.id
|
publication.id
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class Command(BaseCommand):
|
|||||||
if created:
|
if created:
|
||||||
self.echo(f"Added author: {author}")
|
self.echo(f"Added author: {author}")
|
||||||
else:
|
else:
|
||||||
self.echo(f"Author '{author}' alreay known")
|
self.echo(f"Author '{author}' already known")
|
||||||
authors.append(author)
|
authors.append(author)
|
||||||
cite_key = ''
|
cite_key = ''
|
||||||
if authors:
|
if authors:
|
||||||
@@ -147,20 +147,20 @@ class Command(BaseCommand):
|
|||||||
# Add publication to database
|
# Add publication to database
|
||||||
doi = data.get('doi', None)
|
doi = data.get('doi', None)
|
||||||
if not publication:
|
if not publication:
|
||||||
self.echo(f"Will create now with cite key {cite_key}")
|
|
||||||
publication = Publication.objects.create(
|
publication = Publication.objects.create(
|
||||||
cite_key=cite_key,
|
cite_key=cite_key,
|
||||||
title=title,
|
title=title,
|
||||||
year=data.get('year', 0),
|
year=data.get('year', 0),
|
||||||
peer_reviewed=None,
|
peer_reviewed=None,
|
||||||
doi=doi,
|
doi=doi,
|
||||||
|
abstract=data.get('abstract', None),
|
||||||
)
|
)
|
||||||
self.echo(f"Added publication: {publication}")
|
self.echo(f"Added publication: {publication}")
|
||||||
else:
|
else:
|
||||||
self.echo(f"Publication '{publication}' already known")
|
self.echo(f"Publication '{publication}' already known")
|
||||||
|
|
||||||
# Assign authors
|
# Assign authors
|
||||||
for position, author in enumerate(authors):
|
for position, author in enumerate(list(set(authors))):
|
||||||
publication_author, created = PublicationAuthor.objects.get_or_create(
|
publication_author, created = PublicationAuthor.objects.get_or_create(
|
||||||
author=author,
|
author=author,
|
||||||
publication=publication,
|
publication=publication,
|
||||||
@@ -242,11 +242,11 @@ class Command(BaseCommand):
|
|||||||
if abstract := data.get('abstract', None):
|
if abstract := data.get('abstract', None):
|
||||||
self.echo(abstract)
|
self.echo(abstract)
|
||||||
elif choice in {'', 'n', 'no'}:
|
elif choice in {'', 'n', 'no'}:
|
||||||
# TODO Import? copied and adapted from PR
|
# DONE Import? copied and adapted from PR
|
||||||
if paper_id is not None:
|
if paper_id is not None:
|
||||||
self.add_publ(paper_id, base, is_reference)
|
self.add_publ(paper_id, base, is_reference)
|
||||||
else:
|
else:
|
||||||
self.echo("Could not add this paper, please do it manually!")
|
self.warn("Could not add this paper, please do it manually!")
|
||||||
break
|
break
|
||||||
|
|
||||||
# BaseCommand
|
# BaseCommand
|
||||||
@@ -255,11 +255,13 @@ class Command(BaseCommand):
|
|||||||
parser.add_argument('--reset-choices', action='store_true')
|
parser.add_argument('--reset-choices', action='store_true')
|
||||||
parser.add_argument('--no-references', action='store_true')
|
parser.add_argument('--no-references', action='store_true')
|
||||||
parser.add_argument('--no-citations', action='store_true')
|
parser.add_argument('--no-citations', action='store_true')
|
||||||
|
parser.add_argument('-s', '--stage', type=int, default=10000)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
reset_choices: bool = options['reset_choices']
|
reset_choices: bool = options['reset_choices']
|
||||||
no_citations: bool = options['no_citations']
|
no_citations: bool = options['no_citations']
|
||||||
no_references: bool = options['no_references']
|
no_references: bool = options['no_references']
|
||||||
|
stage: int = options['stage']
|
||||||
|
|
||||||
self.cache_path = Path('.choices.semanticscholar.pickle')
|
self.cache_path = Path('.choices.semanticscholar.pickle')
|
||||||
self.cache: Set[str] = set()
|
self.cache: Set[str] = set()
|
||||||
@@ -275,9 +277,12 @@ class Command(BaseCommand):
|
|||||||
semanticscholar__isnull=False,
|
semanticscholar__isnull=False,
|
||||||
exclusion_criteria__isnull=True,
|
exclusion_criteria__isnull=True,
|
||||||
)
|
)
|
||||||
|
if stage < 10000:
|
||||||
|
publications = [p for p in publications if p.stage_added() == stage]
|
||||||
|
self.echo(f"==== {len(publications)} publications from stage {stage} will be shown ====")
|
||||||
try:
|
try:
|
||||||
for publication in tqdm(publications, unit="publication"):
|
for publication in tqdm(publications, unit="publication"):
|
||||||
self.echo(f"=== Publication {publication} ===")
|
self.echo(f"=== Publication {publication}: {publication.title} ===")
|
||||||
for semantic in publication.semanticscholar_set.all():
|
for semantic in publication.semanticscholar_set.all():
|
||||||
data = semanticscholar(semantic.paper_id)
|
data = semanticscholar(semantic.paper_id)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user