Changeset 1251 for trunk/autoquest-core-usageprofiles/src/main/java/de
- Timestamp:
- 07/12/13 16:45:53 (11 years ago)
- Location:
- trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/DefaultSymbolComparator.java
r1196 r1251 30 30 31 31 /* (non-Javadoc) 32 * @see de.ugoe.cs.autoquest.tasktrees.temporalrelation.SymbolComparator#equals( java.lang.Object, java.lang.Object)32 * @see de.ugoe.cs.autoquest.tasktrees.temporalrelation.SymbolComparator#equals(Object, Object) 33 33 */ 34 34 @Override … … 42 42 } 43 43 44 /* (non-Javadoc) 45 * @see de.ugoe.cs.autoquest.usageprofiles.SymbolComparator#getBucketSearchOrder(Object) 46 */ 47 @Override 48 public int[] getBucketSearchOrder(T symbol) { 49 if (symbol != null) { 50 return new int[] { symbol.hashCode() }; 51 } 52 else { 53 return null; 54 } 55 } 56 44 57 } -
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/SymbolComparator.java
r1196 r1251 39 39 */ 40 40 public boolean equals(T symbol1, T symbol2); 41 42 /** 43 * <p> 44 * returns a search order for buckets. This method can be used for optimizing a search for 45 * equal symbols. The client of this class can store symbols in buckets of similar symbols. 46 * Those buckets get an id denoted by an integer. The most appropriate bucket for a symbol is 47 * the first element in the array returned by this method. The symbol should therefore be put 48 * into that bucket. 49 * </p> 50 * <p> 51 * In case a search for an equal symbol shall be performed at the client side, the client 52 * checks the available buckets in the order given as return value of this method. All other 53 * buckets are searched afterwards. In this scenario it is ensured, that the equal symbol is 54 * found as soon as possible as the search always starts in the most appropriate bucket. 55 * However, the other buckets are searched, as well, if no equal symbol is found. Therefore, 56 * in the worst case, all buckets are searched. In the optimal case, the equal symbol is found 57 * in the first bucket. 58 * </p> 59 * <p> 60 * The returned array should contain different integers in each field. This allows a most 61 * efficient search. If an integer is repeated, it is up to the clien, if this is ignored. 62 * </p> 63 * 64 * @param symbol the symbol for which the bucket order is to be returned 65 * 66 * @return a search order for buckets as described 67 * 68 * @see SymbolMap 69 */ 70 public int[] getBucketSearchOrder(T symbol); 41 71 } -
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/Trie.java
r1189 r1251 17 17 import java.io.Serializable; 18 18 import java.util.Collection; 19 import java.util.HashSet;20 19 import java.util.LinkedHashSet; 21 20 import java.util.LinkedList; … … 55 54 * </p> 56 55 */ 57 private Collection<T> knownSymbols;56 private SymbolMap<T, T> knownSymbols; 58 57 59 58 /** … … 88 87 this.comparator = comparator; 89 88 rootNode = new TrieNode<T>(comparator); 90 knownSymbols = new LinkedHashSet<T>();89 knownSymbols = new SymbolMap<T, T>(this.comparator); 91 90 } 92 91 … … 104 103 } 105 104 rootNode = new TrieNode<T>(other.rootNode); 106 knownSymbols = new LinkedHashSet<T>(other.knownSymbols);105 knownSymbols = new SymbolMap<T, T>(other.knownSymbols); 107 106 comparator = other.comparator; 108 107 } … … 116 115 */ 117 116 public Collection<T> getKnownSymbols() { 118 return new LinkedHashSet<T>(knownSymbols );117 return new LinkedHashSet<T>(knownSymbols.getSymbols()); 119 118 } 120 119 … … 153 152 /** 154 153 * <p> 155 * Adds a given subsequence to the trie and increases the counters accordingly. 154 * Adds a given subsequence to the trie and increases the counters accordingly. NOTE: This 155 * method does not add the symbols to the list of known symbols. This is only ensured using 156 * the method {@link #train(List, int)}. 156 157 * </p> 157 158 * … … 162 163 protected void add(List<T> subsequence) { 163 164 if (subsequence != null && !subsequence.isEmpty()) { 164 addToKnownSymbols(subsequence);165 165 subsequence = new LinkedList<T>(subsequence); // defensive copy! 166 166 T firstSymbol = subsequence.get(0); … … 495 495 */ 496 496 private void addToKnownSymbols(T symbol) { 497 for (T knownSymbol : knownSymbols) { 498 if (comparator.equals(knownSymbol, symbol)) { 499 return; 500 } 501 } 502 503 knownSymbols.add(symbol); 504 } 505 506 /** 507 * <p> 508 * adds a list of new symbols to the collection of known symbols. Uses the 509 * {@link #addToKnownSymbols(Object)} method for each element of the provided list. 510 * </p> 511 * 512 * @param symbols the list of symbols to be added to the known symbols 513 */ 514 private void addToKnownSymbols(List<T> symbols) { 515 for (T symbol : symbols) { 516 addToKnownSymbols(symbol); 497 if (!knownSymbols.containsSymbol(symbol)) { 498 knownSymbols.addSymbol(symbol, symbol); 517 499 } 518 500 } … … 653 635 */ 654 636 public void updateKnownSymbols() { 655 knownSymbols = new HashSet<T>();637 knownSymbols = new SymbolMap<T, T>(this.comparator); 656 638 for (TrieNode<T> node : rootNode.getChildren()) { 657 639 addToKnownSymbols(node.getSymbol()); -
trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieNode.java
r1189 r1251 67 67 * </p> 68 68 */ 69 private Collection<TrieNode<T>> children;70 69 private SymbolMap<T, TrieNode<T>> children; 70 71 71 /** 72 72 * <p> … … 115 115 this.symbol = null; 116 116 count = 0; 117 children = new LinkedList<TrieNode<T>>();117 children = new SymbolMap<T, TrieNode<T>>(this.comparator); 118 118 } 119 119 … … 140 140 141 141 count = 0; 142 children = new LinkedList<TrieNode<T>>();142 children = new SymbolMap<T, TrieNode<T>>(this.comparator); 143 143 } 144 144 … … 157 157 count = other.count; 158 158 comparator = other.comparator; 159 children = new LinkedList<TrieNode<T>>(); 160 for (TrieNode<T> child : other.children) { 161 children.add(new TrieNode<T>(child)); 159 children = new SymbolMap<T, TrieNode<T>>(this.comparator); 160 161 for (TrieNode<T> child : other.children.getValues()) { 162 children.addSymbol(child.getSymbol(), new TrieNode<T>(child)); 162 163 } 163 164 } … … 224 225 if (node == null) { 225 226 node = new TrieNode<T>(symbol, comparator); 226 children.add (node);227 children.addSymbol(symbol, node); 227 228 } 228 229 return node; … … 240 241 */ 241 242 protected TrieNode<T> getChild(T symbol) { 242 for (TrieNode<T> child : children) { 243 if (comparator.equals(child.getSymbol(), symbol)) { 244 return child; 245 } 246 } 247 return null; 243 return children.getValue(symbol); 248 244 } 249 245 … … 256 252 */ 257 253 protected Collection<TrieNode<T>> getChildren() { 258 return children ;254 return children.getValues(); 259 255 } 260 256 … … 296 292 public Collection<T> getFollowingSymbols() { 297 293 Collection<T> followingSymbols = new LinkedList<T>(); 298 for (TrieNode<T> child : children ) {294 for (TrieNode<T> child : children.getValues()) { 299 295 followingSymbols.add(child.getSymbol()); 300 296 } … … 346 342 graph.addChild(new Edge(), parent, currentVertex); 347 343 } 348 for (TrieNode<T> node : children ) {344 for (TrieNode<T> node : children.getValues()) { 349 345 node.getGraph(currentVertex, graph); 350 346 } … … 370 366 stringBuilder.append(" " + hashCode() + " [label=\"" + thisSaneId + "\"];" + 371 367 StringTools.ENDLINE); 372 for (TrieNode<T> childNode : children ) {368 for (TrieNode<T> childNode : children.getValues()) { 373 369 stringBuilder.append(" " + hashCode() + " -> " + childNode.hashCode() + ";" + 374 370 StringTools.ENDLINE); 375 371 } 376 for (TrieNode<T> childNode : children ) {372 for (TrieNode<T> childNode : children.getValues()) { 377 373 childNode.appendDotRepresentation(stringBuilder); 378 374 } … … 412 408 protected void getLeafAncestors(List<TrieNode<T>> ancestors) { 413 409 boolean isAncestor = false; 414 for (TrieNode<T> child : children ) {410 for (TrieNode<T> child : children.getValues()) { 415 411 child.getLeafAncestors(ancestors); 416 412 isAncestor |= child.isLeaf(); … … 431 427 protected int getNumLeafs() { 432 428 int numLeafs = 0; 433 for (TrieNode<T> child : children ) {429 for (TrieNode<T> child : children.getValues()) { 434 430 if (child.isLeaf()) { 435 431 numLeafs++;
Note: See TracChangeset
for help on using the changeset viewer.