Quantcast

How to extract some part of string using GROOVY ?

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to extract some part of string using GROOVY ?

Harsha1
Hi, I am brand new to java but I have a requirement where i am suppose to use Groovy.
So is there any good features that can address my requirement?
I have string like
str = "This is a sample text. Trying to explore groovy. In India, Bangalore, Harsha, N., with experts help";

In the above string am only interested in the Name of the person "Harsha" which will always be followed by letter N. and ","
(N stands for Name which will be after every name)

another example is ,
str = "This is a sample text. Trying to explore groovy. In India, Bangalore, Daniel O' Relly, N., with experts help";

Here I need to extract " Daniel O' Relly" which is followed by N. and "," to continue

So is there any features available in groovy that will do the job??

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Robert Fischer
Sounds like you want a regular expression.

~~ Robert.

Harsha1 wrote:

> Hi, I am brand new to java but I have a requirement where i am suppose to use
> Groovy.
> So is there any good features that can address my requirement?
> I have string like
> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
> position sued county board of education in state court to recover $100,000
> in compensatory damages for alleged age discrimination under the federal Age
> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
> dismissed educator's claim without prejudice. Educator appealed.";
>
> In the above string am only interested in the judge name "Jakubowski" which
> will always followed by letter J.
>
> So is there any features available in groovy that will do the job??
>
>
--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html


signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Edward Sumerfield-2
In reply to this post by Harsha1
Here is a good source of code snippets. See the String section and search for "=~" for the regex stuff

    http://pleac.sourceforge.net/pleac_groovy/index.html

More details on regex specifically

    http://groovy.codehaus.org/Regular+Expressions

On Thu, Jun 18, 2009 at 1:31 PM, Harsha1 <[hidden email]> wrote:

Hi, I am brand new to java but I have a requirement where i am suppose to use
Groovy.
So is there any good features that can address my requirement?
I have string like
str = "Background:  Educator who unsuccessfully tried to obtain a teaching
position sued county board of education in state court to recover $100,000
in compensatory damages for alleged age discrimination under the federal Age
Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
dismissed educator's claim without prejudice. Educator appealed.";

In the above string am only interested in the judge name "Jakubowski" which
will always followed by letter J.

So is there any features available in groovy that will do the job??


--
View this message in context: http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Martin C. Martin-2

mystring =~ /\bJ[a-zA-Z]+/

will return a list of all words that start with a capital J.  As Edward
said, you can see more examples here:

http://groovy.codehaus.org/Regular+Expressions

Best,
Martin

Edward Sumerfield wrote:

> Here is a good source of code snippets. See the String section and
> search for "=~" for the regex stuff
>
>     http://pleac.sourceforge.net/pleac_groovy/index.html
>
> More details on regex specifically
>
>     http://groovy.codehaus.org/Regular+Expressions
>
> On Thu, Jun 18, 2009 at 1:31 PM, Harsha1 <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     Hi, I am brand new to java but I have a requirement where i am
>     suppose to use
>     Groovy.
>     So is there any good features that can address my requirement?
>     I have string like
>     str = "Background:  Educator who unsuccessfully tried to obtain a
>     teaching
>     position sued county board of education in state court to recover
>     $100,000
>     in compensatory damages for alleged age discrimination under the
>     federal Age
>     Discrimination in Employment Act (ADEA). Board filed a motion to
>     dismiss.
>     The Circuit Court, Baltimore County, Jakubowski, J., granted the
>     motion and
>     dismissed educator's claim without prejudice. Educator appealed.";
>
>     In the above string am only interested in the judge name
>     "Jakubowski" which
>     will always followed by letter J.
>
>     So is there any features available in groovy that will do the job??
>
>
>     --
>     View this message in context:
>     http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
>     Sent from the groovy - user mailing list archive at Nabble.com.
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe from this list, please visit:
>
>        http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Ted Naleid
Groovy 1.6.3 adds String.find to the regular expression toolkit and it's built for this kind of thing:


str = """Background:  Educator who unsuccessfully tried to obtain a teaching
position sued county board of education in state court to recover \$100,000
in compensatory damages for alleged age discrimination under the federal Age
Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
dismissed educator's claim without prejudice. Educator appealed."""


str.find(/\b\S+ J\./)


On Thu, Jun 18, 2009 at 1:08 PM, Martin C. Martin <[hidden email]> wrote:

mystring =~ /\bJ[a-zA-Z]+/

will return a list of all words that start with a capital J.  As Edward said, you can see more examples here: Best,
Martin

