Esempio n. 1
0
        public static WsdProject Load(string path, IProgressHandle progress)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (PathEx.Identify(path) != PathIdentity.File ||
                Path.GetExtension(path) != FileExtension.WsdProj)
            {
                throw new ArgumentException(ExceptionMessage.PathMustBeExistingWsdProj);
            }

            var projectInfo      = SystemJsonReader.Read <WsdProjectInfo>(path);
            var projectDirectory = Path.GetDirectoryName(path);

            if (projectInfo.ProjectVersion != CurrentProjectVersion)
            {
                throw new Exception(ExceptionMessage.ProjectVersionNotSupported(
                                        projectInfo.ProjectVersion, CurrentProjectVersion));
            }

            progress.SetMessageFormat(MessageFormat.LoadingDictionary_Bytes);

            var dictionary = SystemDictionaryReader.ReadAll(
                Path.Combine(projectDirectory, projectInfo.Dictionary), progress);

            progress.SetMessageFormat(MessageFormat.LoadingTrainData_Files);

            var trainData = SystemDataReader.ReadAllFiles(
                projectDirectory, projectInfo.TrainData.Select(x => (x.Path, x.Name)).ToArray(),
                progress);

            progress.SetMessageFormat(MessageFormat.LoadingTestData_Files);

            var testData = SystemDataReader.ReadAllFiles(
                projectDirectory, projectInfo.TestData.Select(x => (x.Path, x.Name)).ToArray(),
                progress);

            progress.SetMessageFormat(MessageFormat.LoadingWordEmbeddings_Bytes);

            var wordEmbeddings = SystemEmbeddingReader.ReadAll(
                Path.Combine(projectDirectory, projectInfo.WordEmbeddings), progress);

            EmbeddingDictionary meaningEmbeddings = null;

            if (!string.IsNullOrWhiteSpace(projectInfo.MeaningEmbeddings))
            {
                progress.SetMessageFormat(MessageFormat.LoadingMeaningEmbeddings_Bytes);

                meaningEmbeddings = SystemEmbeddingReader.ReadAll(
                    Path.Combine(projectDirectory, projectInfo.MeaningEmbeddings), progress);
            }

            progress.SetMessageFormat(MessageFormat.LoadingDataAnalysis_Bytes);

            var dataAnalysis = SystemDataAnalysisReader.ReadAll(
                Path.Combine(projectDirectory, projectInfo.DataAnalysis), progress);

            var dictionaryStatistics = SystemJsonReader.Read <DictionaryStatistics>(
                Path.Combine(projectDirectory, projectInfo.DictionaryStatistics));

            var dataStatistics = SystemJsonReader.Read <DataStatistics>(
                Path.Combine(projectDirectory, projectInfo.DataStatistics));

            var wordEmbeddingsStatistics = SystemJsonReader.Read <EmbeddingStatistics>(
                Path.Combine(projectDirectory, projectInfo.WordEmbeddingsStatistics));

            var meaningEmbeddingsStatistics = SystemJsonReader.Read <EmbeddingStatistics>(
                Path.Combine(projectDirectory, projectInfo.MeaningEmbeddingsStatistics));

            return(new WsdProject(
                       projectInfo, dictionary, trainData, testData, wordEmbeddings, meaningEmbeddings,
                       dataAnalysis, dictionaryStatistics, dataStatistics, wordEmbeddingsStatistics,
                       meaningEmbeddingsStatistics));
        }