コード例 #1
0
        /// <summary>
        /// 指定されたファイルについて検査
        /// </summary>
        /// <param name="files"></param>
        /// <param name="relatedFiles"></param>
        /// <param name="prospectedTags"></param>
        /// <returns></returns>
        public async Task <bool> CheckFolderUpdateAsync(
            string[] files, PropertiesLevel level,
            IReadOnlyDictionary <string, Record> relatedFiles,
            ConcurrentDictionary <string, ConcurrentBag <TagManager> > prospectedTags)
        {
            var folder = this.Config.GetFolderContainer(this.Path);

            var count = await folder.EnumerateFilesAsync
                            (files, default(CancellationToken), false);

            var options = new LoadingOptions()
            {
                LightMode        = true,
                ContainsChildren = false,
                Level            = level,// PropertiesLevel.Basic,
            };


            this.FileEnumerated?.Invoke(0);
            this.FileLoaded?.Invoke(0);

            await this.DoForAllFilesAsync(folder, options, relatedFiles, prospectedTags);

            var detected = new HashSet <string>(this.DetectedFiles);

            this.RemovedFiles = relatedFiles
                                .AsParallel()
                                .Where(x => !detected.Contains(x.Key))
                                .ToDictionary(x => x.Key, x => x.Value);

            return(true);
        }
コード例 #2
0
        GetTopPunchedCardsPerLabel(
            IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsPerKeyPerLabel,
            IReadOnlyDictionary <string, IExpert> experts,
            int topPunchedCardsPerKeyPerLabelCount)
        {
            var topPunchedCardsPerKeyPerLabel =
                new Dictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > >();

            foreach (var label in DataHelper.GetLabels(BitVectorFactory))
            {
                var topPunchedCardsPerSpecificLabel = punchedCardsPerKeyPerLabel
                                                      .AsParallel()
                                                      .Select(punchedCardsPerKeyPerLabel =>
                                                              Tuple.Create(punchedCardsPerKeyPerLabel, RecognitionHelper.CalculateMaxLoss(punchedCardsPerKeyPerLabel, experts, label)))
                                                      .OrderByDescending(tuple => tuple.Item2)
                                                      .Take(topPunchedCardsPerKeyPerLabelCount)
                                                      .Select(tuple => tuple.Item1);

                foreach (var topPunchedCardPerSpecificLabel in topPunchedCardsPerSpecificLabel)
                {
                    if (!topPunchedCardsPerKeyPerLabel.TryGetValue(topPunchedCardPerSpecificLabel.Key, out var dictionary))
                    {
                        dictionary = new Dictionary <IBitVector, IReadOnlyCollection <IBitVector> >();
                        topPunchedCardsPerKeyPerLabel.Add(topPunchedCardPerSpecificLabel.Key, dictionary);
                    }

                    ((Dictionary <IBitVector, IReadOnlyCollection <IBitVector> >)dictionary).Add(label, topPunchedCardPerSpecificLabel.Value[label]);
                }
            }

            return(topPunchedCardsPerKeyPerLabel);
        }
コード例 #3
0
        private static void MakePredictionsOnTestFileAndCalculateError(MovieScorePredictor predictor, UserCache testingSetCache)
        {
            // Get the list of users to make predictions on
            IReadOnlyDictionary <int, UserCache.UserRatingsCache> listOfUsersToPredictScoresOn = testingSetCache.GetAllUsersAndMovieRatings();

            Console.WriteLine("Making predictions...");
            // Predict ratings for all the users in parallel
            List <MoviePrediction> predictions = listOfUsersToPredictScoresOn.AsParallel().Select(l =>
            {
                // Make the prediction for this users movies
                var returnValue = predictor.PredictAllScores(l.Key, l.Value.GetMovieRatings(), K);

                // This is simply to update the console on the current progress
                l.Value.Predicted = true;
                int predicted     = listOfUsersToPredictScoresOn.Values.Count(n => n.Predicted);
                Console.Write("\r{0}/{1}", predicted, listOfUsersToPredictScoresOn.Count);

                // Return the prediction
                return(returnValue);
            }).SelectMany(s => s.Values).ToList();

            Console.WriteLine(Environment.NewLine);

            Console.WriteLine("Calculating errors...");
            var rootMeanSquareError = RootMeanSquareError.Calculate(predictions);
            var meanAbsoluteError   = MeanAbsoluteError.Calculate(predictions);

            Console.WriteLine("=========================================");
            Console.WriteLine("Root mean square error: {0}", rootMeanSquareError);
            Console.WriteLine("Mean absolute error: {0}", meanAbsoluteError);
        }
コード例 #4
0
 internal static IReadOnlyDictionary <string, IExpert> CreateExperts(IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsCollection)
 {
     return(punchedCardsCollection
            .AsParallel()
            .Select(punchedCardsCollectionItem =>
                    Tuple.Create(punchedCardsCollectionItem.Key, Expert.Create(punchedCardsCollectionItem.Value)))
            .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2));
 }
