-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetails.cs
More file actions
118 lines (118 loc) · 4.36 KB
/
Copy pathdetails.cs
File metadata and controls
118 lines (118 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace DetailChecker
{
public abstract class PostInfo
{
public string SubLinking { get; set; }
public string SubLinked { get; set; }
}
public class CrossPostLineInfo : PostInfo
{
public string SourcePost { get; set; }
public string LinkedPost { get; set; }
public CrossPostLineInfo(string line)
{
string[] linesections = line.Split(' ', '\t');
SubLinking = linesections[0];
SubLinked = linesections[1];
SourcePost = linesections[2].Split('T')[0].Trim();
LinkedPost = linesections[6].Split('T')[0].Trim();
}
public CrossPostLineInfo() { }
public static explicit operator CrossPostLineInfo(string source)
{
return new CrossPostLineInfo
{
SourcePost = source
};
}
}
public class LabelInfo
{
public string SourcePost { get; set; }
public string LinkedPost { get; set; }
public bool Burst { get; private set; }
public LabelInfo(string line)
{
string[] sections = line.Split('\t');
Burst = sections[1] == "burst";
var matches = new Regex("('[^']+')").Matches(sections[0]);
int iterator = 0;
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
if (iterator == 0)
SourcePost = groups[iterator].Value.Trim('\'');
else
LinkedPost = groups[iterator].Value.Trim('\'');
iterator++;
}
}
public override string ToString()
{
return $"{SourcePost}, {LinkedPost}, {Burst}";
}
private LabelInfo() { }
public static explicit operator LabelInfo(string source)
{
return new LabelInfo
{
SourcePost = source
};
}
}
public static class Loader
{
public static List<CrossPostLineInfo> GetCrossLinksInfos(string file)
{
List<CrossPostLineInfo> infos = new List<CrossPostLineInfo>();
foreach (var line in File.ReadAllLines(file))
{
infos.Add(new CrossPostLineInfo(line));
}
return infos;
}
public static List<LabelInfo> GetLabelInfos(string file)
{
var infos = new List<LabelInfo>();
foreach (var line in File.ReadAllLines(file))
{
infos.Add(new LabelInfo(line));
}
return infos;
}
}
public class Details
{
static void breakPoint() { }
public static void Main()
{
List<LabelInfo> labelInfos = Loader.GetLabelInfos("./label_info.tsv");
List<CrossPostLineInfo> crossPostInfos = Loader.GetCrossLinksInfos("./post_crosslinks_info.tsv");
var common = crossPostInfos.GroupBy(s => s.SubLinking).Select(g => new { Linking = g.Key, Count = g.Count() }).OrderByDescending(g => g.Count).Where(g => g.Count >= 200);
/*foreach(var value in common) {
Console.WriteLine($"Sub {value.Linking} linked {value.Count}");
}*/
var burstLabels = labelInfos.Where(a => a.Burst).ToArray();
var crossPostSourcePosts = crossPostInfos.Select(a => a.SourcePost).ToArray();
List<CrossPostLineInfo> labeledCrossposts = new List<CrossPostLineInfo>();
foreach (var label in burstLabels)
{
if (crossPostSourcePosts.Contains(label.SourcePost))
{
labeledCrossposts.Add(crossPostInfos.Find(a => a.SourcePost == label.SourcePost));
}
}
//var burstCrossposts = crossPostInfos.FindAll(a => burstLabels.Contains((LabelInfo)a.SourcePost, faster2));
var inCommon = labeledCrossposts.GroupBy(s => s.SubLinking).Select(g => new { Linking = g.Key, Count = g.Count() }).OrderByDescending(g => g.Count).Where(g => g.Count >= 20);
foreach (var temp in inCommon)
{
Console.WriteLine($"burst crossposts source {temp.Linking}, count: {temp.Count}");
}
}
}
}