コード例 #1
0
ファイル: rawParser.cs プロジェクト: reactxx/rewise
    public static void CSWordSenses()
    {
        var fn    = WikiRawConsts.loadStat().First(f => f.lang == "cs" && f.type == WikiRawConsts.wiktionary).fileNameDump();
        var names = WikiRawConsts.csWordSenses.ToHashSet();
        var lines = new List <string>();

        JsonNew.DeserializeEnum <Sections>(fn + ".sec.json", sect => {
            if (sect.subsections == null)
            {
                return;
            }
            var cs = sect.subsections.FirstOrDefault(s => s.title == "čeština");
            if (cs == null || cs.subsections == null)
            {
                return;
            }
            var senses = cs.subsections.Select(scs => scs.title).Where(s => names.Contains(s)).Distinct().ToArray();
            if (senses.Length == 0)
            {
                return;
            }
            lines.Add($"{sect.title}={string.Join(",", senses)}");
        });
        //using (var rdr = new JsonStreamReader(fn + ".sec.json")) {
        //  foreach (var sect in rdr.Deserialize<Sections>()) {
        //    if (sect.subsections == null) continue;
        //    var cs = sect.subsections.FirstOrDefault(s => s.title == "čeština");
        //    if (cs == null || cs.subsections == null) continue;
        //    var senses = cs.subsections.Select(scs => scs.title).Where(s => names.Contains(s)).Distinct().ToArray();
        //    if (senses.Length == 0) continue;
        //    lines.Add($"{sect.title}={string.Join(",", senses)}");
        //  }
        //}
        File.WriteAllLines(fn + ".cs-senses.txt", lines.OrderBy(s => s));
    }
コード例 #2
0
ファイル: rawParser.cs プロジェクト: reactxx/rewise
    public static void SectionStats()
    {
        Parallel.ForEach(WikiRawConsts.getRawFiles(WikiRawConsts.wiktionary), new ParallelOptions {
            MaxDegreeOfParallelism = 4
        }, rf => {
            var sectStat = new Dictionary <string, int>();
            void add(string l) => sectStat[l] = sectStat.TryGetValue(l, out int c) ? c + 1 : 1;

            JsonNew.DeserializeEnum <Sections>(rf.fileNameDump() + ".sec.json", sect => {
                if (sectStat.Count > 5000)
                {
                    return;
                }
                foreach (var s in sect.lines(0, ""))
                {
                    add(s);
                }
            });
            //using (var rdr = new JsonStreamReader(rf.fileNameDump() + ".sec.json")) {
            //  foreach (var sect in rdr.Deserialize<Sections>()) {
            //    if (sectStat.Count > 5000) break;
            //    foreach (var s in sect.lines(0, "")) add(s);
            //  }
            //}
            File.WriteAllLines(rf.fileNameDump() + ".sec-stat.txt", sectStat.Where(kv => kv.Value >= 10).OrderBy(s => s.Key).Select(s => $"{s.Key} #{s.Value}"));
        });
    }
コード例 #3
0
ファイル: UtilsTest.cs プロジェクト: reactxx/rewise
 public void Test1()
 {
     JsonNew.SerializeEnum(@"c:\temp\pom.json", objs());
     Parallel.ForEach(Enumerable.Range(0, 100), idx => {
         var count = 0;
         JsonNew.DeserializeEnum(typeof(X), @"c:\temp\pom.json", x => {
             count++;
         });
         Assert.Equal(cnt * 2, count);
         count = 0;
     });
 }