コード例 #5
0
        private static IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > GetGlobalTopPunchedCard(
            IReadOnlyDictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > > punchedCardsPerKeyPerLabel,
            IReadOnlyDictionary <string, IExpert> experts)
        {
            var globalTopPunchedCard = punchedCardsPerKeyPerLabel
                                       .AsParallel()
                                       .Select(punchedCardsPerKeyPerLabel =>
                                               Tuple.Create(punchedCardsPerKeyPerLabel, RecognitionHelper.CalculateMaxLossSum(punchedCardsPerKeyPerLabel, experts)))
                                       .MaxBy(tuple => tuple.Item2).Item1;

            return(new Dictionary <string, IReadOnlyDictionary <IBitVector, IReadOnlyCollection <IBitVector> > >
            {
                { globalTopPunchedCard.Key, globalTopPunchedCard.Value }
            });
        }
コード例 #6
0
        /// <summary>
        /// フォルダ内のファイルを列挙
        /// </summary>
        /// <param name="information"></param>
        /// <param name="relatedFiles"></param>
        /// <param name="completely"></param>
        /// <param name="level"></param>
        /// <param name="prospectedTags"></param>
        /// <returns></returns>
        public async Task <bool> ListupFilesAsync(FolderInformation information,
                                                  IReadOnlyDictionary <string, Record> relatedFiles,
                                                  bool completely, PropertiesLevel level,
                                                  ConcurrentDictionary <string, ConcurrentBag <TagManager> > prospectedTags)
        {
            this.Path = PathUtility.WithPostSeparator(information.Path);

            this.TopPath = this.Path;

            var exists = await this.Config.IsFolderExistsAsync(information);

            //フォルダ取得に失敗
            if (!exists)
            {
                this.RemovedFiles = relatedFiles.ToDictionary(x => x.Key, x => x.Value);

                information.RefreshEnable = false;

                return(false);
            }


            //ファイル検索オプション
            var options = new LoadingOptions()
            {
                LightMode = (information.Mode == FolderCheckMode.Light) ? true
                    : (information.Mode == FolderCheckMode.Detail) ? false
                    : !completely,

                ContainsChildren = !information.IsTopDirectoryOnly,
                Level            = level,//PropertiesLevel.Basic,
            };


            this.ChildFolderLoaded?.Invoke(this.Path);
            this.FileEnumerated?.Invoke(0);
            this.FileLoaded?.Invoke(0);

            var folder = this.Config.GetFolderContainer(this.Path);

            var count = await folder.EnumerateFilesAsync
                            (x => this.FileEnumerated?.Invoke(x),
                            options.ContainsChildren, default(CancellationToken), false);


            await this.DoForAllFilesAsync(folder, options, relatedFiles, prospectedTags);

            this.FileLoaded?.Invoke((int)count);


            //旧ライブラリに存在するのに検査して見つからなかったファイルを
            //削除された(可能性のある)ファイルとしてリストアップしておく

            var detected = new HashSet <string>(this.DetectedFiles);

            this.RemovedFiles = relatedFiles
                                .AsParallel()
                                .Where(x => !detected.Contains(x.Key))
                                .ToDictionary(x => x.Key, x => x.Value);


            information.RefreshEnable = false;
            return(true);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: AraHaan/CsWin32
    private static void Main(string[] args)
    {
        using var cts           = new CancellationTokenSource();
        Console.CancelKeyPress += (s, e) =>
        {
            Console.WriteLine("Canceling...");
            cts.Cancel();
            e.Cancel = true;
        };

        Console.WriteLine("Initializing generator...");

        try
        {
            string outputDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "output");
            if (Directory.Exists(outputDirectory))
            {
                foreach (string file in Directory.EnumerateFiles(outputDirectory, "*", SearchOption.AllDirectories))
                {
                    File.Delete(file);
                }
            }
            else
            {
                Directory.CreateDirectory(outputDirectory);
            }

            var    sw           = Stopwatch.StartNew();
            string metadataPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location !) !, "Windows.Win32.winmd");
            string apiDocsPath  = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location !) !, "apidocs.msgpack");
            using var generator = new Generator(
                      metadataPath,
                      Docs.Get(apiDocsPath),
                      new GeneratorOptions
            {
                WideCharOnly   = true,
                EmitSingleFile = true,
            },
                      parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp9));
            Console.WriteLine("Generating code... (press Ctrl+C to cancel)");
            if (args.Length > 0)
            {
                foreach (string name in args)
                {
                    cts.Token.ThrowIfCancellationRequested();
                    if (!generator.TryGenerate(name, cts.Token))
                    {
                        Console.Error.WriteLine("WARNING: No match for " + name);
                    }
                }
            }
            else
            {
                generator.GenerateAll(cts.Token);
            }

            Console.WriteLine("Gathering source files...");
            IReadOnlyDictionary <string, Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax>?compilationUnits = generator.GetCompilationUnits(cts.Token);
            Console.WriteLine("Emitting source files...");
            compilationUnits.AsParallel().WithCancellation(cts.Token).ForAll(unit =>
            {
                string outputPath = Path.Combine(outputDirectory, unit.Key);
                Console.WriteLine("Writing output file: {0}", outputPath);
                using var generatedSourceStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
                using var generatedSourceWriter = new StreamWriter(generatedSourceStream, Encoding.UTF8);
                unit.Value.WriteTo(generatedSourceWriter);
            });

            Console.WriteLine("Generation time: {0}", sw.Elapsed);
        }
        catch (OperationCanceledException oce) when(oce.CancellationToken == cts.Token)
        {
            Console.Error.WriteLine("Canceled.");
        }
    }