コード例 #1
0
ファイル: Bigfile2Yaml.cs プロジェクト: wolfspelz/galdev
        public string GetFilePath(TimelineEntry e, string outputFolder, Dictionary <string, int> years)
        {
            var file = "";

            if (string.IsNullOrEmpty(file))
            {
                file = e.Image;
                if (!string.IsNullOrEmpty(file))
                {
                    var dot = file.IndexOf('.');
                    if (dot > 2)
                    {
                        file = file.Substring(0, dot);
                    }
                }
            }

            if (string.IsNullOrEmpty(file))
            {
                file = e.Title
                       .Replace(" ", "_")
                       .Replace("/", "")
                       .Replace(":", "")
                       .Replace("-", "")
                       .Replace(",", "")
                       .Replace("(", "")
                       .Replace(")", "")
                       .Replace("\"", "")
                ;
                var dot = file.IndexOf('.');
                if (dot > 0)
                {
                    file = file.Substring(0, dot);
                }
                file = file.Truncate(30, "");
            }

            if (!years.ContainsKey(e.Year))
            {
                years[e.Year] = 0;
            }
            else
            {
                years[e.Year] += 1;
            }

            var suffix = "acfilortux";

            file = e.Year + (years[e.Year] == 0 ? "" : "" + suffix[years[e.Year]]) + "_" + file;

            return(Path.Combine(outputFolder, file + ".yaml"));
        }
コード例 #2
0
        public List <TimelineEntry> ProcessInput(Dictionary <string, string> inputData)
        {
            var timeline = new List <TimelineEntry>();

            foreach (var filePair in inputData)
            {
                Log.Info(Path.GetFileName(filePair.Key));

                var deserializer = new YamlDotNet.Serialization.Deserializer();
                var dict         = deserializer.Deserialize <Dictionary <string, object> >(filePair.Value);

                var e = new TimelineEntry();
                foreach (var linePair in dict)
                {
                    switch (linePair.Key.ToLower())
                    {
                    case "name": e.Name = (string)linePair.Value; break;

                    case "year": e.Year = (string)linePair.Value; break;

                    case "title": e.Title = (string)linePair.Value; break;

                    case "short": e.Short = (string)linePair.Value; break;

                    case "summary": e.Summary = (string)linePair.Value; break;

                    case "image": e.Image = (string)linePair.Value; break;

                    case "smallimage": e.Smallimage = (string)linePair.Value; break;

                    case "headline": e.Headline = (string)linePair.Value; break;

                    case "post": e.Post = (string)linePair.Value; break;

                    case "postimage": e.Postimage = (string)linePair.Value; break;

                    case "twitter": e.Twitter = (string)linePair.Value; break;

                    case "twitterimage": e.Twitterimage = (string)linePair.Value; break;

                    case "facebook": e.Facebook = (string)linePair.Value; break;

                    case "facebook2": e.Facebook2 = (string)linePair.Value; break;

                    case "facebook3": e.Facebook3 = (string)linePair.Value; break;

                    case "facebookimage": e.Facebookimage = (string)linePair.Value; break;

                    case "author": e.Author = (string)linePair.Value; break;

                    case "translation": e.Translation = (string)linePair.Value; break;

                    case "tags": e.Tags = ((List <object>)linePair.Value).Select(o => (string)o).ToList(); break;

                    case "topics": e.Topics = ((List <object>)linePair.Value).Select(o => (string)o).ToList(); break;

                    case "text": e.Text = ((string)linePair.Value).Replace("\r\n", "\n").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.TrimEnd()).ToList(); break;
                    }

                    if (string.IsNullOrEmpty(e.Post))
                    {
                        e.Postimage = "";
                    }
                    if (string.IsNullOrEmpty(e.Twitter))
                    {
                        e.Twitterimage = "";
                    }
                    if (string.IsNullOrEmpty(e.Facebook))
                    {
                        e.Facebookimage = "";
                    }
                }
                timeline.Add(e);
            }

            return(timeline);
        }
