fork download
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args)
  7. {
  8. ArrayList<String> taggedArray = new ArrayList<String>();
  9.  
  10. //Example how the string would look like
  11. String string1 = "WRB VBD NN VB IN CC RB VBP NNP";
  12. String string2 = "WRB NN MD PRP VB DT NN IN NNS POS JJ NNS";
  13.  
  14. taggedArray.add(string1);
  15. taggedArray.add(string2);
  16.  
  17. //Nested for loop to match taggedArray(i) with taggedArray(j)
  18. for(int i = 0; i< taggedArray.size(); i++)
  19. {
  20. for(int j = i + 1; j < taggedArray.size(); j++)
  21. {
  22. Scanner scan1 = new Scanner(taggedArray.get(i));
  23.  
  24. int index1 = 0;
  25. while(scan1.hasNext())
  26. {
  27. String token1;
  28. token1 = scan1.next();
  29. System.out.println(token1);
  30. Scanner scan2 = new Scanner(taggedArray.get(j));
  31.  
  32. int index2 =0;
  33. while(scan2.hasNext())
  34. {
  35. String token2 = scan2.next();
  36.  
  37. if(token1.equals(token2))
  38. {
  39. int relPosition;
  40. //Need to get total relPosition for taggedArray.get(j)
  41. relPosition = Math.abs(index1-index2);
  42.  
  43. //The print lines help me keep track of what is going on in the loop
  44. System.out.println("Match found.");
  45. System.out.println("Relative position for " + token1 + " : " + relPosition);
  46. break;
  47.  
  48. }
  49. else
  50. {
  51. System.out.println("No Match Found.");
  52. }
  53.  
  54. index2++;
  55. }
  56.  
  57. index1++;
  58. }
  59. }
  60. }
  61. }
  62. }
Success #stdin #stdout 0.06s 246144KB
stdin
Standard input is empty
stdout
WRB
Match found.
Relative position for WRB : 0
VBD
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
NN
No Match Found.
Match found.
Relative position for NN : 1
VB
No Match Found.
No Match Found.
No Match Found.
No Match Found.
Match found.
Relative position for VB : 1
IN
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
Match found.
Relative position for IN : 3
CC
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
RB
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
VBP
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
NNP
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.
No Match Found.