From dcae4b2d6949b3ca11a96f7af01b293871d44d3c Mon Sep 17 00:00:00 2001 From: Harounnn Date: Fri, 26 Apr 2024 00:04:39 +0100 Subject: [PATCH] summarization part done --- app/build.gradle.kts | 4 +++- app/src/main/AndroidManifest.xml | 3 ++- .../java/com/example/readitai/Adapter.java | 1 + .../java/com/example/readitai/Summarizer.java | 19 +++++++++++++++++++ .../java/com/example/readitai/sumNews.java | 8 +++++++- app/src/main/res/layout/summarization.xml | 11 ++++++++--- 6 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/example/readitai/Summarizer.java diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 175a0ee..993cb7f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -45,5 +45,7 @@ dependencies { androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") - implementation("edu.stanford.nlp:stanford-corenlp:4.4.0") + implementation("com.github.shubham0204:Text2Summary-Android:alpha-05") + + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 78439b3..2e01822 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.ReadITAI" - tools:targetApi="31"> + tools:targetApi="31" + tools:replace="android:theme"> diff --git a/app/src/main/java/com/example/readitai/Adapter.java b/app/src/main/java/com/example/readitai/Adapter.java index 2117653..8ff8e3e 100644 --- a/app/src/main/java/com/example/readitai/Adapter.java +++ b/app/src/main/java/com/example/readitai/Adapter.java @@ -48,6 +48,7 @@ public void onClick(View v) { intent.putExtra("title", models.get(holder.getAdapterPosition()).getTitle()); intent.putExtra("image", models.get(holder.getAdapterPosition()).getUrlToImage()); intent.putExtra("link", models.get(holder.getAdapterPosition()).getUrl()); + intent.putExtra("content", models.get(holder.getAdapterPosition()).getContent()); v.getContext().startActivity(intent); } diff --git a/app/src/main/java/com/example/readitai/Summarizer.java b/app/src/main/java/com/example/readitai/Summarizer.java new file mode 100644 index 0000000..2355eb2 --- /dev/null +++ b/app/src/main/java/com/example/readitai/Summarizer.java @@ -0,0 +1,19 @@ +package com.example.readitai; + +import com.ml.quaterion.text2summary.Text2Summary; + +public class Summarizer { + + String text; + + public Summarizer(String text){ + this.text = text; + } + + public String summarize(){ + System.out.println(text); + String summary = Text2Summary.summarize(text, 0.9F); + System.out.println(summary); + return summary; + } +} diff --git a/app/src/main/java/com/example/readitai/sumNews.java b/app/src/main/java/com/example/readitai/sumNews.java index 372297e..7aa1406 100644 --- a/app/src/main/java/com/example/readitai/sumNews.java +++ b/app/src/main/java/com/example/readitai/sumNews.java @@ -7,7 +7,6 @@ import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; import com.bumptech.glide.Glide; @@ -22,6 +21,7 @@ protected void onCreate(Bundle savedInstanceState){ TextView title = findViewById(R.id.headline); ImageView image = findViewById(R.id.imagesum); + TextView text = findViewById(R.id.summary); TextView link = findViewById(R.id.link); Intent i = getIntent(); @@ -31,6 +31,12 @@ protected void onCreate(Bundle savedInstanceState){ Glide.with(this).load(b.get("image")).into(image); link.setText((String) b.get("link")); + Summarizer summarizer = new Summarizer((String) b.get("content")); + + String summary = summarizer.summarize(); + + text.setText(summary); + } diff --git a/app/src/main/res/layout/summarization.xml b/app/src/main/res/layout/summarization.xml index dacfc53..1be3a69 100644 --- a/app/src/main/res/layout/summarization.xml +++ b/app/src/main/res/layout/summarization.xml @@ -1,7 +1,8 @@ + android:layout_height="match_parent" + android:background="@color/blue"> + android:id="@+id/summary" + android:textSize="25sp" + android:textStyle="bold"> + android:id="@+id/link" + android:textSize="20sp" + android:textStyle="italic">