Edward Sumerfield wrote:
Here is a good source of code snippets. See the String section and search for "=~" for the regex stuff

   http://pleac.sourceforge.net/pleac_groovy/index.html

More details on regex specifically

   http://groovy.codehaus.org/Regular+Expressions

On Thu, Jun 18, 2009 at 1:31 PM, Harsha1 <[hidden email] <mailto:[hidden email]>> wrote:


   Hi, I am brand new to java but I have a requirement where i am
   suppose to use
   Groovy.
   So is there any good features that can address my requirement?
   I have string like
   str = "Background:  Educator who unsuccessfully tried to obtain a
   teaching
   position sued county board of education in state court to recover
   $100,000
   in compensatory damages for alleged age discrimination under the
   federal Age
   Discrimination in Employment Act (ADEA). Board filed a motion to
   dismiss.
   The Circuit Court, Baltimore County, Jakubowski, J., granted the
   motion and
   dismissed educator's claim without prejudice. Educator appealed.";

   In the above string am only interested in the judge name
   "Jakubowski" which
   will always followed by letter J.

   So is there any features available in groovy that will do the job??


   --
   View this message in context:
   http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
   Sent from the groovy - user mailing list archive at Nabble.com.


   ---------------------------------------------------------------------
   To unsubscribe from this list, please visit:

      http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Harsha1
In reply to this post by Edward Sumerfield-2

So is the Regular expression feature in groovy provide more feature than the regular expression of Java??

Edward Sumerfield-2 wrote
Here is a good source of code snippets. See the String section and search
for "=~" for the regex stuff

    http://pleac.sourceforge.net/pleac_groovy/index.html

More details on regex specifically

    http://groovy.codehaus.org/Regular+Expressions

On Thu, Jun 18, 2009 at 1:31 PM, Harsha1 <99harsha.h.n99@gmail.com> wrote:

>
> Hi, I am brand new to java but I have a requirement where i am suppose to
> use
> Groovy.
> So is there any good features that can address my requirement?
> I have string like
> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
> position sued county board of education in state court to recover $100,000
> in compensatory damages for alleged age discrimination under the federal
> Age
> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
> dismissed educator's claim without prejudice. Educator appealed.";
>
> In the above string am only interested in the judge name "Jakubowski" which
> will always followed by letter J.
>
> So is there any features available in groovy that will do the job??
>
>
> --
> View this message in context:
> http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Russel Winder-2
In reply to this post by Harsha1
Is it fair to assume this is an assignment on a programming course?

On Thu, 2009-06-18 at 10:31 -0700, Harsha1 wrote:

> Hi, I am brand new to java but I have a requirement where i am suppose to use
> Groovy.
> So is there any good features that can address my requirement?
> I have string like
> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
> position sued county board of education in state court to recover $100,000
> in compensatory damages for alleged age discrimination under the federal Age
> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
> dismissed educator's claim without prejudice. Educator appealed.";
>
> In the above string am only interested in the judge name "Jakubowski" which
> will always followed by letter J.
>
> So is there any features available in groovy that will do the job??
>
>
--
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: [hidden email]
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:[hidden email]
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

instance via String

Andreas Jöcker
In reply to this post by Harsha1
Hi,

calling a method which I pass as a String parameter works - eg

def foo() {
  println 'bar'
}

def l = 'foo'
"$l"()

But how do I instanciate a class with the same mechanism - eg

class Foo {
  def bar() {
     println 'foobar'
  }
}

def l = 'Foo'
new "$l"().bar()

breaks with

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, test.groovy: 8: unexpected token:  @ line 8, column 5
 new "$l"().bar()

how can I create instances with that mechanism ?

Cheers
A

--

Andreas Jöcker
GiS - Gesellschaft für integrierte Systemplanung mbH
Junkersstr. 2
69469 Weinheim

E-Mail   [hidden email]
Telefon +49 6201 503-59
Fax     +49 6201 503-66

Gesellschaft für integrierte Systemplanung mbH
Geschäftsführer: Eckhard Haffmann, Alfred Gai, Bernd Heselmann
Sitz der Gesellschaft: Zeppelinstr. 11 - 91052 Erlangen
Amtsgericht Fürth/Bayern - Handelsregister-Nr. HRB 3435


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: instance via String

Martin C. Martin-2
I think you need to use Java reflection:

Class.forName("my.package.Foo").getConstructor(...).newInstance(...)

It's a shame that you have to use a completely different syntax, but in
some common cases, the parser needs to know whether a given name starts
with a capital letter during parsing, to know whether its a type or a
method, e.g.:

