collapse collapse

* Who's Online

  • Dot Guests: 46
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Author Topic: Split Paragraphs into Sentences  (Read 17231 times)

0 Members and 1 Guest are viewing this topic.

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Split Paragraphs into Sentences
« on: May 02, 2010, 02:53:47 pm »
Code: [Select]
//this is my string
string para = @":P random random random random random random random random random random random :P
Hi random random random random random random random random random random random ..
..
...";

//so i want to split the Paragraph 'para' into 4 sentences
string sen1 = ":P random random random random random random random random random random random :P";
string sen2 = "Hi random random random random random random random random random random random ..";
string sen3 = "..";
string sen4 = "...";
//How i do that?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #1 on: May 02, 2010, 03:22:49 pm »
Ask yourself, what is a sentence? What does it contain? In the English language what is the sentence delimiter?
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #2 on: May 02, 2010, 03:31:21 pm »
the end of the sentence is "
"

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #3 on: May 02, 2010, 03:49:41 pm »
how do you split then?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #4 on: May 02, 2010, 05:17:25 pm »
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #5 on: May 02, 2010, 06:06:36 pm »
at http://dotnetperls.com/string-split
Code: [Select]
using System;

class Program
{
    static void Main()
    {
        string s = "there is a cat";
        //
        // Split string on spaces.
        // ... This will separate all the words.
        //
        string[] words = s.Split(' ');
        foreach (string word in words)
        {
            Console.WriteLine(word);
        }
    }
}
i can't modify the "word" in
Code: [Select]
        foreach (string word in words)
        {
        }
why?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #6 on: May 02, 2010, 06:10:22 pm »
at http://dotnetperls.com/string-split
Code: [Select]
using System;

class Program
{
    static void Main()
    {
        string s = "there is a cat";
        //
        // Split string on spaces.
        // ... This will separate all the words.
        //
        string[] words = s.Split(' ');
        foreach (string word in words)
        {
            Console.WriteLine(word);
        }
    }
}
i can't modify the "word" in
Code: [Select]
        foreach (string word in words)
        {
        }
why?
Modify? You can change word all you want, perhaps you should brush up on what the foreach actually does.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #7 on: May 02, 2010, 06:16:49 pm »
one more question, how do you find a string in a paragraph and then add "<-" to the end of the sentence?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #8 on: May 02, 2010, 06:19:13 pm »
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #9 on: May 02, 2010, 06:46:26 pm »
i want to get the line number of the paragraph that has the string or strings

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #10 on: May 02, 2010, 07:23:46 pm »
Code: [Select]
                         string [] split = new str.Split(new Char [] {'\n'});
                         int num1 = 0;
             while(split[num1] != null)
             {
              num1 = num1 +1;
              if (split[num1]=="hi")
             {
              split[num1] = split[num1].Replace("hi",":D");
              split[num1] = split[num1] + ":D :D :D";
             }
             }
um.. runtime error?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #11 on: May 02, 2010, 07:27:37 pm »
Code: [Select]
                        string [] split = new str.Split(new Char [] {'\n'});
                         int num1 = 0;
            while(split[num1] != null)
            {
            num1 = num1 +1;
            if (split[num1]=="hi")
            {
            split[num1] = split[num1].Replace("hi",":D");
            split[num1] = split[num1] + ":D :D :D";
            }
            }
um.. runtime error?
Please attach your cs file.

Also in C#, there are no pointers as garbage collection is automatic.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #12 on: May 02, 2010, 07:44:34 pm »
Code: [Select]
using System;
namespace test
{
class Program
{
public static void Main(string[] args)
{
                         string newstr= @"Hi :D people
Hi
Hi";
                         string [] split = newstr.Split(new Char [] {'\n'});
                         int num1 = 0;
             while(split[num1] != null)
             {
              num1 = num1 +1;
              if (split[num1]=="hi")
             {
              split[num1] = split[num1].Replace("hi",":D");
              split[num1] = split[num1] + ":D :D :D";
             }
             }
                          Console.ReadKey(true);
         }
     }
}

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #13 on: May 02, 2010, 07:46:22 pm »
Attach! Don't copy and paste.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #14 on: May 02, 2010, 07:48:45 pm »
pretty simple

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #15 on: May 02, 2010, 07:50:10 pm »
Like I just said, C# doesn't use pointers so you don't use the new keyword.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #16 on: May 02, 2010, 07:55:52 pm »
i don't get it?
every program has pointers in the memory?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #17 on: May 02, 2010, 08:32:02 pm »
Sorry your new char threw me off because that doesn't look right.
In any case:
Code: [Select]
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the boun
ds of the array.
   at test.Program.Main(String[] args)
