Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;

namespace okumadeneme
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //sentiment anaylysis and changing txt to arff format
        private void btnOku_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 3; i++)
            {
                StreamReader sr = new StreamReader("c:\\" + i + ".txt");
                rtbAl.Text += sr.ReadLine();
                sr.Close();
            }
            
            string a = rtbAl.Text;
            //splitting a to know how many sentence in the document
            string[] nokta = a.Split('.');
            for (int i = 0; i < nokta.Length; i++)
            {
                rtbOkunan.Text += nokta[i] + " " + "\n";
                //rtbOkunan2.Text += nokta[i] + " " + "\n";
            }
            //here is for the words that in the sentence
            string b = rtbOkunan.Text;
            string[] bosluk = b.Split(' ');
            

            for (int i = 0; i < bosluk.Length-(nokta.Length-1); i++)
            {
                rtbOkunan.Text += "@attribute " + "\"" + bosluk[i] + "\"" + " integer" + "\n";
                
            }

            rtbOkunan.Text += "@data" + "\n";
            int sayac = 0;
            for (int i = 0; i < nokta.Length; i++)
            {
                for (int j = 0; j < bosluk.Length-(nokta.Length-1); j++)
                {
                    //count each word
                    MatchCollection kac = Regex.Matches(nokta[i], bosluk[j]);
                    sayac = kac.Count;
                    
                    if (sayac != 0)
                    {
                        rtbOkunan.Text += (j+1) + " " + sayac + ",";
                    }
                }
                
            }
            
        }
    }
}
Good evening everyone I have a question,
for example my output should be like this I should write each word only once and keep their indexes and also count them but when I count them if 2 words are the same in a sentence it counts two and write it twice I want to write this also once. I started to code but I cannot fix these problems I will be glad if someone help me about this thank you .

C#
@attribute "kaydirmazlik" integer
@attribute "tutabildigini" integer
@attribute "tozlanarak" integer
@attribute "kullanilacagindan" integer

@data

{0 1,1 1,2 1,3 2,4 1,5 1,6 1,7 1,8 1,9 1,10 1,11 1,12 1,13 1,14 1,15 1,16 1,17 1,18 1,19 1}
{0 0,14 1,93 1,94 1,95 1,96 1,97 1,98 1,99 1,100 1,101 1,102 1,103 1,104 1,105 1,106 1}
{0 1,2 1,3 1,24 1,31 1,107 1,108 1,109 1,110 1,111 1,112 1}
{0 0,186 1,187 1,188 1,189 1,190 1,191 1,192 1,193 1,194 1,195 1}
{0 1,24 1,73 1,129 1,196 1,197 1,198 1,199 1,200 1,201 1,202 1,203 1,204 1}
Posted
Updated 12-Nov-13 10:50am
v3
Comments
Sergey Alexandrovich Kryukov 12-Nov-13 16:49pm    
Absolutely insufficient description of the problem. "I cannot fix these problems" is not informative enough.
Not clear where your problem is, except your code. It is apparently not good enough: 1) it mixes semantic logic code with UI, 2) it mixes logic with hard-coded immediate constants spread everywhere. It does not allow to make code maintainable, and also it is purely readable. I doubt someone will want to dig into it, based on so vague problem explanation, unless some obvious bug is spotted...
—SA
brknlpr 12-Nov-13 17:05pm    
thank you for your response. Ok then I am reading a negative or positive comment from a txt file.I have to separate each DISTINCT word from this file at first.(This is my first problem)Then I have to count each DISTINCT word each sentence and write it to the richtextbox.(This is second problem)
Let's look this sentence as an example think that I read this from txt file.
"I have to count each DISTINCT word each sentence"
{1 1,2 1,3 2,4 1,5,2,6,1,7,1,8,1} the first number is index of the word and the second one is how many times this word is in a sentence. But as you see we have 9 words but we write 8 index because the word "each" we have 2 and I have to write it once.
I hope that I make it clear
Thank you again
Sergey Alexandrovich Kryukov 12-Nov-13 17:23pm    
As I say, you need to 1) separate it from UI, 2) embrace separation of concerns in general. For distinct set of something, use, say, System.Collections.Generic.HashSet<> or System.Collections.Generic.Dictionary<,> and them operate the populated collection. The Count of collection tells you what you need. And so on... You work is way too much ad hoc, but you need to separate universal and agnostic part of code from application-aware and concrete, and so one, structure everything properly. This cannot be taught in one Quick Answer, this is just the work you need to do using systematic approach...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900