/** * Reads events from <tt>eventStream</tt> into a linked list. The predicates associated with each * event are counted and any which occur at least <tt>cutoff</tt> times are added to the * <tt>predicatesInOut</tt> map along with a unique integer index. * * @param eventStream an <code>EventStream</code> value * @param eventStore a writer to which the events are written to for later processing. * @param predicatesInOut a <code>TObjectIntHashMap</code> value * @param cutoff an <code>int</code> value */ private int computeEventCounts( EventStream eventStream, Writer eventStore, TObjectIntHashMap predicatesInOut, int cutoff) throws IOException { TObjectIntHashMap counter = new TObjectIntHashMap(); int predicateIndex = 0; int eventCount = 0; while (eventStream.hasNext()) { Event ev = eventStream.nextEvent(); eventCount++; eventStore.write(FileEventStream.toLine(ev)); String[] ec = ev.getContext(); for (int j = 0; j < ec.length; j++) { if (!predicatesInOut.containsKey(ec[j])) { if (counter.increment(ec[j])) { } else { counter.put(ec[j], 1); } if (counter.get(ec[j]) >= cutoff) { predicatesInOut.put(ec[j], predicateIndex++); counter.remove(ec[j]); } } } } predicatesInOut.trimToSize(); eventStore.close(); return eventCount; }
private static int getAttributeId(String attId) throws IOException { if (myAttributeIds.containsKey(attId)) { return myAttributeIds.get(attId); } int id = myNames.enumerate(attId); myAttributeIds.put(attId, id); return id; }
private List index(int numEvents, EventStream es, TObjectIntHashMap predicateIndex) { TObjectIntHashMap omap = new TObjectIntHashMap(); int outcomeCount = 0; List eventsToCompare = new ArrayList(numEvents); TIntArrayList indexedContext = new TIntArrayList(); while (es.hasNext()) { Event ev = es.nextEvent(); String[] econtext = ev.getContext(); ComparableEvent ce; int ocID; String oc = ev.getOutcome(); if (omap.containsKey(oc)) { ocID = omap.get(oc); } else { ocID = outcomeCount++; omap.put(oc, ocID); } for (int i = 0; i < econtext.length; i++) { String pred = econtext[i]; if (predicateIndex.containsKey(pred)) { indexedContext.add(predicateIndex.get(pred)); } } // drop events with no active features if (indexedContext.size() > 0) { ce = new ComparableEvent(ocID, indexedContext.toNativeArray()); eventsToCompare.add(ce); } else { System.err.println( "Dropped event " + ev.getOutcome() + ":" + Arrays.asList(ev.getContext())); } // recycle the TIntArrayList indexedContext.resetQuick(); } outcomeLabels = toIndexedStringArray(omap); predLabels = toIndexedStringArray(predicateIndex); return eventsToCompare; }
@Override public int compare(Object o1, Object o2) { if (WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) { return WEIGHTS.get(o1) - WEIGHTS.get(o2); } else if (WEIGHTS.containsKey(o1) && !WEIGHTS.containsKey(o2)) { return -1; } else if (!WEIGHTS.containsKey(o1) && WEIGHTS.containsKey(o2)) { return 1; } else { return o1.hashCode() - o2.hashCode(); } }
public boolean isInLexicon(String str) { if (lexicon == null || str == null) return false; return lexicon.containsKey(str); }
public boolean isPresentInString2(String str) { return string2Present.containsKey(str); }