def rank_texts(cls):

        """
        Get total citation counts and ranks for texts.

        Returns: list
        """

        count = fn.Count(Citation.id)

        query = (
            Text.select(Text, count)
            .join(Citation)
            .where(Text.display == True)
            .where(Text.valid == True)
            .group_by(Text.id)
            .order_by(Text.id)
            .naive()
        )

        counts = [t.count for t in query]

        # Compute dense-rank ratios.
        dense_ranks = rankdata(counts, "dense")
        top = max(dense_ranks)
        scores = [float(r / top) for r in dense_ranks]

        # Compute overall ranks (#1 is most frequent).
        max_ranks = rankdata(counts, "max")
        top = max(max_ranks)
        ranks = [int(top - r + 1) for r in max_ranks]

        return [dict(zip(["text", "rank", "score"], t)) for t in zip(query, ranks, scores)]
def test_require_title_and_author(title, author, mock_hlom):
    """
    Skip records that don't have a query-able title and author.
    """

    mock_hlom.add_marc(title=title, author=author)
    Text.ingest_hlom()

    assert Text.select().count() == 0
def test_require_title_and_author(title, author, mock_hlom):

    """
    Skip records that don't have a query-able title and author.
    """

    mock_hlom.add_marc(title=title, author=author)
    Text.ingest_hlom()

    assert Text.select().count() == 0
def test_require_title_and_author(title, author, mock_jstor):

    """
    Skip records that don't have a query-able title and author.
    """

    mock_jstor.add_article(article_title=title, author=author)
    Text.ingest_jstor()

    assert Text.select().count() == 0
def test_set_multiple_authors(mock_jstor):

    mock_jstor.add_article(author=[
        ('David W.', 'McClure'),
        ('Kara G.', 'Weisman'),
    ])

    Text.ingest_jstor()

    assert Text.select().first().authors == [
        'McClure, David W.',
        'Weisman, Kara G.',
    ]
def test_load_multiple(mock_hlom):
    """
    Text.ingest_hlom() should ingest multiple records.
    """

    # 100 records.
    for i in range(100):
        mock_hlom.add_marc()

    Text.ingest_hlom()

    # 100 rows.
    assert Text.select().count() == 100
예제 #7
0
def test_load_multiple(mock_jstor):
    """
    Text.ingest_jstor() should ingest multiple records.
    """

    # 100 records.
    for i in range(100):
        mock_jstor.add_article()

    Text.ingest_jstor()

    # 100 rows.
    assert Text.select().count() == 100
def test_load_multiple(mock_jstor):

    """
    Text.ingest_jstor() should ingest multiple records.
    """

    # 100 records.
    for i in range(100):
        mock_jstor.add_article()

    Text.ingest_jstor()

    # 100 rows.
    assert Text.select().count() == 100
def test_load_multiple(mock_hlom):

    """
    Text.ingest_hlom() should ingest multiple records.
    """

    # 100 records.
    for i in range(100):
        mock_hlom.add_marc()

    Text.ingest_hlom()

    # 100 rows.
    assert Text.select().count() == 100
def test_set_url(mock_jstor):

    mock_jstor.add_article(url='http://test.org')
    Text.ingest_jstor()

    assert Text.select().first().url == 'http://test.org'
예제 #11
0
def test_set_pagination(mock_jstor):

    mock_jstor.add_article(fpage=200, lpage=300)
    Text.ingest_jstor()

    assert Text.select().first().pagination == '200-300'
def test_set_corpus(mock_hlom):

    mock_hlom.add_marc()
    Text.ingest_hlom()

    assert Text.select().first().corpus == 'hlom'
def test_set_publisher(mock_hlom):

    mock_hlom.add_marc(publisher='Chicago Press')
    Text.ingest_hlom()

    assert Text.select().first().publisher == 'Chicago Press'
def test_set_publisher(mock_hlom):

    mock_hlom.add_marc(publisher='Chicago Press')
    Text.ingest_hlom()

    assert Text.select().first().publisher == 'Chicago Press'
def test_set_surname(mock_hlom):

    mock_hlom.add_marc(author='McClure, David W.')
    Text.ingest_hlom()

    assert Text.select().first().surname == 'McClure'
def test_set_identifier(mock_hlom):

    mock_hlom.add_marc(control_number='001')
    Text.ingest_hlom()

    assert Text.select().first().identifier == '001'