String x  // declares variable
println x // calls println method

"$blah" x // What does this do?

Best,
Martin

Andreas Jöcker wrote:

> Hi,
>
> calling a method which I pass as a String parameter works - eg
>
> def foo() {
>   println 'bar'
> }
>
> def l = 'foo'
> "$l"()
>
> But how do I instanciate a class with the same mechanism - eg
>
> class Foo {
>   def bar() {
>      println 'foobar'
>   }
> }
>
> def l = 'Foo'
> new "$l"().bar()
>
> breaks with
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, test.groovy: 8: unexpected token:  @ line 8, column 5
>  new "$l"().bar()
>
> how can I create instances with that mechanism ?
>
> Cheers
> A
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Martin C. Martin-2
In reply to this post by Harsha1


Harsha1 wrote:
>
> So is the Regular expression feature in groovy provide more feature than the
> regular expression of Java??

Well, it uses the Java regular expression underneath.  So in terms of
what strings it can match, and what information you can get, its the
same.  It just provides a more convenient syntax for it.

Best,
Martin

>
>
> Edward Sumerfield-2 wrote:
>> Here is a good source of code snippets. See the String section and search
>> for "=~" for the regex stuff
>>
>>     http://pleac.sourceforge.net/pleac_groovy/index.html
>>
>> More details on regex specifically
>>
>>     http://groovy.codehaus.org/Regular+Expressions
>>
>> On Thu, Jun 18, 2009 at 1:31 PM, Harsha1 <[hidden email]> wrote:
>>
>>> Hi, I am brand new to java but I have a requirement where i am suppose to
>>> use
>>> Groovy.
>>> So is there any good features that can address my requirement?
>>> I have string like
>>> str = "Background:  Educator who unsuccessfully tried to obtain a
>>> teaching
>>> position sued county board of education in state court to recover
>>> $100,000
>>> in compensatory damages for alleged age discrimination under the federal
>>> Age
>>> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
>>> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion
>>> and
>>> dismissed educator's claim without prejudice. Educator appealed.";
>>>
>>> In the above string am only interested in the judge name "Jakubowski"
>>> which
>>> will always followed by letter J.
>>>
>>> So is there any features available in groovy that will do the job??
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
>>> Sent from the groovy - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Martin C. Martin-2
In reply to this post by Russel Winder-2
Is there actually a programming course somewhere that requires the use
of Groovy?  Usually they stick to the most popular ones, where "popular"
is defined by the number of jobs requiring that language.  Java, C/C++,
python, etc.

But perhaps I'm out of touch.

Russel Winder wrote:

> Is it fair to assume this is an assignment on a programming course?
>
> On Thu, 2009-06-18 at 10:31 -0700, Harsha1 wrote:
>> Hi, I am brand new to java but I have a requirement where i am suppose to use
>> Groovy.
>> So is there any good features that can address my requirement?
>> I have string like
>> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
>> position sued county board of education in state court to recover $100,000
>> in compensatory damages for alleged age discrimination under the federal Age
>> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
>> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
>> dismissed educator's claim without prejudice. Educator appealed.";
>>
>> In the above string am only interested in the judge name "Jakubowski" which
>> will always followed by letter J.
>>
>> So is there any features available in groovy that will do the job??
>>
>>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: instance via String

Jochen Theodorou
In reply to this post by Martin C. Martin-2
Martin C. Martin schrieb:
> I think you need to use Java reflection:
>
> Class.forName("my.package.Foo").getConstructor(...).newInstance(...)

I say:

this.class.classLoader.loadClass("my.package.Foo").newInstance(...)

bye blackdrag


--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Jochen Theodorou
In reply to this post by Martin C. Martin-2
Martin C. Martin schrieb:
> Is there actually a programming course somewhere that requires the use
> of Groovy?  Usually they stick to the most popular ones, where "popular"
> is defined by the number of jobs requiring that language.  Java, C/C++,
> python, etc.

I have no link here, but I think there are several courses at universities

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Russel Winder-2
In reply to this post by Martin C. Martin-2
On Fri, 2009-06-19 at 07:36 -0400, Martin C. Martin wrote:
> Is there actually a programming course somewhere that requires the use
> of Groovy?  Usually they stick to the most popular ones, where "popular"
> is defined by the number of jobs requiring that language.  Java, C/C++,
> python, etc.
>
> But perhaps I'm out of touch.

Graham Roberts at UCL now uses Groovy as the first programming language
for the CS programme -- they then follow with Prolog and Java.

