NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>


const char matrix_bigram_strings[10][3] ={"th", "he", "in", "er", "an", "en", "ch", "de", "ei", "te"};

const char matrix_trigram_strings[10][4]={"the", "and", "ing", "ent", "ion", "der", "sch", "ich", "nde", "die"};

const char languages[2][8]={"english", "german"};

//Ýngilizce dilinin frekans deðerleri
const float frequency_eng[20]={ 2.71, 2.33, 2.03, 1.78, 1.61, 1.13, 0.01, 0.01, 0.01, 0.01, 1.81, 0.73, 0.72, 0.42, 0.42, 0.01, 0.01, 0.01, 0.01, 0.01 };
//Almanca dilinin frekans deðerleri
const float frequency_germ[20]={ 0.01, 0.89, 1.71, 3.90, 1.07, 3.61, 2.36, 2.31, 1.98, 1.98, 0.01, 0.01, 0.01, 0.01, 0.01, 1.04, 0.76, 0.75, 0.72, 0.62 };


float calculated_frequencies[20];
float distances [2]={0,0};


void filter_str(char str[]);
void calculate_frequencies_bi(char str[]);
void calculate_frequencies_tri(char str[]);
void calculate_distances();
void detect_lang();

int main()
{
char metin[100];
printf("Metin giriniz: ");
gets(metin);

filter_str(metin);
calculate_frequencies_bi(metin);
calculate_frequencies_tri(metin);
calculate_distances();
detect_lang();

return 0;
}

void filter_str(char str[]){

/* Metnin içerisindeki her karakter taranýr ve ASCII (decimal) numarasý
[A(65)-Z(90)], [a(97)-z(122)] ve 32 (boþluk karakteri) olmayan karakterler
boþluk karakterine çevrilir. */
for (int i = 0; i<strlen(str); i++){
if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122) || (str[i] == 32))
continue;
else
str[i] = " ";
}
}

void calculate_frequencies_bi(char str[]){

int a = 0;
float harf_sayisi = 0;
int bigram_sayisi[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

while (a < 10) {
for (int i = 0; i < strlen(str); i++) {
if ((str[i] == matrix_bigram_strings[a][0]) && (str[++i] == matrix_bigram_strings[a][1]))
bigram_sayisi[a]++;
else
continue;
}

a++;

}

for (int i = 0; i < strlen(str); i++){
if (str[i] != 32)
harf_sayisi++;
else
continue;
}

for (int i = 0; i < 10; i++){
calculated_frequencies[i] = (bigram_sayisi[i] / (harf_sayisi / 2)) * 100;
}

printf("Bigram frekanslari: ");
for (int i = 0; i < 10; i++) {
printf("%s(%.2f) ", matrix_bigram_strings[i], calculated_frequencies[i]);
}
}

void calculate_frequencies_tri(char str[]){

int a = 0;
float harf_sayisi = 0;
int trigram_sayisi[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

while (a < 10) {
for (int i = 0; i < strlen(str); i++) {
if ((str[i] == matrix_trigram_strings[a][0]) && (str[i+1] == matrix_trigram_strings[a][1]) && (str[i+2] == matrix_trigram_strings[a][2]))
trigram_sayisi[a]++;
else
continue;

}

a++;

}

for (int i = 0; i < strlen(str); i++){
if (str[i] != 32)
harf_sayisi++;
else
continue;
}

for (int i = 10; i < 20; i++){
calculated_frequencies[i] = (trigram_sayisi[i-10] / (harf_sayisi / 3)) * 100;
}

printf("nTrigram frekanslari: ");
for (int i = 0; i < 10; i++) {
printf("%s(%.2f) ", matrix_trigram_strings[i], calculated_frequencies[i+10]);
}
}

void calculate_distances(){

int oklit_eng, oklit_germ = 0;

for (int i = 0; i < 20; i++) {
oklit_eng += pow(calculated_frequencies[i] - frequency_eng[i], 2);
oklit_germ += pow(calculated_frequencies[i] - frequency_germ[i], 2);
}

oklit_eng = sqrt(oklit_eng);
oklit_germ = sqrt(oklit_germ);

distances[0] = oklit_eng;
distances[1] = oklit_germ;
}

void detect_lang(){

if (distances[0] < distances[1])
printf("nGirilen metin Ingilizce'dir.(%s)", languages[0]);
else
printf("nGirilen metin Almanca'dir.(%s)", languages[1]);

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.