コード例 #1
0
    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)]
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
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.',
    ]
コード例 #6
0
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
コード例 #8
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
コード例 #9
0
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
コード例 #10
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'
コード例 #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'
コード例 #12
0
def test_set_corpus(mock_hlom):

    mock_hlom.add_marc()
    Text.ingest_hlom()

    assert Text.select().first().corpus == 'hlom'
コード例 #13
0
def test_set_publisher(mock_hlom):

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

    assert Text.select().first().publisher == 'Chicago Press'
コード例 #14
0
def test_set_publisher(mock_hlom):

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

    assert Text.select().first().publisher == 'Chicago Press'
コード例 #15
0
def test_set_surname(mock_hlom):

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

    assert Text.select().first().surname == 'McClure'
コード例 #16
0
def test_set_identifier(mock_hlom):

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

    assert Text.select().first().identifier == '001'
コード例 #17
0
def test_set_journal_identifier(mock_jstor):

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

    assert Text.select().first().journal_identifier == 'criticalinquiry'
コード例 #18
0
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']
コード例 #19
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'
コード例 #20
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'
コード例 #21
0
def test_set_corpus(mock_jstor):

    mock_jstor.add_article()
    Text.ingest_jstor()

    assert Text.select().first().corpus == 'jstor'
コード例 #22
0
def test_set_date(mock_hlom):

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

    assert Text.select().first().date == '1987'
コード例 #23
0
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'
コード例 #24
0
def test_set_title(mock_hlom):

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

    assert Text.select().first().title == 'Book Title'
コード例 #25
0
def test_set_issue_volume(mock_jstor):

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

    assert Text.select().first().issue_volume == '200'
コード例 #26
0
def test_set_identifier(mock_jstor):

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

    assert Text.select().first().identifier == '001'
コード例 #27
0
def test_set_title(mock_hlom):

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

    assert Text.select().first().title == 'Book Title'
コード例 #28
0
def test_set_title(mock_jstor):

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

    assert Text.select().first().title == 'Article Title'
コード例 #29
0
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']
コード例 #30
0
def test_set_surname(mock_jstor):

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

    assert Text.select().first().surname == 'McClure'
コード例 #31
0
def test_set_date(mock_hlom):

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

    assert Text.select().first().date == '1987'
コード例 #32
0
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.']
コード例 #33
0
def test_set_corpus(mock_hlom):

    mock_hlom.add_marc()
    Text.ingest_hlom()

    assert Text.select().first().corpus == 'hlom'
コード例 #34
0
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'
コード例 #36
0
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'
コード例 #38
0
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'
コード例 #40
0
def test_set_surname(mock_hlom):

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

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