Extract Verbs from Sentence [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to know if there is a way to extract verbs from a string.
As an example :
I'll eliminate you.
I want it to only extract "eliminate".

You probably want to be looking at using the Stanford PoS tagger (http://nlp.stanford.edu/software/tagger.shtml). It will tag the string with it's classification (e.g. verb, noun). You can then use a regular expression to pull out the verbs.

ArrayList<String> verbs = new ArrayList<>();
verbs.add("eliminate");
String yourtext = "I'll eliminate you";
for (String verb : verbs) {
int index = yourtext.indexOf(verb);
if (index >= 0) {
System.out.println("Found verb: " + verb + " at position: " + index);
}
}
I'll leave filling the verbs array up to you.

Related

How to convert String to array in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have a string String myStringArray = "[491174, 414529, 414557]";. I want output 491174, 414529, 414557 just this part. I tried many methods to convert string to array and many other things. I tried something I'm adding the code below.
My Code
String myStringArray = "[491174, 414529, 414557]";
String newArray = myStringArray.replaceAll(" ", "");
System.out.println("Before Remove : " + newArray);
String remove = newArray.replaceAll("[^a-zA-Z0-9]", ",");
String rm = remove.replaceFirst(",", "");
System.out.println("After Remove : " + rm);
Output
Before Remove : [491174,414529,414557]
After Remove : 491174,414529,414557,
As you can see I have , in the end and I don't know how to remove this ,. Please help me if you can.
rm = rm.substring(0, rm.length() - 1);

should i use remmove and is this correct in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
in the exercise they told if string contain 00 or 0 remove it
String rse="12+00+9+88";
String re="[0]{1,2}\\+";
String oper[]=chaine.split("[0-9]{1,2}\\+");
for(int i=1;i<oper.length;i++) {
if (oper.equals(re)) {
}
}
You may juse use String.replaceAll and use 2 regexes
(0+)\+ to remove zeros followed by a +
\+(0+), specific case when zeros are the last one, the + is before it
List<String> values = Arrays.asList(
"12+00+9+88",
"12+0+9+88",
"00+9+88",
"0+9+88",
"12+00",
"12+0"
);
for (String s : values) {
String r = s.replaceAll("(0+)\\+", "").replaceAll("\\+(0+)", "");
System.out.println(r);
}
12+9+88
12+9+88
9+88
9+88
12
12

best and simple String parsing in java [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Ex String Param=Value1:100,Value2:2000,Value3:30000:
What is the best way in java to trim the above mentioned string format to get the First element's value?
Result should be 100 (from the above mentioned Ex string param).
Assuming you have a String e = "Value1:100,Value2:2000,Value3:30000";
Your next step would be to analyze its structure. In this case it is very simple key:value which is comma separated.
We have to split at every "," and then ":".
String[] keyValues = e.split(",");
for(String keyValue : keyValues) {
String tupel = keyValue.split(":");
// tupel[0] is your key and tupel [1] is your value
}
You can now work with this. You can add these to a map to access it by name.
Also this How to search a string of key/value pairs in Java could be worth looking at.
If you only want the first value, you can take a substring up to the first ',':
String p = "Value1:100,Value2:2000,Value3:30000:";
int firstComma = p.indexOf(',');
if(firstComma >= 0) {
p = p.substring(0, firstComma);
}
String tuple[] = p.split(":");

Java Scanner Delimiter - Extracting Multiple Sub-strings From a Single String [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have searched nearly all pages on Stackoverflow but still have not found out how to do this. I have the following string (which is being parsed from file):
f: (matchQuan
(Recipe
(Unique FoodType "slurpee" "xxx-xxx-eee-ddd"))
(Unique IngredType "slurpee" "qqq-rrr-sss") "slurpee"
(Cup-Vol 12)).
Now, I want to parse this string again and extract the string matchQuan, the slurpee, the string Unique and FoodType and Recipe and the ID numbers i.e. xxx-xxx-eee-ddd.
How would I do something like this with multiple extractions from a single string? I can't use Scanner.next() I don't believe because it advances to the next token in string.
Thanks!
Will this help for you?
public static void getString() {
String str = "f: (matchQuan " +
"(Recipe "+
"(Unique FoodType" + " slurpee"+ " xxx-xxx-eee-ddd"+
"(Unique IngredType"+ " slurpee"+ " qqq-rrr-sss"+" slurpee" +
" (Cup - Vol 12)).";
String newStr=str.replaceAll("\\(","").replaceAll("\\)","");
String[] arrStr=newStr.split(" ");
for (int i=0;i<arrStr.length;i++){
System.out.println(arrStr[i]);
}
}

cutting chain java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
hello I have this string that is a data table I want to test if the string contains more than _ then we are cutting the chains and in each sub string in a table row
I use talend and my input is an excel
I'm really stuck who can help me please
exemple:
JEN3030_1_2_3
JEN3030_1
JEN3030_2
JEN3030_3
Try String.split()...
String input = "JEN3030_1_2_3"; //or whatever
List<String> output = new ArrayList<String>();
String[] parts = input.split("_");
for(int i = 1; i < parts.length; i++) {
output.add(parts[0] + "_" + parts[i]);
}

Categories

Resources