He and I are writing a new introductory programming textbook -- should
be finished over the summer.

When it comes to education, Groovy is the new Java :-)

Unless of course you use Python, in which case I recommend "Python for
Rookies" but that is probably because my name is on the cover :-)

--
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: [hidden email]
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:[hidden email]
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Chris Broadfoot
In reply to this post by Harsha1
groovy:000> m = str =~ /\b([^,]+), J\.,/; m.find(); m.group(1)
===> Jakubowski

You will also want to escape the $ in "$100,000" as it will be
interpreted as a GString and won't be able to parse it.

2009/6/19 Harsha1 <[hidden email]>:

>
> Hi, I am brand new to java but I have a requirement where i am suppose to use
> Groovy.
> So is there any good features that can address my requirement?
> I have string like
> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
> position sued county board of education in state court to recover $100,000
> in compensatory damages for alleged age discrimination under the federal Age
> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
> dismissed educator's claim without prejudice. Educator appealed.";
>
> In the above string am only interested in the judge name "Jakubowski" which
> will always followed by letter J.
>
> So is there any features available in groovy that will do the job??
>
>
> --
> View this message in context: http://www.nabble.com/How-to-extract-some-part-of-string-using-GROOVY---tp24095339p24095339.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: instance via String

Andreas Jöcker
In reply to this post by Jochen Theodorou
thanks for the hints :)

Am 19.06.2009 13:40, Jochen Theodorou schrieb:

> Martin C. Martin schrieb:
>  
>> I think you need to use Java reflection:
>>
>> Class.forName("my.package.Foo").getConstructor(...).newInstance(...)
>>    
>
> I say:
>
> this.class.classLoader.loadClass("my.package.Foo").newInstance(...)
>
> bye blackdrag
>
>
>  


--

Andreas Jöcker
GiS - Gesellschaft für integrierte Systemplanung mbH
Junkersstr. 2
69469 Weinheim

E-Mail   [hidden email]
Telefon +49 6201 503-59
Fax     +49 6201 503-66

Gesellschaft für integrierte Systemplanung mbH
Geschäftsführer: Eckhard Haffmann, Alfred Gai, Bernd Heselmann
Sitz der Gesellschaft: Zeppelinstr. 11 - 91052 Erlangen
Amtsgericht Fürth/Bayern - Handelsregister-Nr. HRB 3435


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Harsha1
In reply to this post by Russel Winder-2
Hi Russel,
Yes, you can take it that way. Its a part of my assignment.

I have been told to extract that Name part from the paragraph using groovy itself.
I have done this in Java by using Indexof() and lastindexof() functions. But its not been accepted. So when i inquired with others, i got to know that the only way left to do this is using Regular expression.

I am not yet familiar with Regular expression of Java only, so this part is looking like clumsy to me.



Russel Winder-4 wrote
Is it fair to assume this is an assignment on a programming course?

On Thu, 2009-06-18 at 10:31 -0700, Harsha1 wrote:
> Hi, I am brand new to java but I have a requirement where i am suppose to use
> Groovy.
> So is there any good features that can address my requirement?
> I have string like
> str = "Background:  Educator who unsuccessfully tried to obtain a teaching
> position sued county board of education in state court to recover $100,000
> in compensatory damages for alleged age discrimination under the federal Age
> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion and
> dismissed educator's claim without prejudice. Educator appealed.";
>
> In the above string am only interested in the judge name "Jakubowski" which
> will always followed by letter J.
>
> So is there any features available in groovy that will do the job??
>
>
--
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: russel@russel.org.uk
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:russel.winder@ekiga.net
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Martin C. Martin-2
Hi,

Out of curiosity, what school are you at that uses Groovy?

Best,
Martin

Harsha1 wrote:

