Exemple #1
0
int __flann_radius_search(flann_index_t index_ptr,
                          typename Distance::ElementType* query,
                          int* indices,
                          typename Distance::ResultType* dists,
                          int max_nn,
                          float radius,
                          FLANNParameters* flann_params)
{
    typedef typename Distance::ElementType ElementType;
    typedef typename Distance::ResultType DistanceType;

    try {
        init_flann_parameters(flann_params);
        if (index_ptr==NULL) {
            throw FLANNException("Invalid index");
        }
        Index<Distance>* index = (Index<Distance>*)index_ptr;

        Matrix<int> m_indices(indices, 1, max_nn);
        Matrix<DistanceType> m_dists(dists, 1, max_nn);
        SearchParams search_params = create_search_params(flann_params);
        int count = index->radiusSearch(Matrix<ElementType>(query, 1, index->veclen()),
                                        m_indices,
                                        m_dists, radius, search_params );


        return count;
    }
    catch (std::runtime_error& e) {
        Logger::error("Caught exception: %s\n",e.what());
        return -1;
    }
}
Exemple #2
0
int __flann_find_nearest_neighbors_index(flann_index_t index_ptr, typename Distance::ElementType* testset, int tcount,
                                         int* result, typename Distance::ResultType* dists, int nn, FLANNParameters* flann_params)
{
    typedef typename Distance::ElementType ElementType;
    typedef typename Distance::ResultType DistanceType;

    try {
        init_flann_parameters(flann_params);
        if (index_ptr==NULL) {
            throw FLANNException("Invalid index");
        }
        Index<Distance>* index = (Index<Distance>*)index_ptr;

        Matrix<int> m_indices(result,tcount, nn);
        Matrix<DistanceType> m_dists(dists, tcount, nn);

        SearchParams search_params = create_search_params(flann_params);
        index->knnSearch(Matrix<ElementType>(testset, tcount, index->veclen()),
                         m_indices,
                         m_dists, nn, search_params );

        return 0;
    }
    catch (std::runtime_error& e) {
        Logger::error("Caught exception: %s\n",e.what());
        return -1;
    }

    return -1;
}
Exemple #3
0
OP_STATUS ComplementIndexGroup::AddIndex(index_gid_t index_id)
{
	if (m_indexes.Contains(index_id))
		return OpStatus::OK;

	Index* index = m_indexer->GetIndexById(index_id);
	if (index)
	{
		RETURN_IF_ERROR(index->PreFetch());
		
		OpINT32Vector all_messages;
		RETURN_IF_ERROR(m_index->GetAllMessages(all_messages));
		for (UINT32 i = 0; i < all_messages.GetCount(); i++)
		{
			if (index->Contains(all_messages.Get(i)))
			{
				RETURN_IF_ERROR(m_index->RemoveMessage(all_messages.Get(i)));
			}
		}
		
		RETURN_IF_ERROR(m_indexes.Insert(index_id));
		index->AddObserver(this);
	}

	return OpStatus::OK;
}
Exemple #4
0
flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int rows, int cols, float* speedup,
                                  FLANNParameters* flann_params, Distance d = Distance())
{
    typedef typename Distance::ElementType ElementType;
    try {

        init_flann_parameters(flann_params);
        if (flann_params == NULL) {
            throw FLANNException("The flann_params argument must be non-null");
        }
        IndexParams params = create_parameters(flann_params);
        Index<Distance>* index = new Index<Distance>(Matrix<ElementType>(dataset,rows,cols), params, d);
        index->buildIndex();

        if (flann_params->algorithm==FLANN_INDEX_AUTOTUNED) {
            IndexParams params = index->getParameters();
            update_flann_parameters(params,flann_params);
            SearchParams search_params = get_param<SearchParams>(params,"search_params");
            *speedup = get_param<float>(params,"speedup");
            flann_params->checks = search_params.checks;
            flann_params->eps = search_params.eps;
            flann_params->cb_index = get_param<float>(params,"cb_index",0.0);
        }

        return index;
    }
    catch (std::runtime_error& e) {
        Logger::error("Caught exception: %s\n",e.what());
        return NULL;
    }
}
Exemple #5
0
int __flann_find_nearest_neighbors(typename Distance::ElementType* dataset,  int rows, int cols, typename Distance::ElementType* testset, int tcount,
                                   int* result, typename Distance::ResultType* dists, int nn, FLANNParameters* flann_params, Distance d = Distance())
{
    typedef typename Distance::ElementType ElementType;
    typedef typename Distance::ResultType DistanceType;
    try {
        init_flann_parameters(flann_params);

        IndexParams params = create_parameters(flann_params);
        Index<Distance>* index = new Index<Distance>(Matrix<ElementType>(dataset,rows,cols), params, d);
        index->buildIndex();
        Matrix<int> m_indices(result,tcount, nn);
        Matrix<DistanceType> m_dists(dists,tcount, nn);
        SearchParams search_params = create_search_params(flann_params);
        index->knnSearch(Matrix<ElementType>(testset, tcount, index->veclen()),
                         m_indices,
                         m_dists, nn, search_params );
        delete index;
        return 0;
    }
    catch (std::runtime_error& e) {
        Logger::error("Caught exception: %s\n",e.what());
        return -1;
    }

    return -1;
}
Exemple #6
0
bool Slice::loadIndex(Index &index, Buffer &buf)
{
	auto leftSize = _indexFd.fileSize();
	_indexFd.seek(sizeof(SliceIndexHeader), SEEK_SET);
	leftSize -= sizeof(SliceIndexHeader);
	while (leftSize > 0) {
		static uint32_t CHUNK_SIZE = sizeof(IndexEntry) * 100000;
		
		ssize_t readSize = CHUNK_SIZE;
		if (readSize > leftSize)
			readSize = leftSize;
		buf.clear();
		if (_indexFd.read(buf.reserveBuffer(readSize), readSize) != readSize) {
			log::Fatal::L("Can't read data index from sliceID %u\n", _sliceID);
			return false;
		}
		leftSize -= readSize;
		while (buf.readPos() < buf.writtenSize()) {
			IndexEntry &ie = *(IndexEntry*)buf.mapBuffer(sizeof(IndexEntry));
			if (ie.header.status & ST_ITEM_DELETED)
				index.remove(ie.header);
			else
				index.addNoLock(ie);
		}
	}
	return true;
}
Exemple #7
0
bool DB::select(Data *property, Data *tables, Data *qulification) {
    
    cout<<"hello"<<endl;

    Index i = Index();
    block_addr addr = i.getBlock(tables);


    const char * tableName = "x";

    preparePathModelAddr(tableName, addr);
    if (!f.prepareFetchTuple()) // data文件为空
        return 0;

    int numOfAttribute = f.getAttributeNumFromModel(model);
    tuple *p = new tuple[numOfAttribute];

    int numOfResult = 0;
    while (f.fetchTuple(p)) {
        numOfResult++;

        tuple x = p[0];
        int xx = this->ChartoInt(x);
//        char *str = p[1];

        cout << numOfResult << ":" << xx << " " << endl;
        deleteNewAttribute(p, numOfAttribute);
    }

    return true;
}
Exemple #8
0
Index Index::build(DocumentCollection docs) {
    Index index;
    int count = docs.size();
    double avgLen = 0;
    for (auto& doc : docs) {
        for (auto& field : doc.second) {
            string value = field.value;
            for (unsigned i = 0; i < value.length(); i++)
                if (value[i] == ' ' && i != value.length()-1)
                    avgLen++;
            avgLen++;
        }
    }
    avgLen = avgLen / (double)count;

    for (auto& doc : docs) {
        for (auto& field : doc.second) {
            unique_ptr<TokenStream> stream(ArnetAnalyzer::tokenStream(field.value));
            index.addSingle(doc.second.id, 0, stream.get(), avgLen);
        }
    }

    index.optimize();
    return std::move(index);
}
Exemple #9
0
void IndexTestCase::testInt32ForwardIndex()
{
    DocumentSchema schema;
    schema.addSortableField("Int32Id", FieldType::INT32, false);

    const static size_t NUM_DOCS = 1000;
    stringstream ss;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << i << ";";
    }

    GLOBAL_CONF().Build.buildThreadCount = 1;
    buildIndex(schema, ss.str());

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    CPPUNIT_ASSERT(pReader != NULL);
    ForwardIndexIteratorPtr pForIndexIt = pReader->forwardIndexReader("Int32Id");
    CPPUNIT_ASSERT(pForIndexIt != NULL);
    Int32ForwardIndexIteratorPtr pInt32ForIndexIt =
        pForIndexIt.cast<Int32ForwardIndexIterator>();
    CPPUNIT_ASSERT(pInt32ForIndexIt != NULL);
    
    int32_t value = 0;
    docid_t docId = 0;
    for (; docId < (docid_t)NUM_DOCS; ++docId)
    {
        CPPUNIT_ASSERT(pInt32ForIndexIt->seek(docId, value));
        CPPUNIT_ASSERT_EQUAL((int32_t)docId, value);
    }
    CPPUNIT_ASSERT(!pInt32ForIndexIt->seek(docId, value));
}
Exemple #10
0
void IndexTestCase::testRefreshIndexWithMultiBarrel()
{
    DocumentSchema schema;
    schema.addTextField("BODY");
    
    stringstream ss;
    const size_t NUM_DOCS = 1000;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << "body" << i << " hot;";
    }
    buildIndex(schema, ss.str());
    buildIndex(schema, ss.str(), true);

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pIndexReader1 = index.acquireReader();
    checkDocFreq(pIndexReader1, "BODY", "hot", 2 * NUM_DOCS);

    buildIndex(schema, ss.str(), true);
    IndexReaderPtr pIndexReader2 = index.acquireReader(true);
    CPPUNIT_ASSERT(pIndexReader1 != pIndexReader2);
    
    checkDocFreq(pIndexReader2, "BODY", "hot", 3 * NUM_DOCS);
}
Exemple #11
0
void IndexTestCase::testKeywordIndex()
{
    DocumentSchema schema;
    schema.addUnIndexedField("PATH");
    schema.addField("Keyword", "KEYWORD", false);

    buildIndex(schema, "file1.txt, hello world.");

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    CPPUNIT_ASSERT(pReader != NULL);
    TermReaderPtr pTermReader = pReader->termReader();
    CPPUNIT_ASSERT(pTermReader);
    TermIteratorPtr pTermIterator = pTermReader->termIterator("Keyword");
    CPPUNIT_ASSERT(pTermIterator != NULL);

    while (pTermIterator->hasNext())
    {
        TermIterator::TermEntry entry = pTermIterator->next();
        const TermMeta& termMeta = entry.postingIterator->getTermMeta();
        CPPUNIT_ASSERT_EQUAL((df_t)1, termMeta.getDocFreq());
        CPPUNIT_ASSERT_EQUAL((ctf_t)1, termMeta.getCTF());
    }

    Term term("Keyword", "hello world.");
    TermPostingIteratorPtr pPost = pTermReader->seek(&term);
    CPPUNIT_ASSERT(pPost.isNotNull());
    docid_t docId = pPost->skipTo(0);
    CPPUNIT_ASSERT_EQUAL((docid_t)0, docId);
    docId = pPost->skipTo(++docId);
    CPPUNIT_ASSERT_EQUAL((docid_t)INVALID_DOCID, docId);
}
int main()
{
	Index index;
	index.read_dictionary();
	index.debug();
	return 0;
}
int main(void){
	Index idx;
	idx.readFile("dict.dat");
	idx.createIndex("dict.idx");

	return 0;
}
  void
  TensorProductBasis<BASIS0,BASIS1>::reconstruct_1(const Index& lambda,
						   const int j,
						   InfiniteVector<double, Index>& c) const {
    if (lambda.j() >= j) {
      // then we can just copy \psi_\lambda
      c.add_coefficient(lambda, 1.0);
    } else {
      // reconstruct by recursion
      
      typedef typename BASIS0::Index Index0;
      typedef typename BASIS1::Index Index1;
      InfiniteVector<double,Index0> c1;
      InfiniteVector<double,Index1> c2;
      basis0().reconstruct_1(lambda.index0(), lambda.j()+1, c1);
      basis1().reconstruct_1(lambda.index1(), lambda.j()+1, c2);

      for (typename InfiniteVector<double,Index0>::const_iterator it1(c1.begin()), it1end(c1.end());
	   it1 != it1end; ++it1)
	for (typename InfiniteVector<double,Index1>::const_iterator it2(c2.begin()), it2end(c2.end());
	     it2 != it2end; ++it2) {
	  InfiniteVector<double,Index> d;
	  reconstruct_1(Index(it1.index(), it2.index()), j, d);
	  c.add(*it1 * *it2, d);
	}
    }
  }
