def test_citation_tree():

    output_filename = "citation-tree.json"

    paper = list(search("^Casey, A", sort="citations", order="desc", rows=1))[0]

    paper.build_citation_tree(depth=3)

    network.export(paper, "citations", output_filename,
        article_repr=lambda article: article.author[0],
        new_branch_repr=lambda article, branch: {"name": article.author[0], "children": branch},
        end_branch_repr=lambda article: {"name": article.author[0]},
        indent=2, clobber=True)

    if os.path.exists(output_filename):
        os.unlink(output_filename)
Example #2
0
if __name__ == "__main__":

    # Let's do it for *last* month
    current_time = localtime()

    # Just grab the last month (there are more Pythonic ways to do this)
    year = current_time.tm_year - 1 if current_time.tm_mon == 1 else current_time.tm_year
    month = current_time.tm_mon - 1 if current_time.tm_mon > 1 else 12
    
    # The affiliation string to search for
    my_affiliation = '"Australian National University"'

    # Get all the articles
    articles = ads.search(
        affiliation=my_affiliation,
        filter="database:astronomy AND property:refereed",
        dates="{year}/{month}".format(year=year, month=month))

    # ads.search yields a generator, so let's list-ify the articles for multiple use
    articles = list(articles)
    print("There were {0} articles found. Sorting and downloading..".format(len(articles)))

    # Let's do something interesting with the data first
    # We'll sort all the articles by first-authors with our matched affiliation first.
    sorted_articles = sorted(articles,
        key=lambda article: [(my_affiliation.strip('"').lower() in affiliation.lower()) for affiliation in article.aff].index(True))

    # Great! Now let's actually do something real with these articles
    # At Mount Stromlo Observatory (the Research School of Astronomy & Astrophysics within
    # the Australian National University), we have a "monthly papers" board that shows the
    # first page of every paper published by someone at Stromlo within the last month.
Example #3
0
# Standard library
import httplib
import json
import os
import urllib
from collections import Counter

# Module specific
import ads

# Couple of mutable variables for the reader
author_query = "^Casey, Andrew R."
records_filename = "citations.json"

papers = ads.search(author_query)

# How many citations did we have last time this ran?
if not os.path.exists(records_filename):
    all_citations_last_time = {
        "total": 0
    }

else:
    with open(records_filename, "r") as fp:
        all_citations_last_time = json.load(fp)

# Build a dictionary with all of our citations
bibcodes, citations = zip(*[(paper.bibcode, paper.citation_count) for paper in papers])
all_citations = dict(zip(bibcodes, citations))
all_citations["total"] = sum(citations)
Example #4
0
# Standard library
import httplib
import json
import os
import urllib
from collections import Counter

# Module specific
import ads

# Couple of mutable variables for the reader
author_query = "^Casey, Andrew R."
records_filename = "citations.json"

papers = ads.search(author_query)

# How many citations did we have last time this ran?
if not os.path.exists(records_filename):
    all_citations_last_time = {
        "total": 0
    }

else:
    with open(records_filename, "r") as fp:
        all_citations_last_time = json.load(fp)

# Build a dictionary with all of our citations
bibcodes, citations = zip(*[(paper.bibcode, paper.citation_count) for paper in papers])
all_citations = dict(zip(bibcodes, citations))
all_citations["total"] = sum(citations)
Example #5
0
# coding: utf-8

""" Who are the most cited astronomers? """

__author__ = "Andy Casey <*****@*****.**>"

import ads

# Let's assume the most cited people have the most cited papers, since we can only search for papers, not people
most_cited_papers = ads.search(sort="citations", filter="database:astronomy", rows=200)

# Who are these successful people, anyways?
successful_astronomers = [paper.author[0] for paper in most_cited_papers]

# Okay, let's get the top 200 most-cited papers for each person and see how many citations they have in total
total_citations = {}
for astronomer in successful_astronomers:
    papers = ads.search("^{0}".format(astronomer.encode("utf-8")),
        sort="citations", filter="database:astronomy", rows=200)
    total_citations[astronomer] = sum([paper.citation_count for paper in papers])

# Now there's a problem because astronomers publish under "Aaronson, A" and "Aaronson, Aaron". Ugh!
duplicate_astronomers = []
for astronomer in total_citations.keys():
    # Look out for "Groups" or "Teams"
    if "," not in astronomer and total_citations[astronomer] == 0:
        print("{0} looks like a group without any citations, so we're going to delete this item.".format(astronomer))
        duplicate_astronomers.append(astronomer)
        continue

    try:
