Skip to content

Commit 60a8076

Browse files
authored
Merge pull request #29 from iamnehalien29/main
Text Summarizer
2 parents 0cf5565 + 0133883 commit 60a8076

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Java Text Summarizer
2+
3+
A simple Java program that summarizes text by extracting the most important sentences using frequency-based analysis.
4+
5+
This is an **extractive summarizer**, which selects the key sentences from the input text based on word frequency.
6+
7+
---
8+
9+
## 🚀 Features
10+
- Extracts key sentences from any text
11+
- Removes common stopwords to focus on important words
12+
- Configurable summary length (number of sentences)
13+
- Easy to extend for more advanced NLP techniques
14+
15+
---
16+
17+
## 🛠️ Requirements
18+
- Java 8 or higher
19+
- No external libraries required (pure Java implementation)
20+
21+
---
22+
23+
## ⚡ Usage
24+
25+
1. Clone or download the repository.
26+
2. Compile the Java program:
27+
28+
```bash
29+
javac TextSummarizer.java
62 KB
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import java.util.*;
2+
import java.util.stream.Collectors;
3+
4+
public class TextSummarizer {
5+
6+
// List of common stopwords
7+
private static final Set<String> STOPWORDS = Set.of(
8+
"a", "an", "the", "and", "or", "but", "is", "are", "was", "were",
9+
"in", "on", "at", "to", "for", "with", "of", "by", "that", "this"
10+
);
11+
12+
public static void main(String[] args) {
13+
String text = """
14+
Java is a high-level, class-based, object-oriented programming language
15+
that is designed to have as few implementation dependencies as possible.
16+
It is a general-purpose programming language intended to let programmers
17+
write once, run anywhere (WORA), meaning that compiled Java code can run
18+
on all platforms that support Java without the need for recompilation.
19+
Java applications are typically compiled to bytecode that can run on any
20+
Java virtual machine (JVM) regardless of the underlying computer architecture.
21+
""";
22+
23+
int summarySize = 2; // Number of sentences in summary
24+
String summary = summarizeText(text, summarySize);
25+
System.out.println("Summary:\n" + summary);
26+
}
27+
28+
public static String summarizeText(String text, int numSentences) {
29+
// Split text into sentences
30+
String[] sentences = text.split("(?<=[.!?])\\s+");
31+
32+
// Count word frequencies
33+
Map<String, Integer> wordFreq = new HashMap<>();
34+
for (String sentence : sentences) {
35+
String[] words = sentence.toLowerCase().split("\\W+");
36+
for (String word : words) {
37+
if (!STOPWORDS.contains(word) && word.length() > 1) {
38+
wordFreq.put(word, wordFreq.getOrDefault(word, 0) + 1);
39+
}
40+
}
41+
}
42+
43+
// Score sentences
44+
Map<String, Integer> sentenceScores = new HashMap<>();
45+
for (String sentence : sentences) {
46+
int score = 0;
47+
for (String word : sentence.toLowerCase().split("\\W+")) {
48+
score += wordFreq.getOrDefault(word, 0);
49+
}
50+
sentenceScores.put(sentence, score);
51+
}
52+
53+
// Pick top sentences
54+
List<String> summarySentences = sentenceScores.entrySet().stream()
55+
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
56+
.limit(numSentences)
57+
.map(Map.Entry::getKey)
58+
.collect(Collectors.toList());
59+
60+
return String.join(" ", summarySentences);
61+
}
62+
}

Python/Speed test Script/Speed test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csv
44
import json
55
from datetime import datetime
6+
import sys
67

78
def test_speed():
89
st = speedtest.Speedtest()
@@ -41,10 +42,13 @@ def save_json(data, filename="results.json"):
4142
if __name__ == "__main__":
4243
parser = argparse.ArgumentParser(description="Internet Speed Test & Logger")
4344
parser.add_argument("--save", choices=["csv", "json"], help="Save results to CSV or JSON")
44-
args = parser.parse_args()
45+
46+
# ✅ Ignore unwanted Colab/Jupyter args like -f kernel.json
47+
args, unknown = parser.parse_known_args(sys.argv[1:])
4548

4649
print("🚀 Running speed test... please wait.\n")
4750
results = test_speed()
51+
4852
print(f"Download Speed: {results['download_mbps']} Mbps")
4953
print(f"Upload Speed: {results['upload_mbps']} Mbps")
5054
print(f"Ping: {results['ping_ms']} ms")

0 commit comments

Comments
 (0)