File: Summarizer.py

package info (click to toggle)
synopsis 0.8.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,112 kB
  • ctags: 12,996
  • sloc: cpp: 34,254; ansic: 33,620; python: 10,975; sh: 7,261; xml: 6,369; makefile: 773; asm: 445
file content (39 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#
# Copyright (C) 2005 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

from Synopsis import AST
from Processor import Processor
import re

class Summarizer(Processor):
    """Splits comments into summary/detail parts."""

    re_summary = r"[ \t\n]*(.*?\.)([ \t\n]|$)"

    def __init__(self):

        self.re_summary = re.compile(Summarizer.re_summary, re.S)

    def process_comments(self, decl):
        """Summarize the comment of this declaration."""

        comments = decl.comments()
        if not len(comments):
            return
        # Only use last comment
        comment = comments[-1]
        tags = comment.tags()
        # Decide how much of the comment is the summary
        text = comment.text()
        mo = self.re_summary.match(text)
        if mo:
            # Set summary to the sentence
            comment.set_summary(mo.group(1))
        else:
            # Set summary to whole text
            comment.set_summary(text)