Example #6
0
if __name__ == "__main__":

    # Let's do it for *last* month
    current_time = localtime()

    # Just grab the last month (there are more Pythonic ways to do this)
    year = current_time.tm_year - 1 if current_time.tm_mon == 1 else current_time.tm_year
    month = current_time.tm_mon - 1 if current_time.tm_mon > 1 else 12

    # The affiliation string to search for
    my_affiliation = '"Australian National University"'

    # Get all the articles
    articles = ads.search(affiliation=my_affiliation,
                          filter="database:astronomy AND property:refereed",
                          dates="{year}/{month}".format(year=year,
                                                        month=month))

    # ads.search yields a generator, so let's list-ify the articles for multiple use
    articles = list(articles)
    print("There were {0} articles found. Sorting and downloading..".format(
        len(articles)))

    # Let's do something interesting with the data first
    # We'll sort all the articles by first-authors with our matched affiliation first.
    sorted_articles = sorted(
        articles,
        key=lambda article: [(my_affiliation.strip('"').lower(
        ) in affiliation.lower()) for affiliation in article.aff].index(True))

    # Great! Now let's actually do something real with these articles
Example #7
0
# coding: utf-8
""" Who are the most cited astronomers? """

__author__ = "Andy Casey <*****@*****.**>"

import ads

# Let's assume the most cited people have the most cited papers, since we can only search for papers, not people
most_cited_papers = ads.search(sort="citations",
                               filter="database:astronomy",
                               rows=200)

# Who are these successful people, anyways?
successful_astronomers = [paper.author[0] for paper in most_cited_papers]

# Okay, let's get the top 200 most-cited papers for each person and see how many citations they have in total
total_citations = {}
for astronomer in successful_astronomers:
    papers = ads.search("^{0}".format(astronomer.encode("utf-8")),
                        sort="citations",
                        filter="database:astronomy",
                        rows=200)
    total_citations[astronomer] = sum(
        [paper.citation_count for paper in papers])

# Now there's a problem because astronomers publish under "Aaronson, A" and "Aaronson, Aaron". Ugh!
duplicate_astronomers = []
for astronomer in total_citations.keys():
    # Look out for "Groups" or "Teams"
    if "," not in astronomer and total_citations[astronomer] == 0:
        print(
Example #8
0
# coding: utf-8
""" Export the data to make a citation tree visualisation with D3. """

__author__ = "Andy Casey <*****@*****.**>"

import ads

# Let's grab a paper to build a citation tree from
paper = ads.search("^Hubble, E", sort="citations", order="desc")[0]

# Build our citation tree to a depth of 2
paper.build_citation_tree(depth=2)

# Make a function that turns "Lastname, Firstname I." -> "Lastname, F"
pretty_author_name = lambda author: author.split(",")[0] + author.split(",")[
    1].strip()[1] + "."

# Export the network to citation-tree.json
ads.network.export(
    paper,
    "citations",
    "citation-tree.json",
    article_repr=lambda article: pretty_author_name(article.author[0]),
    new_branch_repr=lambda article, branch: {
        "name": pretty_author_name(article.author[0]),
        "children": branch
    },
    end_branch_repr=lambda article:
    {"name": pretty_author_name(article.author[0])},
    indent=2,
    clobber=True)
Example #9
0
# coding: utf-8

""" Export the data to make a citation tree visualisation with D3. """

__author__ = "Andy Casey <*****@*****.**>"

import ads

# Let's grab a paper to build a citation tree from
paper = ads.search("^Hubble, E", sort="citations", order="desc")[0]

# Build our citation tree to a depth of 2
paper.build_citation_tree(depth=2)

# Make a function that turns "Lastname, Firstname I." -> "Lastname, F"
pretty_author_name = lambda author: author.split(",")[0] + author.split(",")[1].strip()[1] + "."

# Export the network to citation-tree.json
ads.network.export(paper, "citations", "citation-tree.json",
    article_repr=lambda article: pretty_author_name(article.author[0]),
    new_branch_repr=lambda article, branch: {"name": pretty_author_name(article.author[0]), "children": branch},
    end_branch_repr=lambda article: {"name": pretty_author_name(article.author[0])},
    indent=2, clobber=True)