Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7656535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:47:20+00:00 2026-05-31T12:47:20+00:00

I’m trying to create a summarizer in Java. I’m using the Stanford Log-linear Part-Of-Speech

  • 0

I’m trying to create a summarizer in Java. I’m using the Stanford Log-linear Part-Of-Speech Tagger to tag the words, and then, for certain tags, I’m scoring the sentence and finally in the summary, I’m printing sentences with a high score value.
Here’s the code:

    MaxentTagger tagger = new MaxentTagger("taggers/bidirectional-distsim-wsj-0-18.tagger");

    BufferedReader reader = new BufferedReader( new FileReader ("C:\\Summarizer\\src\\summarizer\\testing\\testingtext.txt"));
    String line  = null;
    int score = 0;
    StringBuilder stringBuilder = new StringBuilder();
    File tempFile = new File("C:\\Summarizer\\src\\summarizer\\testing\\tempFile.txt");
    Writer writerForTempFile = new BufferedWriter(new FileWriter(tempFile));


    String ls = System.getProperty("line.separator");
    while( ( line = reader.readLine() ) != null )
    {
        stringBuilder.append( line );
        stringBuilder.append( ls );
        String tagged = tagger.tagString(line);
        Pattern pattern = Pattern.compile("[.?!]"); //Find new line
        Matcher matcher = pattern.matcher(tagged);
        while(matcher.find())
        {
            Pattern tagFinder = Pattern.compile("/JJ"); // find adjective tag
            Matcher tagMatcher = tagFinder.matcher(matcher.group());
            while(tagMatcher.find())
            {
                score++; // increase score of sentence for every occurence of adjective tag
            }
            if(score > 1)
                writerForTempFile.write(stringBuilder.toString());
            score = 0;
            stringBuilder.setLength(0);
        }

    }

    reader.close();
    writerForTempFile.close();

The above code isn’t working. Although, if I cut my work and generate score for every line(not sentence),it works. But summaries aren’t generated that way,are they?
Here’s the code for that: (all the declarations being the same as above)

while( ( line = reader.readLine() ) != null )
        {
            stringBuilder.append( line );
            stringBuilder.append( ls );
            String tagged = tagger.tagString(line);
            Pattern tagFinder = Pattern.compile("/JJ"); // find adjective tag
            Matcher tagMatcher = tagFinder.matcher(tagged);
            while(tagMatcher.find())
            {
                score++;  //increase score of line for every occurence of adjective tag
            }
            if(score > 1)
                writerForTempFile.write(stringBuilder.toString());
            score = 0;
            stringBuilder.setLength(0);
        }

EDIT 1:

Information regarding what the MaxentTagger does. A sample code to show it’s functioning :

import java.io.IOException;

import edu.stanford.nlp.tagger.maxent.MaxentTagger;

public class TagText {
    public static void main(String[] args) throws IOException,
            ClassNotFoundException {

        // Initialize the tagger
        MaxentTagger tagger = new MaxentTagger(
                "taggers/bidirectional-distsim-wsj-0-18.tagger");

        // The sample string
        String sample = "This is a sample text";

        // The tagged string
        String tagged = tagger.tagString(sample);

        // Output the result
        System.out.println(tagged);
    }
}

Output:

This/DT is/VBZ a/DT sample/NN sentence/NN

EDIT 2:

Modified code using BreakIterator to find sentence breaks. Yet the problem is persisting.

while( ( line = reader.readLine() ) != null )
        {
            stringBuilder.append( line );
            stringBuilder.append( ls );
            String tagged = tagger.tagString(line);
            BreakIterator bi = BreakIterator.getSentenceInstance();
            bi.setText(tagged);
            int end, start = bi.first();
            while ((end = bi.next()) != BreakIterator.DONE)
            {
                String sentence = tagged.substring(start, end);
                Pattern tagFinder = Pattern.compile("/JJ");
                Matcher tagMatcher = tagFinder.matcher(sentence);
                while(tagMatcher.find())
                {
                    score++;
                }
                scoreTracker.add(score);
                if(score > 1)
                    writerForTempFile.write(stringBuilder.toString());
                score = 0;
                stringBuilder.setLength(0);
                start = end;
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:47:21+00:00Added an answer on May 31, 2026 at 12:47 pm

    Finding sentence breaks can be a bit more involved than just looking for [.?!], consider using BreakIterator.getSentenceInstance()

    Its performance is actually quite similar to LingPipe’s (more complex) implementation, and better than the one in OpenNLP (from my own testing, at least).

    Sample Code

    BreakIterator bi = BreakIterator.getSentenceInstance();
    bi.setText(text);
    int end, start = bi.first();
    while ((end = bi.next()) != BreakIterator.DONE) {
        String sentence = text.substring(start, end);
        start = end;
    }
    

    Edit

    I think this is what you’re looking for:

        Pattern tagFinder = Pattern.compile("/JJ");
        BufferedReader reader = getMyReader();
        String line = null;
        while ((line = reader.readLine()) != null) {
            BreakIterator bi = BreakIterator.getSentenceInstance();
            bi.setText(line);
            int end, start = bi.first();
            while ((end = bi.next()) != BreakIterator.DONE) {
                String sentence = line.substring(start, end);
                String tagged = tagger.tagString(sentence);
                int score = 0;
                Matcher tag = tagFinder.matcher(tagged);
                while (tag.find())
                    score++;
                if (score > 1)
                    writerForTempFile.println(sentence);
                start = end;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.