Skip to content

Commit

Permalink
1.0.7_added analyzer module
Browse files Browse the repository at this point in the history
  • Loading branch information
altunenes committed Sep 1, 2023
1 parent 04dc208 commit 31d181c
Show file tree
Hide file tree
Showing 13 changed files with 50,194 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
".\\Cargo.toml"
]
}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustysozluk"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
authors = ["altunenes <enesaltun2@gmail.com>"]
description = "Eksi Sozluk API wrapper"
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Description

`RustySozluk` is a Rust library for fetching user entries and thread entries from eksisozluk.com.
`RustySozluk` is a Rust library for fetching user entries and thread entries from eksisozluk.com and analyzing sentiment of entries.
With the power of Rust and `tokio` library, it is possible to fetch entries in a thread in a very short time.

## Features
Expand All @@ -22,14 +22,15 @@ With the power of Rust and `tokio` library, it is possible to fetch entries in a
- Fetch entries in a particular thread
- Asynchronous API using Rust's `async/await`
- Export entries to both `JSON` and `CSV` formats
- Calculate sentiment of entries or get simple frequency of words in entries

## Installation

Add `rustysozluk` to your `Cargo.toml`:

```toml
[dependencies]
rustysozluk = "0.1.6"
rustysozluk = "0.1.7"
```

## Usage
Expand All @@ -53,6 +54,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
If you want to fetch entries in a thread, you can simple use `fetch_thread` function just like `fetch_user` function, no need to change anything.



## Sentiment Analysis

rustysozluk has "analyzer" module which is used for sentiment analysis. It uses [Sağlam et al., 2019](https://journals.tubitak.gov.tr/cgi/viewcontent.cgi?article=1639&context=elektrik) model to classify entries as positive, negative and give a "Tone" score between -1 and 1.

here is an example usage:

```rust
use rustysozluk::tokio;
use rustysozluk::fetch_title;
use rustysozluk::analyzer::analyzer::analyze_sentiment;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let title = "https://eksisozluk1923.com/rust-programlama-dili--5575227";
let number_of_entries = 4;
let entries = fetch_title(title, number_of_entries).await?;
analyze_sentiment(entries)?;
Ok(())

}
```


### Contributing

Any kind of contribution is welcome! Feel free to open an issue =)
15 changes: 15 additions & 0 deletions examples/analyze.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use rustysozluk::{fetch_user, tokio};
use rustysozluk::analyzer::analyzer::top_words;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let username = "morgomir";
let entry_number = 4;
let output_csv = false;
let entries = fetch_user(username, entry_number).await?;
top_words(entries, "files/stopwords.csv", 5,output_csv)?; // stopwords file path, top N words. False means output is not csv.
Ok(())
}



29 changes: 29 additions & 0 deletions examples/analyze2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//this example is more advanced than analyze.rs.
// Bu örnek, analyze.rs'den daha gelişmiştir.

use rustysozluk::{fetch_user, tokio};
use rustysozluk::analyzer::analyzer::{read_stopwords, word_frequencies};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let username = "morgomir";
let entry_number = 4;
let entries = fetch_user(username, entry_number).await?;

let stopwords = read_stopwords("files/stopwords.csv")?; // stopwords file path

// Count word frequencies in the entries // kelime frekansını çıkart
let word_count: std::collections::HashMap<String, usize> = word_frequencies(entries.iter().map(|e| e.content.clone()).collect(), &stopwords);

// Sort the HashMap by value (frequency) in descending order // HashMapi azalana göre sırala
let mut word_vec: Vec<(&String, &usize)> = word_count.iter().collect();
word_vec.sort_by(|a, b| b.1.cmp(a.1));

// Display the top 10 most frequent words / en çok kullanılan 10 kelimeyi göster
println!("Top 10 most frequent words:");
for (idx, (word, freq)) in word_vec.iter().enumerate().take(10) {
println!("{}. {}: {}", idx + 1, word, freq);
}

Ok(())
}
15 changes: 15 additions & 0 deletions examples/sentiment_title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//this example fetches the title and analyzes the sentiment of the entries in the title
//bu örnek başlığı alır ve başlıktaki girdilerin duygu durumunu analiz eder
use rustysozluk::tokio;
use rustysozluk::fetch_title;
use rustysozluk::analyzer::analyzer::analyze_sentiment;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let title = "https://eksisozluk1923.com/rust-programlama-dili--5575227"; // title URL //başlık URL'si
let number_of_entries = 4; // number of entries to fetch //alınacak girdi sayısı
let entries = fetch_title(title, number_of_entries).await?;
analyze_sentiment(entries)?;
Ok(())

}
14 changes: 14 additions & 0 deletions examples/sentiment_user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

//this example fetches the title and analyzes the sentiment of the entries in the title
//bu örnek başlığı alır ve başlıktaki girdilerin duygu durumunu analiz eder
use rustysozluk::{fetch_user, tokio};
use rustysozluk::analyzer::analyzer::analyze_sentiment;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let username = "morgomir"; // username //kullanıcı adı
let entry_number = 4; // number of entries to fetch //alınacak girdi sayısı
let entries = fetch_user(username, entry_number).await?;
analyze_sentiment(entries)?; // analyze sentiment //duygu durumunu analiz et
Ok(())
}
Loading

0 comments on commit 31d181c

Please sign in to comment.