/// <summary> /// Tworzy kontekst dla wszystkich tokenów w macierzy i zapisuje go do pliku /// /// Kontekst jest zarządzalny przez IxHalContext. /// </summary> public void calculateContext() { ProgressReport progressReport; /* Posłuży do zapisywania wyników */ IxHalContext contextWriter = new IxHalContext(workingDirPath, IxHalContext.Mode.CREATE); /* Obiekt czytający dla tokenów, dla których będzie liczony kontekst */ IxHalMatrixReader matrixReader = new IxHalMatrixReader(workingDirPath); matrixReader.setProgressReportPrefix("!"); /* Obiekt czytający dla tokenów, od których liczone będą odległości do kontekstów */ IxHalMatrixReader matrixReaderSub = new IxHalMatrixReader(workingDirPath); /* Semafor maksymalnej liczby jednocześnie zakolejkowanych wątków ThreadPool */ Semaphore semaphore = new Semaphore(IxSettings.halAnalyzerThreadsNum, IxSettings.halAnalyzerThreadsNum); /* Seria wierszy tokenów, dla których aktualnie liczony jest kontekst */ KeyValuePair<uint, ArrayRow<uint>>[] calculatedForRows = matrixReader.readArrayRowsChunk(1000); while (calculatedForRows.Length != 0) { /* Kalkulatory kontekstów */ IxHalTokenContextCalculator[] calculators = IxHalTokenContextCalculator.create(semaphore, calculatedForRows); int calculatorsCount = calculators.Length; /* Porcja wierszy tokenów, od których liczone będą odległości do kontekstów */ KeyValuePair<uint, ArrayRow<uint>>[] calculatedAgainstRows = matrixReaderSub.readArrayRowsChunk(1000); while (calculatedAgainstRows.Length != 0) { progressReport = new ProgressReport(calculatorsCount, 10, "c"); /* Zleć uzupełnianie kontekstów kalkulatorom */ for (int i = 0; i < calculatorsCount; i++) { calculators[i].calculate(calculatedAgainstRows); progressReport.progressOne(); } /* Pobierz następną porcję tokenów, od których liczone są odległości do kontekstów */ calculatedAgainstRows = matrixReaderSub.readArrayRowsChunk(1000); progressReport.done(); } /* Obliczono już cały kontekst dla tej porcji calculatedForRows - zresetuj obiekt czytający */ matrixReaderSub.reset(); Misc.waitFullSemaphore(semaphore, IxSettings.halAnalyzerThreadsNum); progressReport = new ProgressReport(calculatorsCount, 10, "f"); /* Finalizuj obliczanie kontekstów w kalkulatorach */ for (int i = 0; i < calculatorsCount; i++) { calculators[i].computeFinalResult(); progressReport.progressOne(); } Misc.waitFullSemaphore(semaphore, IxSettings.halAnalyzerThreadsNum); progressReport.done(); progressReport = new ProgressReport(calculatorsCount, 10, "w"); /* Przekaż w kolejności wyniki do contextWriter */ for (int i = 0; i < calculatorsCount; i++) { calculators[i].writeDownResult(contextWriter); progressReport.progressOne(); } /* Pobierz kolejną porcję wierszy tokenów, dla których będzie liczony kontekst */ calculatedForRows = matrixReader.readArrayRowsChunk(100); progressReport.done(); } /* Zakończ pracę */ contextWriter.finalize(); }