Exemplo n.º 1
0
def test_person_summary():
    s = Summarizer()

    people = [
        {
            "gender": "F",
            "image": "https://example.com/image1",
            "party": [{"name": "Democratic"}, {"name": "Democratic", "end_date": "1990"}],
        },
        {
            "gender": "F",
            "image": "https://example.com/image2",
            "party": [{"name": "Democratic"}, {"name": "Working Families"}],
            "extras": {"religion": "Zoroastrian"},
            "contact_details": [{"fax": "123-456-7890", "note": "Capitol Office"}],
            "other_identifiers": [{"scheme": "fake", "identifier": "abc"}],
            "ids": {"twitter": "fake"},
        },
        {
            "gender": "M",
            "image": "https://example.com/image3",
            "party": [{"name": "Republican"}],
            "contact_details": [{"phone": "123-456-7890", "note": "Capitol Office"}],
            "other_identifiers": [{"scheme": "fake", "identifier": "123"}],
        },
    ]

    for p in people:
        s.summarize(p)

    assert s.parties == {"Republican": 1, "Democratic": 2, "Working Families": 1}
    assert s.contact_counts == {"Capitol Office phone": 1, "Capitol Office fax": 1}
    assert s.id_counts == {"fake": 2, "twitter": 1}
    assert s.optional_fields == {"gender": 3, "image": 3}
    assert s.extra_counts == {"religion": 1}
Exemplo n.º 2
0
  def test_summarize_multipe(self):
    args = '{"output_ids": [], \
      "ppg_ids": ["DEF", "LTFL", "LP61"], \
      "problem_objective_ids": ["FGH"], \
      "goal_ids": ["EFG"], \
      "operation_ids": ["BEN", "LISA"], \
      "report_type": "Mid Year Report",  \
      "year": 2013 }'

    s = Summarizer(env = 'test', args = args)

    summary = s.summarize()
    assert summary.strip() == 'the quick brown fox. the second quick brown fox.'
Exemplo n.º 3
0
    def test_summarize_multipe(self):
        args = '{"output_ids": [], \
      "ppg_ids": ["DEF", "LTFL", "LP61"], \
      "problem_objective_ids": ["FGH"], \
      "goal_ids": ["EFG"], \
      "operation_ids": ["BEN", "LISA"], \
      "report_type": "Mid Year Report",  \
      "year": 2013 }'

        s = Summarizer(env='test', args=args)

        summary = s.summarize()
        assert summary.strip(
        ) == 'the quick brown fox. the second quick brown fox.'
Exemplo n.º 4
0
  def test_summarize_large(self):
    args = '{"output_ids": [], \
      "ppg_ids": ["DEF", "LTFL", "LP61"], \
      "problem_objective_ids": ["FGH"], \
      "goal_ids": ["EFG"], \
      "operation_ids": ["BEN", "LISA", "JEFF"], \
      "report_type": "Mid Year Report",  \
      "year": 2013 }'

    max_chars = 500

    s = Summarizer(env = 'test', args = args, max_chars = max_chars)

    summary = s.summarize()
    assert len(summary) <= max_chars
Exemplo n.º 5
0
    def test_summarize_large(self):
        args = '{"output_ids": [], \
      "ppg_ids": ["DEF", "LTFL", "LP61"], \
      "problem_objective_ids": ["FGH"], \
      "goal_ids": ["EFG"], \
      "operation_ids": ["BEN", "LISA", "JEFF"], \
      "report_type": "Mid Year Report",  \
      "year": 2013 }'

        max_chars = 500

        s = Summarizer(env='test', args=args, max_chars=max_chars)

        summary = s.summarize()
        assert len(summary) <= max_chars
Exemplo n.º 6
0
import pickle

from pathlib import Path
from summa import summarizer
from summarize import Summarizer


if __name__ == '__main__':

	DATA_PATH = Path('data')
	reviewtext = pd.read_pickle(DATA_PATH/'df_processed_reviews.p')
	idx2sent = pickle.load(open(DATA_PATH/'idx2sent.p', 'rb'))
	sent2vec = pickle.load(open(DATA_PATH/'sent2vec.p', 'rb'))

	idx = 198
	my_summarizer = Summarizer(reviewtext, idx2sent, sent2vec)
	review, my_summary = my_summarizer.summarize(idx, n=100)
	summary = summarizer.summarize(review, ratio=0.2)