コード例 #3
0
ファイル: Bigfile2Yaml.cs プロジェクト: wolfspelz/galdev
        public List <TimelineEntry> Analyse(string data)
        {
            var timeline = new List <TimelineEntry>();

            var lines = data.Replace("\r\n", "\n").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            var lineCount = 0;

            foreach (var line in lines)
            {
                var e = new TimelineEntry();

                var segments = line.Split(new char[] { '\t' }, 2);
                e.Year = segments[0];
                var text = segments[1];

                var sections = segments[1].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (sections.Length > 0)
                {
                    var paragraphs = sections[0].Split(new char[] { '#' });
                    if (paragraphs.Length > 0)
                    {
                        e.Title = paragraphs[0].Trim().Trim('.');
                    }
                    if (paragraphs.Length > 1)
                    {
                        for (var i = 1; i < paragraphs.Length; i++)
                        {
                            e.Text.Add(paragraphs[i].Trim());
                        }
                    }
                }

                if (sections.Length > 1)
                {
                    for (var i = 1; i < sections.Length; i++)
                    {
                        var parts = sections[i].Trim().Split(new char[] { '=' }, 2);;
                        if (parts.Length == 1)
                        {
                            e.Tags = parts[0].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Replace("#", "").Trim()).ToList();
                        }
                        if (parts.Length == 2)
                        {
                            var key   = parts[0].Trim();
                            var value = parts[1].Trim();
                            switch (key)
                            {
                            case "tags":
                                e.Tags = value.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Replace("#", "").Trim()).ToList();
                                break;

                            case "image":
                                e.Image = value;
                                break;

                            case "smallimage":
                                e.Smallimage = value;
                                break;

                            case "twitter":
                                e.Twitter = value;
                                break;

                            case "twitterimage":
                                e.Twitterimage = value;
                                break;

                            case "facebook":
                            {
                                var fbParts      = value.Split(new char[] { '#' });
                                var claimAndText = fbParts[0].Trim();
                                if (claimAndText.Contains(" - "))
                                {
                                    var yearPos = claimAndText.IndexOf(e.Year);
                                    if (yearPos > 0)
                                    {
                                        var headline = claimAndText.Substring(0, yearPos).Trim();
                                        headline   = headline.TrimEnd('-');
                                        headline   = headline.Trim();
                                        e.Headline = headline;
                                        var facebook = claimAndText.Substring(yearPos).Trim();
                                        //var likePos = facebook.IndexOf("(");
                                        //if (likePos > 0)
                                        //{
                                        //    facebook = facebook.Substring(0, likePos).Trim();
                                        //}
                                        e.Facebook = facebook;
                                    }
                                }
                                else
                                {
                                    e.Facebook = claimAndText;
                                }
                                if (fbParts.Length == 3)
                                {
                                    e.Facebook2 = fbParts[1].Trim();
                                    e.Facebook3 = fbParts[2].Trim();
                                    var x   = fbParts[2].Trim();
                                    var pos = x.ToLower().IndexOf("weiter");
                                    if (pos > 0)
                                    {
                                        x = x.Substring(0, pos).Trim();
                                    }
                                    e.Short = x;
                                }
                            }
                            break;

                            case "facebookimage":
                                e.Facebookimage = value;
                                break;

                            case "author":
                                e.Author = value;
                                break;

                            case "translation":
                                e.Translation = value;
                                break;

                            case "topic":
                                e.Topics = value.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList();
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }

                {
                    var dot = e.Image.IndexOf('.');
                    if (dot > 0)
                    {
                        e.Name = e.Image.Substring(0, dot);
                    }
                }

                e.Post = e.Facebook;
                if (!string.IsNullOrEmpty(e.Facebookimage))
                {
                    e.Postimage = e.Facebookimage;
                }
                if (!string.IsNullOrEmpty(e.Twitterimage))
                {
                    e.Postimage = e.Twitterimage; // some years ago larger than FB image, later the same
                }

                timeline.Add(e);
                lineCount++;
            }

            return(timeline);
        }
コード例 #4
0
ファイル: Bigfile2Yaml.cs プロジェクト: wolfspelz/galdev
        public string CreateYamlData(TimelineEntry e)
        {
            var s = "";

            if (!string.IsNullOrEmpty(e.Name))
            {
                s += $"Name: {e.Name}\r\n";
            }
            s += $"Year: {YamlValue(e.Year)}\r\n";
            s += $"Title: {YamlValue(e.Title)}\r\n";
            if (!string.IsNullOrEmpty(e.Short))
            {
                s += $"Short: {YamlValue(e.Short)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Summary))
            {
                s += $"Summary: {YamlValue(e.Summary)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Image))
            {
                s += $"Image: {YamlValue(e.Image)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Headline))
            {
                s += $"Headline: {YamlValue(e.Headline)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Smallimage))
            {
                s += $"SmallImage: {YamlValue(e.Smallimage)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Post))
            {
                s += $"Post: {YamlValue(e.Post)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Postimage))
            {
                s += $"PostImage: {YamlValue(e.Postimage)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Twitter))
            {
                s += $"Twitter: {YamlValue(e.Twitter)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Twitterimage))
            {
                s += $"TwitterImage: {YamlValue(e.Twitterimage)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Facebook))
            {
                s += $"Facebook: {YamlValue(e.Facebook)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Facebook2))
            {
                s += $"Facebook2: {YamlValue(e.Facebook2)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Facebook3))
            {
                s += $"Facebook3: {YamlValue(e.Facebook3)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Facebookimage))
            {
                s += $"FacebookImage: {YamlValue(e.Facebookimage)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Author))
            {
                s += $"Author: {YamlValue(e.Author)}\r\n";
            }
            if (!string.IsNullOrEmpty(e.Translation))
            {
                s += $"Translation: {YamlValue(e.Translation)}\r\n";
            }
            if (e.Tags.Count > 0)
            {
                s += $"Tags: [{string.Join(", ", e.Tags.Select(x => YamlValue(x)))}]\r\n";
            }
            if (e.Topics.Count > 0)
            {
                s += $"Topics: [{string.Join(", ", e.Topics.Select(x => YamlValue(x)))}]\r\n";
            }
            if (e.Text.Count > 0)
            {
                s += $"Text: |\r\n{string.Join("\r\n", e.Text.Select(x => "  " + x))}\r\n";
            }
            return(s);
        }