/// <summary> /// Standardowy konstruktor /// </summary> /// <param name="workingDirPath">Ścieżka do katalogu z danymi HAL</param> /// <param name="fwdIndex">Indeks wprzód (używany w trybie IxHalCalculationMode.CALCULATE_HAL_ON_DEMAND, inaczej /// może być null)</param> /// <param name="invIndex">Odwrócony indeks (używany w trybie IxHalCalculationMode.CALCULATE_HAL_ON_DEMAND, inaczej /// może być null)</param> public IxHalContextObtainer(string workingDirPath, IxStdDiskFwdIndex fwdIndex, IxStdDiskRIIndex invIndex) { switch (IxSettings.halSearchMode) { case IxHalCalculationMode.CALCULATE_HAL_ON_DEMAND: halContextOnDemandComputer = new IxHalOnDemCtxComp(workingDirPath, invIndex, fwdIndex); break; case IxHalCalculationMode.CALCULATE_CONTEXT_ON_PREPARED_HAL: halContextComputer = new IxHalCtxComp(workingDirPath); break; case IxHalCalculationMode.USE_PRECALCULATED_CONTEXT: halContext = new IxHalContext(workingDirPath, IxHalContext.Mode.READ); break; default: throw new NotImplementedException(); break; } }
/// <summary> /// Przeprowadza proces indeksowania. /// /// Ewentualny rzucony wyjątek zostanie wypisany na konsolę bez /// dalszych akcji. Metody należy użyć raz, po wskazaniu indeksera i crawlera /// (setCrawler(), setIndexer()). /// </summary> public void DoIndexing() { if (indexer == null) throw new Exception("IndyxLib.IxCreator: indexer is not initialized"); if (crawler == null) throw new Exception("IndyxLib.IxCreator: crawler is not initialized"); try { indexer.setCrawler(crawler); indexer.createIndex(); indexer.finalize(); //tworzymy pliki z pozycjami tokenów w dokumentach //FwdIndex (podajemy id dokumentu, dostajemy uszeregowaną liste id tokenow wystepujacych w dokumencie) IxStdDiskFwdIndex fwdIndex = new IxStdDiskFwdIndex(pathToIndex + @"\fwdIndex", IxIndexMode.READ); IxTokenPositionsIndex index = new IxTokenPositionsIndex(pathToIndex); index.Create(fwdIndex); } catch (IxException ex) { Console.WriteLine(ex); } }
/// <summary> /// Standardowy konstruktor /// </summary> /// <param name="workingDirPath">Ścieżka do katalogu zawierającego (lub mającego zawierać) plik danych kontekstów na żądanie /// </param> /// <param name="bkdIndex">Odwrócony indeks</param> /// <param name="fwdIndex">Indeks wprzód</param> public IxHalOnDemCtxComp(string workingDirPath, IIxIndex bkdIndex, IxStdDiskFwdIndex fwdIndex) { workingDirPath = Misc.provideEndBackslash(workingDirPath); Misc.provideDirectory(workingDirPath); dataFilePath = workingDirPath + "halContextOnDemand.dat"; this.invIndex = bkdIndex; this.fwdIndex = fwdIndex; if (File.Exists(dataFilePath)) loadNearestFromFile(dataFilePath); }
public void Create(IxStdDiskFwdIndex fwdIndex) { Console.WriteLine("Rozpoczynam tworzenie plików z pozycjami tokenów..."); if (Directory.Exists(_pathToPositionsLocation)) { throw new Exception("Folder positions istnieje!"); } //tworzymy sciezke w folderze z indexem dla plikow z polozeniem tokenow w dokumentach Directory.CreateDirectory(_pathToPositionsLocation); //tworzymy plik z indexem pozycji i danymi pozycji _positionsDataWriter = new BinaryWriter(File.Create(_pathToPositionsLocation + "\\positions.dat"), Encoding.UTF8); _positionsIndexWriter = new BinaryWriter(File.Create(_pathToPositionsLocation + "\\positions.idx"), Encoding.UTF8); //ponieważ podczas implementacji klasy IxStdDiskFwdIndex autor nie przewidział możliwości //pobrania wszystkich dokumentów, musimy pobierać je tak długo, aż dostaniemy exception uint docId = 0; long dataCount = 0; while (true) { docId++; try { dataCount += SaveTokensPositionsIntoDataFile(GetTokens(fwdIndex, docId)); if (docId == 1) { _positionsIndexWriter.Write((long)0); _positionsIndexWriter.Write(dataCount); } else { _positionsIndexWriter.Write(dataCount); } } catch (ArgumentOutOfRangeException e) { break; } } _positionsDataWriter.Flush(); _positionsDataWriter.Close(); _positionsIndexWriter.Flush(); _positionsIndexWriter.Close(); }
static void Main(string[] args) { IxStdDiskFwdIndex fwdIndex = new IxStdDiskFwdIndex(@"D:\indexes\enwiki\fwdIndex", IxIndexMode.READ); IxFwdDistDiskDict fwdDict = new IxFwdDistDiskDict(@"D:\indexes\enwiki\fwdDict", IxDictionaryMode.READ, null); IxHalCreator halCreator = new IxHalCreator(@"D:\indexes\enwiki\hal", @"K:\halTmp", fwdIndex, fwdDict, IxSettings.defaultHalWindow); Stopwatch timer = new Stopwatch(); timer.Start(); //halCreator.createHal(); //halCreator.optimizeMatrix(); halCreator.createHalIndex(); //halCreator.calculateContext(); //halCreator.createAllowedTokensIdsFile(@"K:\WordNet\index.noun"); timer.Stop(); Console.WriteLine("HALCreator: all jobs completed in {0}", timer.Elapsed); Console.ReadLine(); }
/// <summary> /// Standardowy konstruktor /// </summary> /// <param name="indexDirPath">Ścieżka do katalogu, gdzie zostaną zapisane dane indeksu (musi nie istnieć bądź być pusty)</param> /// <param name="threadCount">Liczba wątków indeksera</param> public IxStdRIIndexer(string indexDirPath, uint threadCount) { if (!Misc.isDirectoryMissingOrEmpty(indexDirPath)) throw new IxException("Target index directory exists and is not empty"); this.indexDirPath = Misc.provideEndBackslash(indexDirPath); Misc.provideDirectory(this.indexDirPath); index = new Index.IxStdDiskRIIndex(this.indexDirPath + "invIndex", IxIndexMode.CREATE); documentsIndex = new DocumentsIndex.IxStdDiskDocumentsIndex(this.indexDirPath + "documents", DocumentsIndexMode.CREATE); if (IxSettings.createFwdIndex) fwdIndex = new IxStdDiskFwdIndex(this.indexDirPath + "fwdIndex", IxIndexMode.CREATE); sharedData = new IxStdRIIndexerSharedData(); sharedData.docIdAllocator = this; if (IxSettings.createBkdDictionary) sharedData.dictionary = new IxDoubleDictCreator(this, this); else sharedData.dictionary = createFwdDict(this); this.threadCount = threadCount; }
/// <summary> /// Standardowy konstruktor /// </summary> /// <param name="workingDirPath">Ścieżka do katalogu, gdzie mają być zapisane dane HAL</param> /// <param name="altWorkingDirPath">Ścieżka do alternatywnego katalogu (np. na innym dysku), lub null</param> /// <param name="fwdIndex">Indeks wprzód (w trybie IxIndexMode.READ)</param> /// <param name="fwdDictionary">Słownik wprzód (w trybie IxDictionaryMode.READ)</param> /// <param name="halWindow">Okno analizy HAL</param> public IxHalCreator(string workingDirPath, string altWorkingDirPath, IxStdDiskFwdIndex fwdIndex, IIxForwardDictionary fwdDictionary, int[] halWindow) { this.workingDirPath = Misc.provideEndBackslash(workingDirPath); Misc.provideDirectory(workingDirPath); if (altWorkingDirPath == null) { altWorkingDirPath = workingDirPath; } else { altWorkingDirPath = Misc.provideEndBackslash(altWorkingDirPath); Misc.provideDirectory(altWorkingDirPath); } this.fwdIndex = fwdIndex; this.fwdDictionary = fwdDictionary; this.halWindow = halWindow; }
private IxDocumentWithTokensAndPositions GetTokens(IxStdDiskFwdIndex fwdIndex, uint documentId) { IxDocumentWithTokensAndPositions result = new IxDocumentWithTokensAndPositions(); result.DocumentId = documentId; //pobieramy id wszystkich tokenów występujących w każdym dokumencie uint[] orderedTokensId = fwdIndex.getDocumentTokenList(documentId); for (uint j = 0; j < orderedTokensId.Length; j++) { IxTokenPositions tempOccurence = result.Tokens.Where(x => x.TokenId == orderedTokensId[j]).FirstOrDefault(); if (tempOccurence == null) { tempOccurence = new IxTokenPositions(); tempOccurence.TokenId = orderedTokensId[j]; tempOccurence.Positions.Add(j); result.Tokens.Add(tempOccurence); } else { tempOccurence.Positions.Add(j); } } result.TotalNumberOfTokens = (uint)orderedTokensId.Length; return result; }
/// <summary> /// Standardowy konstruktor /// </summary> /// <param name="workingDir">Katalog z danymi indeksu</param> public IxHALIRSearchEngine(string workingDir) { workingDir = Misc.provideEndBackslash(workingDir); this.workingDir = workingDir; invIndex = new IxStdDiskRIIndex(workingDir + "invIndex", IxIndexMode.READ); fwdIndex = new IxStdDiskFwdIndex(workingDir + "fwdIndex", IxIndexMode.READ); documentsIndex = new IxStdDiskDocumentsIndex(workingDir + "documents", DocumentsIndexMode.READ); fwdDictionary = new IxFwdDistDiskDict(workingDir + "fwdDict", IxDictionaryMode.READ, null); bkdDictionary = new IxStdBkdDiskDict(workingDir + "bkdDict", IxDictionaryMode.READ); tokenListing = new IxTokenizer(fwdDictionary); halContextObtainer = new IxHalContextObtainer(workingDir + "hal", fwdIndex, invIndex); documentsCount = (double)invIndex.getDocumentsCount(); }