Exemple #1
0
async def duration(req: BasicRequest):
    """Calculates the approximate reading duration for the document based on reader read speed"""

    sentences = list(Doc(req.doc))

    word_count = sum((len(s) for s in sentences))

    dur = (word_count / (req.wpm / 60))
    unit = TimeUnitEnum.SECOND

    logger.info(f"Total duration {dur}")

    return RichSummary(sentence_count=len(sentences), word_count=word_count, wpm=req.wpm, duration=dur, unit=unit)
Exemple #2
0
async def rouge1(req: Request):
    """Baseline [Rouge1 Summarizer](https://github.com/GlobalMaksimum/sadedegel/tree/master/sadedegel/summarize/README.md)

            Rank sentences based on their rouge1 score in Document and return a list of sentences until number of total tokens is less than equal to `wpm x duration`
    """

    sentences = list(Doc(req.doc))

    if req.unit == TimeUnitEnum.MINUTE:
        duration_in_min = req.duration
    else:
        duration_in_min = req.duration / 60.

    return summarize(Rouge1Summarizer(), sentences, req.wpm * duration_in_min)
Exemple #3
0
async def firstk(req: Request):
    """Baseline [Position Summarizer](https://github.com/GlobalMaksimum/sadedegel/tree/master/sadedegel/summarize/README.md)

            Picks up first a few sentences until total number of tokens is less than equal to `wpm x duration`
    """

    sentences = list(Doc(req.doc))

    if req.unit == TimeUnitEnum.MINUTE:
        duration_in_min = req.duration
    else:
        duration_in_min = req.duration / 60.

    return summarize(PositionSummarizer(), sentences, req.wpm * duration_in_min)
Exemple #4
0
async def random(req: Request):
    """Baseline [Random Summarizer](https://github.com/GlobalMaksimum/sadedegel/tree/master/sadedegel/summarize/README.md)

            Picks up random sentences until total number of tokens is less than equal to `wpm x duration`
    """

    sentences = Doc(req.doc).sents

    if req.unit == TimeUnitEnum.MINUTE:
        duration_in_min = req.duration
    else:
        duration_in_min = req.duration / 60.

    return summarize(RandomSummarizer(seed=None), sentences, req.wpm * duration_in_min)