That is the error I get when I try to run your program.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #18 on: May 02, 2010, 08:40:40 pm »
yes me too i don't know why?

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #19 on: May 02, 2010, 08:42:14 pm »
It means you are trying to access an array outside of its bounds.
Taking a quick look - you should increment num1 at the end of the loop.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #20 on: May 02, 2010, 08:52:06 pm »
Cannot use local variable 'num1' before it is declared (CS0841)

Offline FireX

  • Full Member
  • ***
  • Posts: 108
  • Reputation 131
  • Gender: Male
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #21 on: May 02, 2010, 09:30:29 pm »
-_- why won't it work!!!!

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #22 on: May 03, 2010, 04:32:26 pm »
You do know I can't read the code on your HD? You need to upload your code to the site.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Split Paragraphs into Sentences
« Reply #23 on: May 03, 2010, 05:09:32 pm »
Cannot use local variable 'num1' before it is declared (CS0841)
Its complaining that you never declared. So fix it. Go declare it someplace.
Code: C#
  1. int inum =0;
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline 0xDEAD10CC

  • Newbie
  • *
  • Posts: 21
  • Reputation 0
  • Gender: Male
  • void of_space();
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #24 on: April 06, 2014, 04:06:08 pm »
Like I just said, C# doesn't use pointers so you don't use the new keyword.

What?  :o C# does have pointers if unsafe context is specified. You DO however, use the new keyword to create arrays.

I would rewrite that like so though:
Code: [Select]
string newstr = @"Hi :D people
Hi
Hi";
string[] arr = newstr.Split(new[] { '\n' });
for (int i = 0; i < arr.Length; ++i)
{
  if (arr[i] == "hi")
  {
    arr[i] = arr[i].Replace("hi", ":D");
    arr[i] += ":D :D :D";
  }
}

The contents are split, but nothing will be changed though, because "hi" != "Hi". If you want a case insensitive check, you'll have to use a string comparer (recommended). If you use ToLower() you may (depending on what kind of encoding the string has) run into localization issues.

Code: [Select]
if (arr[i].Equals("hi", StringComparison.OrdinalIgnoreCase))
But Replace() is still case sensitive, so you'll either have to use Regex, or create your own method to replace portions of the string using case insensitive strategies. Perhaps IndexOf(), Substring(), and concatenation? Regex is going to be slow unless you are dealing with larger strings and compiled regex to 'minify' the overhead to make it justifiable.
« Last Edit: April 06, 2014, 04:15:15 pm by 0xDEAD10CC »
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #25 on: April 06, 2014, 09:35:27 pm »
Like I just said, C# doesn't use pointers so you don't use the new keyword.

What?  :o C# does have pointers if unsafe context is specified. You DO however, use the new keyword to create arrays.

I suppose I do need to take that back - I just read an article on them the other day. Very interesting - especially considering they provide no smart pointer constructs (at least none I could see). However, by Microsoft's own accord you should not use them but rather pass things as references.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline 0xDEAD10CC

  • Newbie
  • *
  • Posts: 21
  • Reputation 0
  • Gender: Male
  • void of_space();
    • View Profile
Re: Split Paragraphs into Sentences
« Reply #26 on: April 06, 2014, 11:42:29 pm »
Exactly! You've done your research well.  :D

I like using them for various things... If I'm just writing test code it goes nicely with a few things. I specifically like stackalloc.
[ Assembly / C++ / .NET / Haskell / J Programmer ]

 

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]