Example #1
0
def test_docs_with_text(add_text, add_doc, add_citation):

    """
    Citation_Index.docs_with_text() should return a set of ids for documents
    that assign a given text.
    """

    t1 = add_text()
    t2 = add_text()

    d1 = add_doc()
    d2 = add_doc()
    d3 = add_doc()
    d4 = add_doc()

    add_citation(text=t1, document=d1)
    add_citation(text=t1, document=d2)
    add_citation(text=t2, document=d3)
    add_citation(text=t2, document=d4)

    Citation_Index.es_insert()

    doc_ids = Citation_Index.docs_with_text(t1.id)

    assert doc_ids == [d1.id, d2.id]
Example #2
0
def assigned_with(text_id, size=1000):

    """
    Given a "seed" text, rank other texts assigned on the same syllabi.

    Args:
        text_id (int): The text id.

    Returns:
        dict: Elasticsearch hits.
    """

    # Get syllabi that assign the text.
    doc_ids = Citation_Index.docs_with_text(text_id)

    # Rank texts assigned by those sylalbi.
    ranks = Citation_Index.compute_ranking(dict(
        document_id=doc_ids
    ))

    # Omit the seed text.
    ranks.pop(str(text_id))

    # Materialize the text metadata.
    texts = Text_Index.materialize_ranking(ranks, size=size)

    return texts
def assigned_with(text_id, size=200):

    """
    Given a "seed" text, rank other texts assigned on the same syllabi.

    Args:
        text_id (int): The text id.

    Returns:
        dict: Elasticsearch hits.
    """

    # Get syllabi that assign the text.
    doc_ids = Citation_Index.docs_with_text(text_id)

    # Rank texts assigned by those sylalbi.
    ranks = Citation_Index.compute_ranking(dict(
        document_id=doc_ids
    ))

    # Omit the seed text.
    ranks.pop(str(text_id))

    # Materialize the text metadata.
    texts = Text_Index.materialize_ranking(ranks, size=size)

    return texts