[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
Can i break the String to bits?  XML
Forum Index » New to Java
Author Message
NewOrder

Newbie

Joined: 06/22/2010 05:04:50
Messages: 7
Offline

what i am trying to do here, is to make it possible for the user to type 2 lines, and then say(or display) whether the string of the first sentence correspond to the string of the second sentence.

so for example:

first sentence:
i will go shopping

second sentence:
Tomorrow, i will go swiming.

" i will go" corresponds in the second sentence. so how can i make the program look for corresponding words, and identify them?

so far , i have written this. but i dont know how to finish.


stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline

Ultimately you're trying to do natural language parsing - a very difficult thing to do with any programming language. You might consider breaking the sentence into individual words (see String.split() for details) and then find out how many words match. However, that will mean that two sentences that may or may not be related but have a high number of the same words would be considered similar even if they are not.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
NewOrder

Newbie

Joined: 06/22/2010 05:04:50
Messages: 7
Offline

stdunbar wrote:Ultimately you're trying to do natural language parsing - a very difficult thing to do with any programming language. You might consider breaking the sentence into individual words (see String.split() for details) and then find out how many words match. However, that will mean that two sentences that may or may not be related but have a high number of the same words would be considered similar even if they are not.





the problem comes when the user might write a sentence with 100 ways. i cant compare all his words using loops or for methods.


i thought to make two variables

string end= " "

String Word= end+Str.charAt() + end

but how can i number each variable and make it look at the second string with no problem


view plaincopy to clipboardprint?

1. import java.io.*;
2. class Ex11
3. {
4.
5. public static void main(String[] args)
6. {
7. Console console=System.console();
8. System.out.println("please write a sentence"+" ");
9. String Str;
10. Str=console.readLine();
11.
12.
13. System.out.println("please write another sentence"+" ");
14. String Str2;
15. Str2=console.readLine();
16.
17.
18.
19. for(int i=0; i<Str.length(); i++){
20. for(int j=0; j><Str2.length(); j++){
21. if(Str.charAt(i)==Str2.charAt(j)){
22. char Str3;
23. Str3 += Str.charAt(i);
24. System.out.println(Str3);
25.
26. }
27. }
28.
29.
30. }
31.
32.
33.
34.
35.
36. }
37. }
38.
39.
40.

import java.io.*; class Ex11 { public static void main(String[] args) { Console console=System.console(); System.out.println("please write a sentence"+" "); String Str; Str=console.readLine(); System.out.println("please write another sentence"+" "); String Str2; Str2=console.readLine(); for(int i=0; i><Str.length(); i++){ for(int j=0; j><Str2.length(); j++){ if(Str.charAt(i)==Str2.charAt(j)){ char Str3; Str3 += Str.charAt(i); System.out.println(Str3); } } } } } >



i tried.

i found that if you add all the characters, you get no where.

Example
lets say i remove all the " " from Sentence A and B and compare between them.

i went to school yesterday
i went to a hospital yesterday

that would be:
iwenttoschoolyesterday
iwenttoahospitalyesterday

the computer wont identify similary charactaristics, cause the length of the string is different from the start. you wont be able to identify yesterday as similar, cause their character number is different.


The second thing that i discovered..
is that you cant isolate words and loop each one, that looping might continue for ever, cause i dont know how long a sentence can be


what i thought that would work is if i tried to define a variable called "Word"
but if " " character, i cant tell java to stop counting words before that space, can i ?


is there a way i could make java count all characters till " ", and then add all that character string to a variable called Word. then make java pass onto another String (after " ") find its characters till it reaches " ",
and add it to a word?
another variable
Words=Word+Words


is this direction possible? can it be done?

This message was edited 2 times. Last update was at 06/29/2010 00:58:57

 
Forum Index » New to Java
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle