int Dictionary::get_document_index (ustring dictionaryname) { DocMap::iterator dm = m_document_map.find(dictionaryname); int dindex; if (dm == m_document_map.end()) { dindex = m_documents.size(); m_document_map[dictionaryname] = dindex; pugi::xml_document *doc = new pugi::xml_document; m_documents.push_back (doc); pugi::xml_parse_result parse_result; if (boost::ends_with (dictionaryname.string(), ".xml")) { // xml file -- read it parse_result = doc->load_file (dictionaryname.c_str()); } else { // load xml directly from the string parse_result = doc->load_buffer (dictionaryname.c_str(), dictionaryname.length()); } if (! parse_result) { m_context->error ("XML parsed with errors: %s, at offset %d", parse_result.description(), parse_result.offset); m_document_map[dictionaryname] = -1; return -1; } } else { dindex = dm->second; } DASSERT (dindex < (int)m_documents.size()); return dindex; }
Document::UP read(DocumentIdT lid, const document::DocumentTypeRepo &) const override { DocMap::const_iterator itr = _docs.find(lid); if (itr != _docs.end()) { Document::UP retval(itr->second->clone()); return retval; } return Document::UP(); }
int findTheDot(QueryMap q_obj, DocMap w) { int dot=0; for (QueryMap::iterator l=q_obj.begin(); l != q_obj.end(); ++l) for (DocMap::iterator p = w.begin(); p != w.end(); ++p) if (l->first == p->first) dot+=dotprod(l->second, p->second); return dot; }
Doc* DocSet::findOrMakeDoc(const std::string& doc) { DocMap::iterator it = docMap_.find(doc); if (it != docMap_.end()) { return it->second; } Doc* newDoc = new Doc(NULL); docMap_[doc] = newDoc; return newDoc; }
void remove(uint64_t syncToken, DocumentIdT lid) override { _lastSyncToken = syncToken; _docs.erase(lid); }
void DocSet::produceClusters(DocSet::ClusterMap& outClusters) { for (DocMap::iterator it = docMap_.begin(); it != docMap_.end(); ++it) { Doc* rep = it->second->findRep(); outClusters[rep].push_back(it->first); } }
float Doc_mod(DocMap w) { float store=0; for (DocMap::iterator p = w.begin(); p != w.end(); ++p) store+=(p->second*p->second); return sqrt(store); }