Improve citations graph

This commit is contained in:
Maximilian Blochberger committed 2021-03-17 08:48:32 +01:00
1 parent 7d007f0283
commit 47a0070aa6
2 files changed
+19 -6

No files matched your search

+13 -6
View File
@@ -3,13 +3,13 @@ from typing import Set, Tuple
from django.core.management.base import BaseCommand, CommandParser from django.core.management.base import BaseCommand, CommandParser
from django.db.models import Count, Q from django.db.models import Count, Q
from sok.models import Publication from sok.models import Publication, PublicationReference
class Command(BaseCommand): class Command(BaseCommand):
def echo(self, msg: str): def echo(self, msg: str, nl: bool = True):
self.stdout.write(msg) self.stdout.write(msg, ending='\n' if nl else '')
# BaseCommand # BaseCommand
@@ -27,7 +27,7 @@ class Command(BaseCommand):
).filter(citation_count__gte=min_citations) ).filter(citation_count__gte=min_citations)
self.echo("digraph G {") self.echo("digraph G {")
self.echo("\trankdir = RL;") self.echo("\trankdir = BT;")
graph: Set[Tuple[int, int]] = set() graph: Set[Tuple[int, int]] = set()
@@ -48,9 +48,16 @@ class Command(BaseCommand):
)) ))
if pk: if pk:
self.echo(f'\t"{publication.pk}" -> "{reference.pk}";') self.echo(f'\t"{publication.pk}" -> "{reference.pk}"',nl=False)
else: else:
self.echo(f'\t"{publication.cite_key}" -> "{reference.cite_key}";') self.echo(f'\t"{publication.cite_key}" -> "{reference.cite_key}"', nl=False)
rel = PublicationReference.objects.get(publication=publication, reference=reference)
if rel.is_self_cite:
self.echo(" [style=dashed]", nl=False)
self.echo(";")
self.echo("}") self.echo("}")
+6
View File
@@ -179,5 +179,11 @@ class PublicationReference(models.Model):
reference = models.ForeignKey(Publication, on_delete=models.CASCADE, related_name='cited_by') reference = models.ForeignKey(Publication, on_delete=models.CASCADE, related_name='cited_by')
identifier = models.CharField(max_length=255, blank=True, null=True, default=None) identifier = models.CharField(max_length=255, blank=True, null=True, default=None)
@property
def is_self_cite(self) -> bool:
lhs: Set[int] = set(self.publication.authors.values_list('pk', flat=True))
rhs: Set[int] = set(self.reference.authors.values_list('pk', flat=True))
return not lhs.isdisjoint(rhs)
class Meta: class Meta:
unique_together = (('publication', 'reference'), ('publication', 'identifier')) unique_together = (('publication', 'reference'), ('publication', 'identifier'))