void IndexContentTestCase::testIndexContent_DL0()
{
    Index* pIndex;
    IndexReaderPtr pReader;

    const Term* pTerm;
    TermIteratorPtr pTermIter;
    int	docCount = 0;
    uint32_t i;
    uint32_t indexTermId;
    string fileName;

    //Check posting list
    Path indexPath = TestHelper::getTestDataPath();
    indexPath.makeDirectory();
    indexPath.pushDirectory(_T("test_dl0index"));    
    pIndex = new Index(indexPath.toString().c_str(), Index::READ, NULL);
    auto_ptr<Index> indexPtr(pIndex);
    pReader = pIndex->acquireReader();
    TermReaderPtr pTermReader = pReader->termReader();

    pTermIter = pTermReader->termIterator("BODY");

    StoredFieldsReaderPtr pDocReader = pReader->createStoredFieldsReader();
    //Iterator all terms
    while(pTermIter->next())
    {
        pTerm = pTermIter->term();

        CPPUNIT_ASSERT(pTermReader->seek(pTerm));
		
        indexTermId = (pTerm->cast<int32_t>())->getValue();
        TermPostingIteratorPtr pTermDocFreqs = pTermReader->termPostings();
        docCount = 0;

        while(pTermDocFreqs->nextDoc())
        {
            DocumentPtr pDoc = pDocReader->document(pTermDocFreqs->doc());
            docCount++;

            // 获取文件路径
            fileName.assign(pDoc->getField("PATH")->getValue().c_str());

            TermList* pTermIdList = m_pDocScanner->getTermListOfFile(fileName);
            CPPUNIT_ASSERT(pTermIdList != NULL);//存在该文件
            for(i = 0; i < pTermIdList->getSize(); i++)
            {
                if(indexTermId == pTermIdList->getValue(i))
                {
                    break;
                }
            }
            CPPUNIT_ASSERT(i < pTermIdList->getSize());//源文档中是否存在该词
        }//end while nextDoc()
        CPPUNIT_ASSERT_EQUAL((df_t)docCount, pTermDocFreqs->getDocFreq());//测DF
    }
    CPPUNIT_ASSERT_EQUAL((int64_t)m_pDocScanner->getTotalTermCount(), 
                         pReader->getNumTerms());//CTF
}
void FittingLayer::markFigureKeyUnselected(const FigureKey& figureKey)
{
	Index index = figureKeyToIndex(figureKey);
	if (index.isValid()) 
	{
		getChosenSymbol(index)->setVisible(false);	
	}
}
Exemple #17
0
 friend inline bool  operator<= ( const Index& id0, const Index& id1 )
 {
     if ( id0.isInvalid() || id1.isInvalid() )
     {
         return false;
     }
     return ( id0.m_idx <= id1.m_idx );
 }
