Skip to content

Commit

Permalink
OPENNLP-1592 Provide tests for MetaSummarizer (#154)
Browse files Browse the repository at this point in the history
- provides a minimal set of JUnit tests for MetaSummarizer
- improves the existing code so that summarization works (again)
- improves the code quality
- adds JavaDoc where possible
- formats incorrectly formatted code to better match JNC
  • Loading branch information
mawiesne authored Jul 10, 2024
1 parent c4bebd8 commit 668e6f7
Show file tree
Hide file tree
Showing 37 changed files with 54,474 additions and 943 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
<exclude>**/src/test/resources/**/*.cxt</exclude>
<exclude>**/src/test/resources/**/*.xml</exclude>
<exclude>**/src/test/resources/**/*.sensemap</exclude>
<exclude>**/src/test/resources/**/*.story</exclude>
<exclude>**/src/test/resources/**/*.bin</exclude>
<exclude>**/src/test/resources/**/tagfiles/*</exclude>
<!-- These files do not allow a license header -->
Expand Down
9 changes: 7 additions & 2 deletions summarizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
58 changes: 29 additions & 29 deletions summarizer/src/main/java/opennlp/summarization/DocProcessor.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package opennlp.summarization;

Expand All @@ -22,26 +22,26 @@
import opennlp.tools.stemmer.Stemmer;

/**
* A document processor abstracts a lot of the underlying complexities of parsing the document and
* A document processor abstracts a lot of the underlying complexities of parsing the document and
* preparing it (e.g. stemming, stop word removal) from the summarization algorithm.
* <p>
* The current package supports sentence extraction based algorithms.
* Thus, extracting sentences from the text is the first step and the basis for related algorithms.
*/
public interface DocProcessor {

/**
* Extracts sentences from a string representing an article.
*/
List<Sentence> getSentencesFromStr(String text) ;
/**
* Extracts sentences from a string representing an article.
*/
List<Sentence> getSentencesFromStr(String text);

/**
* Parses out words from a specified {@link String sent}.
*/
String[] getWords(String sent);

/**
* Parses out words from a specified {@link String sent}.
*/
String[] getWords(String sent);

/**
* Provides a stemmer to stem words
*/
Stemmer getStemmer();
/**
* Provides a stemmer to stem words.
*/
Stemmer getStemmer();
}
27 changes: 11 additions & 16 deletions summarizer/src/main/java/opennlp/summarization/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,36 @@ public class Score implements Comparable<Score> {
private int sentId;
private double score;

public Score()
{
public Score() {
score = 0;
}

public int getSentId(){
public int getSentId() {
return sentId;
}

public double getScore()
{
return score;
public void setSentId(int sentId) {
this.sentId = sentId;
}

public void setScore(double score)
{
this.score = score;
public double getScore() {
return score;
}

public void setSentId(int sentId)
{
this.sentId = sentId;
public void setScore(double score) {
this.score = score;
}

@Override
public int compareTo(Score o) {

if(o.score > score) return 1;
if (o.score > score) return 1;
else if (o.score < score) return -1;
return 0;
}

@Override
public String toString()
{
return sentId +" "+score;
public String toString() {
return sentId + " " + score;
}
}
Loading

0 comments on commit 668e6f7

Please sign in to comment.