Changeset 1718 for branches/autoquest-core-tasktrees-alignment/src
- Timestamp:
- 09/03/14 10:13:25 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1717 r1718 15 15 package de.ugoe.cs.autoquest.tasktrees.temporalrelation; 16 16 17 import java.io.File; 17 18 import java.io.FileInputStream; 18 19 import java.io.FileOutputStream; … … 77 78 78 79 79 public static int nThreads;80 public static boolean harmonizeSequences;81 public static boolean loadSubstutionMatrix;82 83 80 84 81 private int iteration = 0; … … 193 190 public RuleApplicationResult apply(List<IUserSession> sessions) { 194 191 RuleApplicationData appData = new RuleApplicationData(sessions); 195 if(SequenceForTaskDetectionRuleAlignment.harmonizeSequences) { 192 File harmonized = new File("harmonized.dat"); 193 if(harmonized.exists() && !harmonized.isDirectory()) { 194 Console.traceln(Level.INFO,"loading harmonized sessions from file"); 195 appData = loadAppData("harmonized"); 196 } 197 else { 196 198 //appData.getStopWatch().start("harmonization"); 197 199 harmonizeEventTaskInstancesModel(appData); … … 202 204 saveAppData("harmonized"); 203 205 } 204 else { 205 Console.traceln(Level.INFO,"loading harmonized sessions from file"); 206 appData = loadAppData("harmonized"); 207 } 208 System.out.println(SequenceForTaskDetectionRuleAlignment.loadSubstutionMatrix); 209 if(!SequenceForTaskDetectionRuleAlignment.loadSubstutionMatrix) { 206 207 File substitution = new File("substitution.dat"); 208 if(!(substitution.exists() && !substitution.isDirectory())) { 210 209 Console.traceln(Level.INFO, "generating substitution matrix from " + appData.getUniqueTasks().size() + " unique tasks"); 211 210 appData.getStopWatch().start("substitution matrix"); … … 651 650 // Generate pairwise alignments 652 651 int size = appData.getNumberSequences().size(); 653 Console.traceln(Level.INFO, "generating pairwise alignments"); 654 LinkedList<Match> matchseqs = new LinkedList<Match>(); 652 Console.traceln(Level.INFO, "generating pairwise alignments from " + size + " sessions"); 655 653 int count = 0; 656 654 657 for (int i = 0; i < appData.getNumberSequences().size(); i++) { 658 NumberSequence ns1 = appData.getNumberSequences().get(i); 659 count++; 660 // if((count%(size/100)==0)) { 661 // Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 662 // } 663 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 664 NumberSequence ns2 = appData.getNumberSequences().get(j); 665 if (i != j) { 666 //Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); 667 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 668 aa.align(ns1, ns2, appData.getSubmat(),9); 669 matchseqs.addAll(aa.getMatches()); 670 } 671 } 672 } 673 GlobalDataContainer.getInstance().addData("aligned", matchseqs); 674 saveAppData("aligned"); 655 //Checking if i have an already calculated file result of this action in the working directory 656 File aligned = new File("aligned" + iteration + ".dat"); 657 if(!(aligned.exists() && !aligned.isDirectory())) { 658 appData.matchseqs = new LinkedList<Match>(); 659 System.out.println(appData.matchseqs); 660 for (int i = 0; i < appData.getNumberSequences().size(); i++) { 661 NumberSequence ns1 = appData.getNumberSequences().get(i); 662 count++; 663 664 //Print out the progress 665 if(size>100) { 666 if((count%(size/100)==0)) { 667 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 668 } 669 } 670 else { 671 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 672 } 673 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 674 NumberSequence ns2 = appData.getNumberSequences().get(j); 675 if (i != j) { 676 //Console.traceln(Level.FINEST,"Aligning sequence " + i + " with sequence " + j); 677 AlignmentAlgorithm aa = AlignmentAlgorithmFactory.create(); 678 aa.align(ns1, ns2, appData.getSubmat(),9); 679 appData.getMatchseqs().addAll(aa.getMatches()); 680 } 681 } 682 } 683 GlobalDataContainer.getInstance().addData("aligned" + iteration, appData); 684 saveAppData("aligned" + iteration); 685 } 686 else { 687 Console.traceln(Level.INFO,"loading matches from file"); 688 appData = loadAppData("aligned"+iteration); 689 } 690 675 691 676 692 Console.traceln(Level.INFO, "searching for patterns occuring most"); 677 693 678 694 // search each match in every other sequence 679 for (Iterator<Match> it = matchseqs.iterator(); it.hasNext();) {695 for (Iterator<Match> it = appData.getMatchseqs().iterator(); it.hasNext();) { 680 696 Match pattern = it.next(); 681 697 682 698 // Skip sequences with more 0 events (scrolls) than other events. 683 699 // Both of the pattern sequences are equally long, so the zero … … 711 727 } 712 728 }; 713 Collections.sort( matchseqs, comparator);729 Collections.sort(appData.getMatchseqs(), comparator); 714 730 appData.getStopWatch().stop("detecting tasks"); 715 731 … … 717 733 HashMap<Integer, List<MatchOccurence>> replacedOccurences = new HashMap<Integer, List<MatchOccurence>>(); 718 734 // Replace matches in the sessions 719 for (int i = 0; i < matchseqs.size(); i++) { 735 for (int i = 0; i < appData.getMatchseqs().size(); i++) { 736 720 737 // Every pattern consists of 2 sequences, therefore the minimum 721 738 // occurrences here is 2. 722 739 // We just need the sequences also occurring in other sequences as 723 740 // well 724 if (matchseqs.get(i).occurenceCount() > 2) { 725 741 if (appData.getMatchseqs().get(i).occurenceCount() > 2) { 726 742 appData.detectedAndReplacedTasks = true; 727 ISequence task = matchAsSequence(appData, matchseqs.get(i));728 invalidOccurence: for (Iterator<MatchOccurence> it = matchseqs743 ISequence task = matchAsSequence(appData, appData.getMatchseqs().get(i)); 744 invalidOccurence: for (Iterator<MatchOccurence> it = appData.getMatchseqs() 729 745 .get(i).getOccurences().iterator(); it.hasNext();) { 730 746 MatchOccurence oc = it.next(); 731 747 732 748 /* 733 if (iteration > 1) {749 if (iteration > 0) { 734 750 735 751 System.out.println("Trying to replace sequence: "); 736 matchseqs.get(i).getFirstSequence().printSequence();737 matchseqs.get(i).getSecondSequence().printSequence();752 appData.getMatchseqs().get(i).getFirstSequence().printSequence(); 753 appData.getMatchseqs().get(i).getSecondSequence().printSequence(); 738 754 System.out.println(" in session number: " 739 755 + (oc.getSequenceId() + 1) + " at position " … … 808 824 } 809 825 } 810 matchseqs = null;826 appData.setMatchseqs(null); 811 827 appData.getStopWatch().stop("replacing tasks"); 812 828 } … … 828 844 829 845 ObjectDistanceSubstitionMatrix submat; 830 831 846 847 LinkedList<Match> matchseqs; 848 832 849 private ArrayList<NumberSequence> numberseqs; 833 850 … … 868 885 } 869 886 887 public LinkedList<Match> getMatchseqs() { 888 return matchseqs; 889 } 890 891 public void setMatchseqs(LinkedList<Match> matchseqs) { 892 this.matchseqs = matchseqs; 893 } 894 870 895 private ObjectDistanceSubstitionMatrix getSubmat() { 871 896 return submat; … … 907 932 908 933 934 909 935 /** 910 936 *
Note: See TracChangeset
for help on using the changeset viewer.