Figure
Figure
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="News Articles Summarizer"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="16dp"
android:textColor="@color/white"/>
Figure: RelativeLayout
<TextView
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="News Articles Summarizer"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="16dp"
android:textColor="@color/white"/>
<EditText
android:id="@+id/urlText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/urlLabel"
android:hint="Paste Url Here"
android:textSize="14sp" />
<EditText
android:id="@+id/numSentencesEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:inputType="number"
android:text="2"
android:hint="Summary Length"
android:layout_below="@id/numSentencesLabel"
android:layout_marginBottom="2dp"/>
<Button
android:id="@+id/resetButton"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_below="@id/numSentencesEntry"
android:layout_alignParentEnd="true"
android:layout_marginStart="23dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="5dp"
android:layout_toEndOf="@+id/summarizeButton"
android:background="@drawable/resetbtn"
android:text="Reset"
android:textColor="#ffffff"
android:cursorVisible="true"/>
<TextView
android:id="@+id/feedbackLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/progressBar"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/summaryText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#000000"
android:padding="8dp"
android:background="#dddddd"
android:scrollbars="vertical"/>
</ScrollView>
Figure: Initialize
private void resetFields() {
titleText.setText("");
authorText.setText("");
publicationText.setText("");
summaryText.setText("");
sentimentText.setText("");
urlText.setText("");
progressBar.setVisibility(View.GONE);
feedbackLabel.setText("");
}
Figure: Reset
private void startSummarization() {
progressBar.setVisibility(View.VISIBLE);
feedbackLabel.setText("Summarizing...");
new Thread(new Runnable() {
@Override
public void run() {
try {
summarizeArticle();
} catch (Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
feedbackLabel.setText("Error: " + e.getMessage());
progressBar.setVisibility(View.GONE);
}
});
}
}
}).start();
}
int numSentences;
try {
numSentences = Integer.parseInt(numSentencesEntry.getText().toString());
} catch (NumberFormatException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
feedbackLabel.setText("Invalid number of sentences.");
progressBar.setVisibility(View.GONE);
}
});
return;
}
String[] negativeWords = {
"bad", "terrible", "poor", "negative", "unfortunate", "wrong", "inferior",
"sad", "angry", "war", "death", "awful", "horrible", "terrible", "disappointing",
"disgusting", "unpleasant", "miserable", "regretful", "dreadful",
"frustrating", "upset", "disheartening", "hate", "hateful", "angry", "annoy", "annoying",
"ashamed", "blame", "boring", "cry", "damage", "danger", "dark", "defeat", "dislike", "failure",
"fear", "corrupt", "corruption", "scandal", "dishonest", "unethical", "untrustworthy",
"deceptive", "manipulative", "biased", "partisan", "divisive", "controversial"
};
summaryText.setText(summary);
sentimentText.setText("Polarity: " + polarity + ", Sentiment: " + (polarity > 0
? "positive" : polarity < 0 ? "negative" : "neutral"));
}
}
@Test
public void testSummarizeButton() {
// Test the Summarize button functionality
Espresso.onView(ViewMatchers.withId(R.id.urlText)).perform(ViewActions.type
Text
("https://edition.cnn.com/asia/live-news/india-general-election-
results-06-04-24-intl-hnk/index.html"));
Espresso.onView(ViewMatchers.withId(R.id.summarizeButton)).perform(ViewA
ctions.click());
Espresso.onView(ViewMatchers.withId(R.id.summaryText)).check(ViewAssertio
ns.matches(ViewMatchers.isDisplayed()));
}
}
Figure: UI Testing
public void testSummarization() {
// Test the summarization method with a URL as input text
String inputText = "https://edition.cnn.com/asia/live-news/india-general-
election-results-06-04-24-intl-hnk/index.html";
int numSentences = 3;
// Call the preprocessText method with the input URL and numSentences
String actualSummary = preprocessText(inputText, numSentences);
return summary;
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
return "";
}
}