Browse Source

Improve citations graph

master
Maximilian Blochberger 4 years ago
parent
commit
47a0070aa6
No known key found for this signature in database GPG Key ID: A2A8F3CC6591A5FA
  1. 19
      sok/management/commands/citations.py
  2. 6
      sok/models.py

19
sok/management/commands/citations.py

@ -3,13 +3,13 @@ from typing import Set, Tuple
from django.core.management.base import BaseCommand, CommandParser
from django.db.models import Count, Q
from sok.models import Publication
from sok.models import Publication, PublicationReference
class Command(BaseCommand):
def echo(self, msg: str):
self.stdout.write(msg)
def echo(self, msg: str, nl: bool = True):
self.stdout.write(msg, ending='\n' if nl else '')
# BaseCommand
@ -27,7 +27,7 @@ class Command(BaseCommand):
).filter(citation_count__gte=min_citations)
self.echo("digraph G {")
self.echo("\trankdir = RL;")
self.echo("\trankdir = BT;")
graph: Set[Tuple[int, int]] = set()
@ -48,9 +48,16 @@ class Command(BaseCommand):
))
if pk:
self.echo(f'\t"{publication.pk}" -> "{reference.pk}";')
self.echo(f'\t"{publication.pk}" -> "{reference.pk}"',nl=False)
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("}")

6
sok/models.py

@ -179,5 +179,11 @@ class PublicationReference(models.Model):
reference = models.ForeignKey(Publication, on_delete=models.CASCADE, related_name='cited_by')
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:
unique_together = (('publication', 'reference'), ('publication', 'identifier'))

Loading…
Cancel
Save