/** * Checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey(Object key) { return _map.containsKey(unwrapKey(key)); }
public void topicXMLReport (PrintWriter out, int numWords) { out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); TreeSet<IDSorter> sortedWords = new TreeSet<IDSorter>(); for (int type = 0; type < numTypes; type++) { if (typeTopicCounts[type].containsKey(topic)) { sortedWords.add(new IDSorter(type, typeTopicCounts[type].get(topic))); } } int word = 1; Iterator<IDSorter> iterator = sortedWords.iterator(); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + word + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); word++; } out.println(" </topic>"); } out.println("</topicModel>"); }
public void topicXMLReport (PrintWriter out, int numWords) { out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); TreeSet<IDSorter> sortedWords = new TreeSet<IDSorter>(); for (int type = 0; type < numTypes; type++) { if (typeTopicCounts[type].containsKey(topic)) { sortedWords.add(new IDSorter(type, typeTopicCounts[type].get(topic))); } } int word = 1; Iterator<IDSorter> iterator = sortedWords.iterator(); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + word + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); word++; } out.println(" </topic>"); } out.println("</topicModel>"); }
public void topicXMLReport (PrintWriter out, int numWords) { out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); TreeSet<IDSorter> sortedWords = new TreeSet<IDSorter>(); for (int type = 0; type < numTypes; type++) { if (typeTopicCounts[type].containsKey(topic)) { sortedWords.add(new IDSorter(type, typeTopicCounts[type].get(topic))); } } int word = 1; Iterator<IDSorter> iterator = sortedWords.iterator(); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + word + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); word++; } out.println(" </topic>"); } out.println("</topicModel>"); }
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
/** * Returns a unique numeric index for a variable in this model. * Every UndirectedModel <tt>mdl</tt> maintains a mapping between its * variables and the integers 0...size(mdl)-1 , which is suitable * for caching the variables in an array. * <p> * <tt>getIndex</tt> and <tt>get</tt> are inverses. That is, if * <tt>idx == getIndex (var)</tt>, then <tt>get(idx)</tt> will * return <tt>var</tt>. * @param var A variable contained in this graphical model * @return The numeric index of var * @see #get(int) */ public int getIndex (Variable var) { int idx = var.getIndex(); if (projectionMap.containsKey(idx)) { return projectionMap.get(idx); } else { return -1; } }
/** * Returns a unique numeric index for a variable in this model. * Every UndirectedModel <tt>mdl</tt> maintains a mapping between its * variables and the integers 0...size(mdl)-1 , which is suitable * for caching the variables in an array. * <p> * <tt>getIndex</tt> and <tt>get</tt> are inverses. That is, if * <tt>idx == getIndex (var)</tt>, then <tt>get(idx)</tt> will * return <tt>var</tt>. * @param var A variable contained in this graphical model * @return The numeric index of var * @see #get(int) */ public int getIndex (Variable var) { int idx = var.getIndex(); if (projectionMap.containsKey(idx)) { return projectionMap.get(idx); } else { return -1; } }
/** * Returns a unique numeric index for a variable in this model. * Every UndirectedModel <tt>mdl</tt> maintains a mapping between its * variables and the integers 0...size(mdl)-1 , which is suitable * for caching the variables in an array. * <p> * <tt>getIndex</tt> and <tt>get</tt> are inverses. That is, if * <tt>idx == getIndex (var)</tt>, then <tt>get(idx)</tt> will * return <tt>var</tt>. * @param var A variable contained in this graphical model * @return The numeric index of var * @see #get(int) */ public int getIndex (Variable var) { int idx = var.getIndex(); if (projectionMap.containsKey(idx)) { return projectionMap.get(idx); } else { return -1; } }
public final void plusEqualsSparse(SparseVector v, double factor) { if (indices.length == 0) return; if (index2location == null) setIndex2Location(); Lock lock = this.lock.readLock(); lock.lock(); try { int vNumLocs = v.numLocations(); for (int i = 0; i < vNumLocs; i++) { int index = v.indexAtLocation(i); if (index > maxIndex) break; if (index2location.containsKey(index)) { values[index2location.get(index)] += v.valueAtLocation(i) * factor; } //int location = index2location.get(index); //if (location >= 0) // values[location] += v.valueAtLocation (i) * factor; } } finally { lock.unlock(); } }
/** {@inheritDoc} */ @Override public DocumentIndexEntry getDocumentEntry(int docid) { //BasicDocumentIndexEntry die = new BasicDocumentIndexEntry(); // refactored by Dyaa NonIncrementalDocumentIndexEntry die = new NonIncrementalDocumentIndexEntry(); int diedocid= -1; if(docids2lengths.containsKey(docid)) diedocid = docid; die.setDocid(diedocid); die.setDocumentLength(docids2lengths.get(docid)); return die; }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }
public void preProcess(FeatureVector fv) { cache.resetQuick(); int fi; for (int loc = 0; loc < fv.numLocations(); loc++) { fi = fv.indexAtLocation(loc); if (constraintsMap.containsKey(fi)) { cache.add(constraintsMap.get(fi)); } } }
/** * Retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or null if no such mapping exists. */ public Object get(Object key) { int k = unwrapKey(key); int v = _map.get(k); // 0 may be a false positive since primitive maps // cannot return null, so we have to do an extra // check here. if (v == 0) { return _map.containsKey(k) ? wrapValue(v) : null; } else { return wrapValue(v); } }
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { IIntIterator featIt = _featuresDB.getFeatures(); int length = 0; while (featIt.hasNext()) { int feature = featIt.next(); int pos = _featuresDocuments.get(feature) .binarySearch(document); if (pos >= 0) length += _featuresFrequencies.get(feature).getQuick(pos); } _documentLenghts.put(document, length); return length; } }
public final void plusEqualsSparse (SparseVector v, double factor) { if (indices.length == 0) return; if (index2location == null) setIndex2Location (); int vNumLocs = v.numLocations(); for (int i = 0; i < vNumLocs; i++) { int index = v.indexAtLocation(i); if (index > maxIndex) break; if (index2location.containsKey(index)) { values[ index2location.get(index) ] += v.valueAtLocation (i) * factor; } //int location = index2location.get(index); //if (location >= 0) // values[location] += v.valueAtLocation (i) * factor; } }
public final void plusEqualsSparse (SparseVector v, double factor) { if (indices.length == 0) return; if (index2location == null) setIndex2Location (); int vNumLocs = v.numLocations(); for (int i = 0; i < vNumLocs; i++) { int index = v.indexAtLocation(i); if (index > maxIndex) break; if (index2location.containsKey(index)) { values[ index2location.get(index) ] += v.valueAtLocation (i) * factor; } //int location = index2location.get(index); //if (location >= 0) // values[location] += v.valueAtLocation (i) * factor; } }
public int getFeatureDocumentsCount(int feature) { if (_featureDocumentsCount.containsKey(feature)) return _featureDocumentsCount.get(feature); else { IIntIterator docIt = _documentsDB.getDocuments(); int count = 0; while (docIt.hasNext()) { if (hasDocumentFeature(docIt.next(), feature)) ++count; } _featureDocumentsCount.put(feature, count); return count; } }
public int getDocumentFeaturesCount(int document) { if (_documentFeaturesCount.containsKey(document)) return _documentFeaturesCount.get(document); else { IIntIterator featIt = _featuresDB.getFeatures(); int count = 0; while (featIt.hasNext()) { if (hasDocumentFeature(document, featIt.next())) ++count; } _documentFeaturesCount.put(document, count); return count; } }