Exemple #18
0
void ExtToMime::Refresh()
{
	major.Clear();
	minor.Clear();
	map.Clear();
	Load("/usr/local/share/mime/globs");
	Load("/usr/share/mime/globs");
}
Exemple #19
0
void IndexDict::makeTolerantIndexFromList(list<Document *> doclist, int k) {
	
	
	if(_ctwf)
		makeFuzzyIndexFromList(doclist);
	else
		makeIndexFromList(doclist);

	_k = k;


	cout << "computing kgram index ...\n";
	map< Index, list<Posting> >::iterator iterT = _dict.begin();
	for(iterT; iterT != _dict.end(); iterT++)
	{
		Index t = iterT->first;
		string token = t.getToken();
		int len = token.length();

		if(len < k)
		{
			
			_kgrams[token].push_back(token);
		}
		else
		{
			string kgram = token.substr(0, k-1);
			_kgrams[kgram].push_back(token);
			for(int i = 0; i < (len - k + 1); i++)
			{
				kgram = token.substr(i, k);
				_kgrams[kgram].push_back(token);
			}
			kgram = token.substr(len - k + 1);
			_kgrams[kgram].push_back(token);
		}
	}
	cout << "done!\n";

	
	map<string, list<string> >::iterator iter = _kgrams.begin();
	for(int i = 0; i < 100; i++)
		iter++;

	for(int i = 0; i < 5; i++)
	{
		cout << iter->first << " ====>> ";
		list<string>::iterator str = iter->second.begin();
		for(str; str != iter->second.end(); str++)
		{
			cout << *str << " -> ";
		}
		cout << endl << endl;
		iter++;
	}
	

}
Exemple #20
0
inline Vector getIndexVectorFromIndex(
    const Index& index,
    const Size& bufferSize,
    const Index& bufferStartIndex)
{
  Index unwrappedIndex;
  unwrappedIndex = getIndexFromBufferIndex(index, bufferSize, bufferStartIndex);
  return (getBufferOrderToMapFrameTransformation() * unwrappedIndex.matrix()).cast<double>();
}
Exemple #21
0
static bool sIsEqual(const Index<Value>& a, const Index<Value>& b)
{
	if(&a == &b) return true;
	if(a.GetCount() != b.GetCount()) return false;
	for(int i = 0; i < a.GetCount(); i++) {
		if(a[i] != b[i]) return false;
	}
	return true;
}
 int 
 CachedQuarkletProblem<PROBLEM>::number (const Index& lambda, const int jmax) const{
     
     WaveletBasis mybasis(basis());
     const int waveletsonzerolevel = (mybasis.last_wavelet(jmax)).number()+1;
     const int waveletsonplevel = ((mybasis.last_wavelet(jmax,lambda.p())).number()+1);
     const int lambda_num = (lambda.p()==0) ? lambda.number() : lambda.number() + (lambda.p()-1) * waveletsonplevel + waveletsonzerolevel;
     return lambda_num;
 }
