- Timestamp:
- 07/23/14 18:18:11 (10 years ago)
- Location:
- branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/AlignmentAlgorithm.java
r1612 r1620 6 6 7 7 public interface AlignmentAlgorithm { 8 9 public abstract void align(int[] input1, int[] input2, SubstitutionMatrix submat,float threshold);10 8 11 9 /** … … 20 18 public abstract void printAlignment(); 21 19 22 public abstract ArrayList<ArrayList<NumberSequence>> getMatches(); 20 public abstract ArrayList<Match> getMatches(); 21 22 void align(NumberSequence input1, NumberSequence input2, 23 SubstitutionMatrix submat, float threshold); 23 24 24 25 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NeedlemanWunsch.java
r1616 r1620 260 260 261 261 @Override 262 public ArrayList< ArrayList<NumberSequence>> getMatches() {262 public ArrayList<Match> getMatches() { 263 263 // TODO Auto-generated method stub 264 264 return null; … … 266 266 267 267 @Override 268 public void align( int[] input1, int[]input2, SubstitutionMatrix submat,268 public void align(NumberSequence input1, NumberSequence input2, SubstitutionMatrix submat, 269 269 float threshold) { 270 this.input1 = input1 ;271 this.input2 = input2 ;272 length1 = input1. length;273 length2 = input2. length;270 this.input1 = input1.getSequence(); 271 this.input2 = input2.getSequence(); 272 length1 = input1.size(); 273 length2 = input2.size(); 274 274 this.submat = submat; 275 275 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1619 r1620 6 6 public class NumberSequence { 7 7 private int[] sequence; 8 private int signature; 8 private int id; 9 10 public ArrayList<Match> getMatches() { 11 return matches; 12 } 13 14 15 public void setMatches(ArrayList<Match> matches) { 16 this.matches = matches; 17 } 18 19 public void addMatches(ArrayList<Match> matches) { 20 this.matches.addAll(matches); 21 } 22 23 private ArrayList<Match> matches; 9 24 10 25 public NumberSequence(int size) { … … 12 27 sequence = new int[size]; 13 28 } 14 29 15 30 public int[] getSequence() { 16 31 return sequence; … … 21 36 } 22 37 23 public int getSignature() { 24 return signature; 25 } 26 27 public void setSignature(int signature) { 28 this.signature = signature; 29 } 38 30 39 31 40 public void printSequence() { … … 38 47 public NumberSequence shuffle() { 39 48 NumberSequence result = new NumberSequence(sequence.length); 49 result.setId(getId()); 40 50 result.setSequence(this.sequence); 41 51 Random rgen = new Random(); … … 51 61 } 52 62 53 // TODO: This can be done faster 54 public int containsPattern( ArrayList<NumberSequence>pattern) {63 64 public int containsPattern(Match pattern) { 55 65 int i = 0; 56 66 int count = 0; 57 int[] pat1 = pattern.get (0).getSequence();58 int[] pat2 = pattern.get (1).getSequence();67 int[] pat1 = pattern.getFirstSequence().getSequence(); 68 int[] pat2 = pattern.getSecondSequence().getSequence(); 59 69 notmatched: while (i < sequence.length - pat1.length) { 60 70 if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { 61 for (int j = 0; j < pat1.length; j++) { 62 if (sequence[i + j] != pat1[j] 63 && sequence[i + j] != pat2[j]) { 71 int ipat1 =0; 72 int ipat2 =0; 73 while(ipat1 < pat1.length && ipat2<pat2.length) { 74 if(pat1[ipat1]==-1) { 75 ipat1++; 76 continue; 77 } 78 if(pat2[ipat2]==-1) { 79 ipat2++; 80 continue; 81 } 82 if (sequence[i + ipat1] != pat1[ipat1] 83 && sequence[i + ipat2] != pat2[ipat2]) { 64 84 i++; 65 85 continue notmatched; 66 86 } 87 ipat1++; 88 ipat2++; 67 89 } 68 90 count++; … … 72 94 return count; 73 95 } 96 97 //Returns the number of times event occurs in this sequence 98 public int eventCount(int event) { 99 int count = 0; 100 for(int i=0;i<sequence.length;i++) { 101 if(sequence[i] == event) { 102 count++; 103 } 104 } 105 return count; 106 } 74 107 75 108 public int size() { 76 109 return sequence.length; 77 110 } 111 112 113 public int getId() { 114 return id; 115 } 116 117 118 public void setId(int id) { 119 this.id = id; 120 } 78 121 } -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWaterman.java
r1612 r1620 265 265 266 266 @Override 267 public ArrayList< ArrayList<NumberSequence>> getMatches() {267 public ArrayList<Match> getMatches() { 268 268 // TODO Auto-generated method stub 269 269 return null; … … 271 271 272 272 @Override 273 public void align( int[] input1, int[]input2, SubstitutionMatrix submat,273 public void align(NumberSequence input1, NumberSequence input2, SubstitutionMatrix submat, 274 274 float threshold) { 275 this.input1 = input1 ;276 this.input2 = input2 ;277 length1 = input1. length;278 length2 = input2. length;275 this.input1 = input1.getSequence(); 276 this.input2 = input2.getSequence(); 277 length1 = input1.size(); 278 length2 = input2.size(); 279 279 this.submat = submat; 280 280 -
branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/SmithWatermanRepeated.java
r1619 r1620 231 231 ns1.setSequence(reversed1); 232 232 ns2.setSequence(reversed2); 233 234 alignment.add(ns1); 235 alignment.add(ns2); 233 ns1.setId(alignment.get(0).getId()); 234 ns2.setId(alignment.get(1).getId()); 235 236 alignment.set(0, ns1); 237 alignment.set(1, ns2); 236 238 } 237 239 … … 272 274 } 273 275 274 public ArrayList< ArrayList<NumberSequence>> getMatches() {275 ArrayList< ArrayList<NumberSequence>> result = new ArrayList<ArrayList<NumberSequence>>();276 public ArrayList<Match> getMatches() { 277 ArrayList<Match> result = new ArrayList<Match>(); 276 278 277 279 //both alignment sequences should be equally long … … 288 290 count++; 289 291 } 290 //I am really missing memcpy here 292 //I am really missing memcpy here? How does one do this better in java? 291 293 int[] tmp1 = new int[count]; 292 294 int[] tmp2 = new int[count]; … … 299 301 tmpns1.setSequence(tmp1); 300 302 tmpns2.setSequence(tmp2); 301 ArrayList<NumberSequence> tmpal = new ArrayList<NumberSequence>(); 302 tmpal.add(tmpns1); 303 tmpal.add(tmpns2); 303 Match tmpal = new Match(); 304 tmpal.setFirstSequence(tmpns1); 305 tmpal.setSecondSequence(tmpns2); 306 tmpal.addOccurence(new MatchOccurence(start,alignment.get(0).getId())); 307 tmpal.addOccurence(new MatchOccurence(start,alignment.get(1).getId())); 304 308 result.add(tmpal); 305 309 } 306 310 i++; 307 311 } 308 309 310 311 312 313 314 312 return result; 315 316 313 } 317 314 … … 354 351 355 352 @Override 356 public void align( int[] input1, int[]input2, SubstitutionMatrix submat,353 public void align(NumberSequence input1, NumberSequence input2, SubstitutionMatrix submat, 357 354 float threshold) { 358 this.input1 = input1; 359 this.input2 = input2; 360 length1 = input1.length; 361 length2 = input2.length; 355 356 alignment = new ArrayList<NumberSequence>(); 357 alignment.add(input1); 358 alignment.add(input2); 359 360 this.input1=input1.getSequence(); 361 this.input2=input2.getSequence(); 362 363 length1 = input1.size(); 364 length2 = input2.size(); 362 365 this.submat = submat; 363 366 … … 367 370 368 371 matrix = new MatrixEntry[length1+2][length2+1]; 369 alignment = new ArrayList<NumberSequence>();372 370 373 371 374 for (int i = 0; i <= length1+1; i++) {
Note: See TracChangeset
for help on using the changeset viewer.