Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java error for extraction  RSS feed

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm getting an error in the programcan any one help me to correct it?
the program is




Error in the program

can any one tell me how to get an output for ths like this

important example about regex
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do take some efforts to CarefullyChooseOneForum
This is the Ranch Office which is for

Questions, suggestions and whining about this site. Use the other forums to ask questions about Java.



Both your posts have been moved to a more appropriate forum

In future, while posting code, please do UseCodeTags. I have added them for you this time. As you can see the code tags make the code much more easier to read and understand
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about going through this and trying to debug on your own? Error that you are receiving
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm getting an error in the code while extraction for this program

for the text
{NP} <PLACE> Agaya/NNP Gangai/NNP </PLACE> (/( {/NP} {NP} <PLACE> Tamil/NNP </PLACE> :/: ?/. ?/. ?/. ?/. ?/. ?/. ?/. ?/. ?/. )/SYM {/NP} {NP} waterfalls/NNS {/NP} {VP} is/VBZ located/VBN {/VP} {PP} in/IN {/PP} {NP} <PLACE> Kolli/NNP Hills/NNP </PLACE> {/NP} {PP} of/IN {/PP} {NP} the/DT Eastern/NNP Ghats/NNS ./. {/NP}

expected output is
Agaya Gangai


program is
import java.io.*;
import java.util.regex.*;



class Words{
public static void main(String[] args) throws IOException
{
//String sentence = "this is an important example about regex for my work and for me ";
String sentence = "{NP} <PLACE> Agaya/NNP Gangai/NNP </PLACE> (/( {/NP} {NP} <PLACE> Tamil/NNP </PLACE> :/: ?/. ?/. ?/. ?/. ?/. ?/. ?/. ?/. ?/. )/SYM {/NP} {NP} waterfalls/NNS {/NP} {VP} is/VBZ located/VBN {/VP} {PP} in/IN {/PP} {NP} <PLACE> Kolli/NNP Hills/NNP </PLACE> {/NP} {PP} of/IN {/PP} {NP} the/DT Eastern/NNP Ghats/NNS ./. {/NP} ";
//Pattern pattern = Pattern.compile("(?<={NP}).*.(?={/NP})");
Pattern pattern = Pattern.compile("(?<={NP}.*.(?={/NP})");
//Pattern pattern = Pattern.compile("(?<=an).*.(?=for)");
Matcher matcher = pattern.matcher(sentence);
boolean found = false;
while(matcher.find())
{
System.out.println("I found the text:" +matcher.group().toString());
found = true;
}
if(!found)
{
System.out.println("I didn't found the text");
}
}
}

i'm getting an error in run time like this

Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 3
(?<={NP}.*.(?={/NP})
^
at java.util.regex.Pattern.error(Pattern.java:1730)
at java.util.regex.Pattern.closure(Pattern.java:2792)
at java.util.regex.Pattern.sequence(Pattern.java:1906)
at java.util.regex.Pattern.expr(Pattern.java:1769)
at java.util.regex.Pattern.group0(Pattern.java:2500)
at java.util.regex.Pattern.sequence(Pattern.java:1823)
at java.util.regex.Pattern.expr(Pattern.java:1769)
at java.util.regex.Pattern.compile(Pattern.java:1477)
at java.util.regex.Pattern.<init>(Pattern.java:1150)
at java.util.regex.Pattern.compile(Pattern.java:840)
at Words.main(Words.java:12)

can any one help me please?
 
Sheriff
Posts: 57868
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did it say in the link you were given?
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it telling error like this

Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 3
(?<={NP}.*.(?={/NP})
^
at java.util.regex.Pattern.error(Pattern.java:1730)
at java.util.regex.Pattern.closure(Pattern.java:2792)
at java.util.regex.Pattern.sequence(Pattern.java:1906)
at java.util.regex.Pattern.expr(Pattern.java:1769)
at java.util.regex.Pattern.group0(Pattern.java:2500)
at java.util.regex.Pattern.sequence(Pattern.java:1823)
at java.util.regex.Pattern.expr(Pattern.java:1769)
at java.util.regex.Pattern.compile(Pattern.java:1477)
at java.util.regex.Pattern.<init>(Pattern.java:1150)
at java.util.regex.Pattern.compile(Pattern.java:840)
at Words.main(Words.java:12)

for the abouve program.there is no link given for this .i need to extract the words within that {NP} *{/NP}
can you help me how to get that output please?
 
Java Cowboy
Sheriff
Posts: 16081
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error means that (?<={NP}.*.(?={/NP}) is not a valid regular expression.

Lookup the API documentation of class java.util.regex.Pattern. It describes exactly how regular expressions in Java work.

I haven't tried it out, but I think you'll need to escape the { and } in the regular expression. Try this: (?<=\\{NP\\}.*.(?=\\{/NP\\})
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i got it .. thank's a lot.. but i need only the name Agaya Gangai.now i'm getting all the words after that alos.how to get only that word ? can you tell me the method how to proceed?
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

can any one tell me how to extract multiple words from the sentence using the java command and what is the syntax.for matching one words we use "pattern.compile" but for multiple words tags how to give the syntax for the document and how to match it to relevant queries.can any one help me how to proceed?
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another learning resource for regex: http://www.regular-expressions.info/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!