Exemple #23
0
void IndexTestCase::testInt32_IF()
{
    DocumentSchema schema;
    schema.addField("Int32", "INT32_IF", false);

    const static size_t NUM_DOCS = 1000;
    stringstream ss;
    for (size_t i = 0; i < NUM_DOCS; ++i)
    {
        ss << (i % 100) << ";";
    }

    GLOBAL_CONF().Build.buildThreadCount = 1;
    buildIndex(schema, ss.str());

    tstring str = getTestPath();
    Index index;
    index.open(str, Index::READ, NULL);
    IndexReaderPtr pReader = index.acquireReader();
    CPPUNIT_ASSERT(pReader != NULL);
    TermReaderPtr pTermReader = pReader->termReader();
    CPPUNIT_ASSERT(pTermReader);
    TermIteratorPtr pTermIterator = pTermReader->termIterator("Int32");
    CPPUNIT_ASSERT(pTermIterator != NULL);

    while (pTermIterator->hasNext())
    {
        TermIterator::TermEntry entry = pTermIterator->next();
        const TermMeta& termMeta = entry.postingIterator->getTermMeta();
        CPPUNIT_ASSERT_EQUAL((df_t)10, termMeta.getDocFreq());
        CPPUNIT_ASSERT_EQUAL((ctf_t)10, termMeta.getCTF());
    }

    Term term("Int32", "0");
    TermPostingIteratorPtr pPost = pTermReader->seek(&term);
    CPPUNIT_ASSERT(pPost);
    docid_t docId = pPost->skipTo(0);
    CPPUNIT_ASSERT_EQUAL((docid_t)0, docId);
    docId = pPost->skipTo(901);
    CPPUNIT_ASSERT_EQUAL((docid_t)INVALID_DOCID, docId);

    ForwardIndexIteratorPtr pForIndexIt = pReader->forwardIndexReader("Int32");
    CPPUNIT_ASSERT(pForIndexIt != NULL);
    Int32ForwardIndexIteratorPtr pInt32ForIndexIt =
        pForIndexIt.cast<Int32ForwardIndexIterator>();
    CPPUNIT_ASSERT(pInt32ForIndexIt != NULL);
    
    int32_t value = 0;
    docId = 0;
    for (; docId < (docid_t)NUM_DOCS; ++docId)
    {
        CPPUNIT_ASSERT(pInt32ForIndexIt->seek(docId, value));
        CPPUNIT_ASSERT_EQUAL((int32_t)(docId % 100), value);
    }
    CPPUNIT_ASSERT(!pInt32ForIndexIt->seek(docId, value));
}
DesktopDragObject::InsertType AccessTreeViewListener::GetIndexInsertType(index_gid_t dest, DesktopDragObject::InsertType suggested)
{
	Index* index = g_m2_engine->GetIndexById(dest);
	AccessModel* model = static_cast<AccessModel*>(m_treeview.GetTreeModel());
	
	if (suggested == DesktopDragObject::INSERT_INTO && index && index->GetType() != IndexTypes::UNIONGROUP_INDEX && model->GetCategoryID() != IndexTypes::CATEGORY_LABELS)
		return DesktopDragObject::INSERT_AFTER;

	return suggested;
}
Exemple #25
0
Vector<String> HelpTopicEnumDeclModules()
{
	Index<String> modmap;
	const HelpTopicInfoMap& map = HelpTopicMap();
	for(int i = 0; i < map.GetCount(); i++)
		modmap.FindAdd(map[i].decl_module);
	Vector<String> mm = modmap.PickKeys();
	Sort(mm, StdLess<String>());
	return mm;
}
Exemple #26
0
void HistogramND::GetRange(const Index& bucket,Point& min,Point& max) const
{
  Assert(bucket.size()==divs.size());
  min.resize(bucket.size());
  max.resize(bucket.size());
  for(size_t i=0;i<divs.size();i++) {
    min[i]=(bucket[i] == 0? -Inf: divs[i][bucket[i]-1]);
    max[i]=(bucket[i] == divs[i].size()+1? Inf : divs[i][bucket[i]]);
  }
}
Exemple #27
0
        void clearData()
        {
            for (std::vector<Index*>::iterator iit = usedIndices.begin();
                        iit != usedIndices.end(); iit++) {
                Index *idx = *iit;
                idx->clearData();
            }

            PlotManager::instance().redraw(false);
        }
Exemple #28
0
 IndexedButton * Manager::findButton( const std::string & elementIndex , int player )
 {
     Index * i = fetchIndex( player );
     if( i )
     {
         return i->getButton( elementIndex );
     }
     
     return 0;
 }
Exemple #29
0
PropertiesInfo::PropertiesInfo(const Index& index,
                               Context ctx,
                               ClassAnalysis* cls)
  : m_cls(cls)
{
  if (m_cls == nullptr && ctx.cls != nullptr) {
    m_privateProperties = index.lookup_private_props(ctx.cls);
    m_privateStatics    = index.lookup_private_statics(ctx.cls);
  }
}
Exemple #30
0
 IndexedAxis * Manager::findAxis( const std::string & elementIndex , int player )
 {
     Index * i = fetchIndex( player );
     if( i )
     {
         return i->getAxis( elementIndex );
     }
     
     return 0;
 }