def test_set_journal_identifier(mock_jstor):

    mock_jstor.add_article(journal_id='criticalinquiry')
    Text.ingest_jstor()

    assert Text.select().first().journal_identifier == 'criticalinquiry'
def test_set_authors(mock_hlom):

    mock_hlom.add_marc(author='David W. McClure')
    Text.ingest_hlom()

    assert Text.select().first().authors == ['David W. McClure']
def test_set_pagination(mock_jstor):

    mock_jstor.add_article(fpage=200, lpage=300)
    Text.ingest_jstor()

    assert Text.select().first().pagination == '200-300'
def test_set_issue_number(mock_jstor):

    mock_jstor.add_article(issue_number=10)
    Text.ingest_jstor()

    assert Text.select().first().issue_number == '10'
def test_set_corpus(mock_jstor):

    mock_jstor.add_article()
    Text.ingest_jstor()

    assert Text.select().first().corpus == 'jstor'
def test_set_date(mock_hlom):

    mock_hlom.add_marc(pubyear='1987')
    Text.ingest_hlom()

    assert Text.select().first().date == '1987'
def test_set_journal_title(mock_jstor):

    mock_jstor.add_article(journal_title='Critical Inquiry')
    Text.ingest_jstor()

    assert Text.select().first().journal_title == 'Critical Inquiry'
def test_set_title(mock_hlom):

    mock_hlom.add_marc(title='Book Title')
    Text.ingest_hlom()

    assert Text.select().first().title == 'Book Title'
def test_set_issue_volume(mock_jstor):

    mock_jstor.add_article(issue_volume=200)
    Text.ingest_jstor()

    assert Text.select().first().issue_volume == '200'
def test_set_identifier(mock_jstor):

    mock_jstor.add_article(article_id='001')
    Text.ingest_jstor()

    assert Text.select().first().identifier == '001'
def test_set_title(mock_hlom):

    mock_hlom.add_marc(title='Book Title')
    Text.ingest_hlom()

    assert Text.select().first().title == 'Book Title'
def test_set_title(mock_jstor):

    mock_jstor.add_article(article_title='Article Title')
    Text.ingest_jstor()

    assert Text.select().first().title == 'Article Title'
def test_set_authors(mock_hlom):

    mock_hlom.add_marc(author='David W. McClure')
    Text.ingest_hlom()

    assert Text.select().first().authors == ['David W. McClure']
def test_set_surname(mock_jstor):

    mock_jstor.add_article(author=[('David W.', 'McClure')])
    Text.ingest_jstor()

    assert Text.select().first().surname == 'McClure'
def test_set_date(mock_hlom):

    mock_hlom.add_marc(pubyear='1987')
    Text.ingest_hlom()

    assert Text.select().first().date == '1987'
def test_set_single_author(mock_jstor):

    mock_jstor.add_article(author=[('David W.', 'McClure')])
    Text.ingest_jstor()

    assert Text.select().first().authors == ['McClure, David W.']
def test_set_corpus(mock_hlom):

    mock_hlom.add_marc()
    Text.ingest_hlom()

    assert Text.select().first().corpus == 'hlom'
def test_set_identifier(mock_hlom):

    mock_hlom.add_marc(control_number='001')
    Text.ingest_hlom()

    assert Text.select().first().identifier == '001'
예제 #35
0
def test_set_issue_number(mock_jstor):

    mock_jstor.add_article(issue_number=10)
    Text.ingest_jstor()

    assert Text.select().first().issue_number == '10'
def test_set_publisher(mock_jstor):

    mock_jstor.add_article(publisher_name='Chicago Journals')
    Text.ingest_jstor()

    assert Text.select().first().publisher == 'Chicago Journals'
예제 #37
0
def test_set_url(mock_jstor):

    mock_jstor.add_article(url='http://test.org')
    Text.ingest_jstor()

    assert Text.select().first().url == 'http://test.org'
def test_set_date(mock_jstor):

    mock_jstor.add_article(pub_year=1987, pub_month=6, pub_day=25)
    Text.ingest_jstor()

    assert Text.select().first().date == '1987-06-25'
예제 #39
0
def test_set_identifier(mock_jstor):

    mock_jstor.add_article(article_id='001')
    Text.ingest_jstor()

    assert Text.select().first().identifier == '001'
def test_set_surname(mock_hlom):

    mock_hlom.add_marc(author='McClure, David W.')
    Text.ingest_hlom()

    assert Text.select().first().surname == 'McClure'