> Hi Russel,
> Yes, you can take it that way. Its a part of my assignment.
>
> I have been told to extract that Name part from the paragraph using groovy
> itself.
> I have done this in Java by using Indexof() and lastindexof() functions. But
> its not been accepted. So when i inquired with others, i got to know that
> the only way left to do this is using Regular expression.
>
> I am not yet familiar with Regular expression of Java only, so this part is
> looking like clumsy to me.
>
>
>
>
> Russel Winder-4 wrote:
>> Is it fair to assume this is an assignment on a programming course?
>>
>> On Thu, 2009-06-18 at 10:31 -0700, Harsha1 wrote:
>>> Hi, I am brand new to java but I have a requirement where i am suppose to
>>> use
>>> Groovy.
>>> So is there any good features that can address my requirement?
>>> I have string like
>>> str = "Background:  Educator who unsuccessfully tried to obtain a
>>> teaching
>>> position sued county board of education in state court to recover
>>> $100,000
>>> in compensatory damages for alleged age discrimination under the federal
>>> Age
>>> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
>>> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion
>>> and
>>> dismissed educator's claim without prejudice. Educator appealed.";
>>>
>>> In the above string am only interested in the judge name "Jakubowski"
>>> which
>>> will always followed by letter J.
>>>
>>> So is there any features available in groovy that will do the job??
>>>
>>>
>> --
>> Russel.
>> =============================================================================
>> Dr Russel Winder      Partner
>>                                             xmpp: [hidden email]
>> Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
>> 41 Buckmaster Road,   f: +44 8700 516 084   voip:
>> sip:[hidden email]
>> London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder
>>
>>  
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Russel Winder-2
In reply to this post by Harsha1
On Mon, 2009-06-22 at 03:50 -0700, Harsha1 wrote:
> Hi Russel,
> Yes, you can take it that way. Its a part of my assignment.

OK, no problem per se.  I have seen many instances of students trying to
hoodwink people on mailing lists to do their assignments for them, so I
get very cautious when I see emails such as this.

(If you check out my CV you will see why I have become so sensitized to
this issue. :-)

Now we know what the situation is we can respond far more
constructively.

> I have been told to extract that Name part from the paragraph using groovy
> itself.

This is still a bit under-specified I'm afraid.  Is it known that you
are looking for the string "Jakubowski, J" or is it more complicated,
e.g. that you are looking for a name of a judge.  

> I have done this in Java by using Indexof() and lastindexof() functions. But
> its not been accepted. So when i inquired with others, i got to know that
> the only way left to do this is using Regular expression.

Regular expressions are almost certainly the tool needed to get a good
answer to the question, but without seeing the actual question, it is
difficult to know why you got the reaction you did.

> I am not yet familiar with Regular expression of Java only, so this part is
> looking like clumsy to me.

Regular expressions are regular expressions.  Languages like Java, C++,
Python, Groovy, Perl and Ruby all have slightly different language
support.  Most things in Java are a bit clumsy of expression :-)  Groovy
uses the Java regular expression classes directly but provides lots of
syntactic short cuts so that the code you write as a programmer is far
less verbose, and generally far more comprehensible.

> Russel Winder-4 wrote:
> >
> > Is it fair to assume this is an assignment on a programming course?
> >
> > On Thu, 2009-06-18 at 10:31 -0700, Harsha1 wrote:
> >> Hi, I am brand new to java but I have a requirement where i am suppose to
> >> use
> >> Groovy.
> >> So is there any good features that can address my requirement?
> >> I have string like
> >> str = "Background:  Educator who unsuccessfully tried to obtain a
> >> teaching
> >> position sued county board of education in state court to recover
> >> $100,000
> >> in compensatory damages for alleged age discrimination under the federal
> >> Age
> >> Discrimination in Employment Act (ADEA). Board filed a motion to dismiss.
> >> The Circuit Court, Baltimore County, Jakubowski, J., granted the motion
> >> and
> >> dismissed educator's claim without prejudice. Educator appealed.";
> >>
> >> In the above string am only interested in the judge name "Jakubowski"
> >> which
> >> will always followed by letter J.
> >>
> >> So is there any features available in groovy that will do the job??
Definitely, the real problem here is to know what it is you want to do.
The phrase 'interested in the judge name "Jakubowski" which will always
followed by letter J.' doesn't really say what it is the program is to
do.

--
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: [hidden email]
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:[hidden email]
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to extract some part of string using GROOVY ?

Russel Winder-2
In reply to this post by Martin C. Martin-2
On Mon, 2009-06-22 at 07:27 -0400, Martin C. Martin wrote:
> Hi,
>
> Out of curiosity, what school are you at that uses Groovy?

Definitely and good question, I wish I had remembered to ask it. :-)

Interesting sidebar:  In the USA (and Canada?) "school" means any form
of education from nursery to postgraduate degree.  In UK (and Europe,
Australia, South Africa, New Zealand?) "school" generally means
pre-University.

It would be good if Groovy was being used for pre-University programming
courses!
 
--
Russel.
=============================================================================
Dr Russel Winder      Partner
                                            xmpp: [hidden email]
Concertant LLP        t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,   f: +44 8700 516 084   voip: sip:[hidden email]
London SW11 1EN, UK   m: +44 7770 465 077   skype: russel_winder

signature.asc (204 bytes) Download Attachment
12
Loading...