コード例 #1
0
        public static String WriteNotesLinkDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var retVal = new MDLinkLine();

            retVal.Link = "Reference";
            if (reference is LitChar)
            {
                retVal.Tag = "Character";
            }
            else if (reference is LitPlace)
            {
                retVal.Tag = "Place";
            }
            else if (reference is LitMyth)
            {
                retVal.Tag = "Myth";
            }
            else if (reference is LitObject)
            {
                retVal.Tag = "Object";
            }
            else
            {
                retVal.Tag = "Reference";
            }
            return(retVal.ToString());
        }
コード例 #2
0
        public static MDSourceFile WriteSourceFileDefault(
            this LitOptions LO,
            LitNovel novel,
            LitSceneMetadata metadata,
            LitAuthor author
            )
        {
            //Write all of the lines of the file
            var lines = LO.WriteMetadata(metadata, author);
            var query = novel.Scenes
                        .Where(s => s.Metadata == metadata)
                        .Select(s => LO.WriteElmSourceLines(s, author));

            foreach (var scenelines in query)
            {
                lines.AddRange(scenelines);
            }
            //Create the file
            var SourceFile = new MDSourceFile()
            {
                Metadata = metadata,
                Author   = author,
                Lines    = lines
            };

            return(SourceFile);
        }
コード例 #3
0
        public static List <String> WriteNotesLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var retVal = new List <String>();

            retVal.Add(LO.WriteNotesHeader(novel, reference));
            retVal.Add(LO.WriteNotesLink(novel, reference));
            retVal.AddRange(LO.WriteNotesCommentary(novel, reference));
            retVal.AddRange(LO.WriteNotesTags(novel, reference));

            if (reference is LitChar)
            {
                retVal.AddRange(LO.WriteNotesCharLines(novel, reference as LitChar));
            }
            if (reference is LitPlace)
            {
                retVal.AddRange(LO.WriteNotesPlaceLines(novel, reference as LitPlace));
            }
            if (reference is LitMyth)
            {
                retVal.AddRange(LO.WriteNotesMythLines(novel, reference as LitMyth));
            }
            if (reference is LitObject)
            {
                retVal.AddRange(LO.WriteNotesObjectLines(novel, reference as LitObject));
            }

            return(retVal);
        }
コード例 #4
0
 public static List <String> WriteNotesCommentaryDefault(
     this LitOptions LO,
     LitNovel novel,
     LitRef reference
     )
 {
     return(new List <string>(new String[] { reference.Commentary }));
 }
コード例 #5
0
        public static MDNotesFile WriteNotesFileDefault(this LitOptions LO, LitNovel novel)
        {
            var retVal = new MDNotesFile();

            foreach (var reference in novel.References)
            {
                retVal.Lines.AddRange(LO.WriteNotesLines(novel, reference));
            }
            return(retVal);
        }
コード例 #6
0
        /// <summary>
        /// THIS FUNCTION MIGHT BE USEFUL FOR "CHECKING MY WORK" BUT NOT FOR ANYTHING ELSE
        /// </summary>
        /// <param name="novel"></param>
        /// <returns></returns>
        public static List <LitRef> GetAllReferences(this LitNovel novel)
        {
            var retVal = novel.References;

            foreach (var scene in novel.Scenes)
            {
                retVal.AddRange(scene.GetAllReferences());
            }
            return(retVal);
        }
コード例 #7
0
 public static void ParseElmTextDefault(
     this LitOptions LO,
     LitNovel novel,
     LitElm elm,
     LitAuthor author,
     IEnumerable <String> lines
     )
 {
     elm.Source[author] = LO.SourceLinesToString(lines);
 }
コード例 #8
0
        public static void ParseElmHeaderDefault(
            this LitOptions LO,
            LitNovel novel,
            LitElm elm,
            IEnumerable <String> SceneLines
            )
        {
            var headerInfo = LO.ParseHeader(SceneLines.First());

            elm.Header = headerInfo.Text;
        }
コード例 #9
0
        public static List <String> WriteNotesCharLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitChar character
            )
        {
            var retVal  = new List <String>();
            var AllElms = novel.AllElms();

            //Show actor instances
            var actorHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Actor in"
            };

            retVal.Add(actorHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(s => s.Actors.Contains(character))
                .Select(s => s.TreeTag.ToHyperlink())
                );

            //Show speaker instances
            var speakerHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Speaker in"
            };

            retVal.Add(speakerHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.Speakers.Contains(character))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            //Show mentions
            var characterHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Mentioned in"
            };

            retVal.Add(characterHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.References.Contains(character))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            return(retVal);
        }
コード例 #10
0
        public static LitRef ParseToLitRefDefault(this LitOptions LO, LitNovel novel, IEnumerable <String> lines)
        {
            if (lines.Count() == 0)
            {
                return(null);
            }
            var PartitionedLines = ParsingTools.PartitionLines(lines, l => System.Text.RegularExpressions.Regex.IsMatch(l, @"^##[^#]"));
            var link             = PartitionedLines.First().Select(s => LO.ParseLink(s)).Where(l => l != null).First();

            var retVal = new LitRef();

            //Do the specific things for this style of reference
            if (link.Link.Equals("Reference"))
            {
                if (link.Tag.Equals("Character"))
                {
                    retVal = new LitChar();
                    (retVal as LitChar).ParseLitChar(PartitionedLines);
                }
                else if (link.Tag.Equals("Place"))
                {
                    retVal = new LitPlace();
                }
                else if (link.Tag.Equals("Myth"))
                {
                    retVal = new LitMyth();
                }
                else if (link.Tag.Equals("Object"))
                {
                    retVal = new LitObject();
                }
            }

            //Get the first tag of the reference
            string pattern = @"^# (.+)";
            var    match   = System.Text.RegularExpressions.Regex.Match(lines.First(), pattern);

            retVal.Tags.Add(new LitTag(match.Groups[1].Value));

            //Save the commentary
            retVal.Commentary = LO.SourceLinesToString(PartitionedLines.First());

            //Save the tags
            pattern = "^## Tags$";
            var tagsList = PartitionedLines.Where(list => System.Text.RegularExpressions.Regex.IsMatch(list.First(), pattern)).First();

            foreach (var tagline in tagsList.Where(s => LO.IsSourceLine(s)))
            {
                retVal.AddTag(new LitTag(tagline));
            }

            return(novel.AddReferenceDistinct(retVal));
        }
コード例 #11
0
        public static IEnumerable <LitElm> AllElms(
            this LitNovel novel
            )
        {
            var retVal = new List <LitElm>();

            foreach (var scene in novel.Scenes)
            {
                retVal.AddRange(scene.AllElms());
            }
            return(retVal);
        }
コード例 #12
0
 /// <summary>
 /// Adds the scene to the novel
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="scene"></param>
 public static void AddScene(this LitNovel novel, LitElm scene)
 {
     foreach (var NovelScene in novel.Scenes)
     {
         if (NovelScene.IsElmMergeable(scene))
         {
             NovelScene.MergeElm(scene);
             return;
         }
     }
     novel.Scenes.Add(scene);
 }
コード例 #13
0
        public static LitAuthor ParseAuthorDefault(
            this LitOptions LO,
            LitNovel novel,
            IEnumerable <String> metadatalines
            )
        {
            var retVal = new LitAuthor();
            var links  = metadatalines.Select(l => LO.ParseLink(l)).Where(link => link != null);

            retVal.Author = links.Where(link => link.Link.Equals("Author")).Select(link => link.Tag.ToLower()).FirstOrDefault();
            return(novel.AddAuthorDistinct(retVal));
        }
コード例 #14
0
 /// <summary>
 /// Will add a new source info to the novel, and return the current source info
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public static LitAuthor AddAuthorDistinct(this LitNovel novel, LitAuthor info)
 {
     foreach (var currentSourceInfo in novel.Authors)
     {
         if (currentSourceInfo.IsSourceInfoIntersection(info))
         {
             return(currentSourceInfo);
         }
     }
     novel.Authors.Add(info);
     return(info);
 }
コード例 #15
0
 /// <summary>
 /// Will add a new SceneMetadata to the novel, or if this metadata already exists, will return the one that already does
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="metadata"></param>
 /// <returns></returns>
 public static LitSceneMetadata AddMetadataDistinct(this LitNovel novel, LitSceneMetadata metadata)
 {
     foreach (var currentSceneMetadata in novel.SceneMetadata)
     {
         if (currentSceneMetadata.Descriptor.Equals(metadata.Descriptor))
         {
             return(currentSceneMetadata);
         }
     }
     novel.SceneMetadata.Add(metadata);
     return(metadata);
 }
コード例 #16
0
        public static LitSceneMetadata ParseMetadataDefault(this LitOptions LO, LitNovel novel, IEnumerable <String> sourceLines)
        {
            var retVal = new LitSceneMetadata();
            var links  = sourceLines.Select(l => LO.ParseLink(l)).Where(link => link != null);

            retVal.Descriptor = links.Where(link => link.Link.Equals("Descriptor")).Select(link => link.Tag).FirstOrDefault();

            var pattern = @"^# (.*)$";
            var match   = System.Text.RegularExpressions.Regex.Match(sourceLines.First(), pattern);

            retVal.Header = match.Groups[1].Value;

            return(novel.AddMetadataDistinct(retVal));
        }
コード例 #17
0
        public static String WriteNotesHeaderDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var TagHeader = new MDHeader()
            {
                HeaderLevel = 1,
                Text        = reference.Tags.First().Tag
            };

            return(TagHeader.ToString());
        }
コード例 #18
0
        /// <summary>
        /// Takes the lines of the notes, and populates the novel References and such appropiately
        /// </summary>
        /// <param name="novel"></param>
        /// <param name="lines"></param>
        public static void ParseNotesFileDefault(this LitOptions LO,
                                                 LitNovel novel,
                                                 MDNotesFile notesfile
                                                 )
        {
            var    PartitionedLines = LO.ExtractNotesRefs(notesfile);
            LitRef litref           = null;

            foreach (var refLines in PartitionedLines)
            {
                litref = LO.ParseToLitRef(novel, refLines);
                novel.AddReferenceDistinct(litref, false);
            }
        }
コード例 #19
0
 /// <summary>
 /// Will add a new reference to the list of references of the novel, or,
 /// if the novel has the reference already, will add any new tags that the
 /// current reference might not have.
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="reference"></param>
 public static LitRef AddReferenceDistinct(this LitNovel novel, LitRef reference, bool generated)
 {
     foreach (var currentRef in novel.References)
     {
         if (currentRef.IsReferenceIntersection(reference))
         {
             currentRef.CombineRef(reference);
             return(currentRef);
         }
     }
     novel.References.Add(reference);
     if (generated)
     {
         novel.GeneratedReference.Add(reference);
     }
     return(reference);
 }
コード例 #20
0
        /// <summary>
        /// This is the kickoff point for where the magic happens
        /// </summary>
        /// <param name="source"></param>
        /// <param name="LO"></param>
        /// <returns></returns>
        public static LitNovel ParseAnnSourceDefault(this LitOptions LO, MDAnnSource source)
        {
            var retVal = new LitNovel();

            //Preliminary tagging
            LO.TagAnnSource(source);

            //Parse the current notes file and fill the novel with current references
            LO.ParseNotesFile(retVal, source.Notes);

            //Parse all of the source files
            foreach (var sourceFile in source.Sources)
            {
                LO.ParseSourceFile(retVal, sourceFile);
            }

            return(retVal);
        }
コード例 #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public static LitElm ParseToElmDefault(
            this LitOptions LO,
            LitNovel novel,
            LitSceneMetadata metadata,
            LitAuthor author,
            IEnumerable <String> lines
            )
        {
            var retVal = new LitElm();

            //Some checks
            if (!novel.Authors.Contains(author))
            {
                throw new Exception(String.Format("Novel does not contain source info. {0}", author.Author));
            }
            if (!novel.SceneMetadata.Contains(metadata))
            {
                throw new Exception(String.Format("Novel does not contain metadata. {0}", metadata.Descriptor));
            }

            //Parse the header
            LO.ParseElmHeader(novel, retVal, lines);

            var PartitionedLines = LO.ExtractSubElms(lines);

            LO.ParseElmLinks(
                novel,
                retVal,
                LO.ExtractElmLinkLines(PartitionedLines.First())
                );

            LO.ParseElmText(novel, retVal, author, PartitionedLines.First());

            foreach (var eventLines in PartitionedLines.Skip(1))
            {
                var litEvent = LO.ParseToElm(novel, metadata, author, eventLines);
                retVal.AddElm(litEvent);
            }

            retVal.Metadata = metadata;
            return(retVal);
        }
コード例 #22
0
        /// <summary>
        /// Kick off point for creating the source objects out of the novel
        /// </summary>
        /// <param name="novel"></param>
        /// <returns></returns>
        public static MDAnnSource WriteAnnSourceDefault(
            this LitOptions LO,
            LitNovel novel
            )
        {
            var retVal = new MDAnnSource();

            //Write source files
            foreach (var author in novel.Authors)
            {
                foreach (var metadata in novel.SceneMetadata)
                {
                    retVal.Sources.Add(LO.WriteSourceFile(novel, metadata, author));
                }
            }
            //Write notes file
            retVal.Notes = LO.WriteNotesFile(novel);

            return(retVal);
        }
コード例 #23
0
        public static void ParseSourceFileDefault(
            this LitOptions LO,
            LitNovel novel,
            MDSourceFile sourceFile
            )
        {
            var PartitionedElms = LO.ExtractFromSourceFile(sourceFile);

            //Extract and add the metadata
            var MetadataLines    = LO.ExtractMetadata(PartitionedElms);
            var LitSceneMetadata = LO.ParseMetadata(novel, MetadataLines);
            var Author           = LO.ParseAuthor(novel, MetadataLines);

            //Extract and add the scenes
            var PartitionedElmLines = LO.ExtractElms(PartitionedElms);

            foreach (var ElmLines in PartitionedElmLines)
            {
                var scene = LO.ParseToElm(novel, LitSceneMetadata, Author, ElmLines);
                novel.AddScene(scene);
            }
        }
コード例 #24
0
        public static List <String> WriteNotesPlaceLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitPlace place
            )
        {
            var retVal  = new List <String>();
            var AllElms = novel.AllElms();

            //Show actor instances
            var locationHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Location of"
            };

            retVal.Add(locationHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(s => s.Locations.Contains(place))
                .Select(s => s.TreeTag.ToHyperlink())
                );

            //Show mentions
            var placeHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Mentioned in"
            };

            retVal.Add(placeHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.References.Contains(place))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            return(retVal);
        }
コード例 #25
0
        public static List <String> WriteNotesObjectLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitObject obj
            )
        {
            var retVal  = new List <String>();
            var AllElms = novel.AllElms();

            //Show speaker instances
            var itemHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Speaker in"
            };

            retVal.Add(itemHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.Items.Contains(obj))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            //Show mentions
            var objectHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Mentioned in"
            };

            retVal.Add(objectHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.References.Contains(obj))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            return(retVal);
        }
コード例 #26
0
        public static List <String> WriteNotesMythLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitMyth myth
            )
        {
            var retVal  = new List <String>();
            var AllElms = novel.AllElms();

            //Show actor instances
            var eventHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Event of"
            };

            retVal.Add(eventHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.Events.Contains(myth))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            //Show mentions
            var mythHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Mentioned in"
            };

            retVal.Add(mythHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.References.Contains(myth))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            return(retVal);
        }
コード例 #27
0
        public static MDTagFile WriteTagFileDefault(
            this LitOptions LO,
            LitNovel novel,
            MDAnnSourceInfo info
            )
        {
            var    retVal = new MDTagFile();
            var    Tags   = new List <MDTag>();
            string Filename;

            foreach (var author in novel.Authors)
            {
                foreach (var metadata in novel.SceneMetadata)
                {
                    Filename = LO.ToShourtSourceFilename(info, metadata, author);
                    var query = novel.Scenes.Where(s => s.Metadata == metadata);
                    foreach (var scene in query)
                    {
                        Tags.AddRange(LO.GetAllTags(scene, Filename));
                    }
                }
            }
            Filename = LO.ToShortNotesFilename(info);
            foreach (var litRef in novel.References)
            {
                foreach (var Tag in litRef.Tags)
                {
                    Tags.Add(new MDTag()
                    {
                        TagName = Tag.Tag,
                        TagFile = Filename,
                        TagLine = LO.WriteRefTagEX(litRef)
                    });
                }
            }

            retVal.Lines = Tags.Select(t => LO.WriteTagLine(t)).ToList();
            return(retVal);
        }
コード例 #28
0
        public static MDAnnSource WriteAnnSourceNovel(
            this LitOptions LO,
            LitNovel novel
            )
        {
            var retVal = new MDAnnSource();
            var list   = new List <MDSourceFile>();

            foreach (var scene in novel.Scenes)
            {
                list.AddRange(
                    WriteSourceFileNovel(
                        LO,
                        new[] { scene.Header },
                        new String [] { },
                        scene,
                        novel.Authors.First()
                        )
                    );
            }
            retVal.Sources = list;
            return(retVal);
        }
コード例 #29
0
        public static List <String> WriteNotesTagsDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var retVal = new List <string>();

            var tagsHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Tags"
            };

            retVal.Add(tagsHeader.ToString());

            //Place the tags in the header
            foreach (var tag in reference.Tags)
            {
                retVal.Add(tag.Tag);
            }

            return(retVal);
        }
コード例 #30
0
 public static void ParseElmLinksDefault(
     this LitOptions LO,
     LitNovel novel,
     LitElm elm,
     IEnumerable <MDLinkLine> links
     )
 {
     foreach (var link in links)
     {
         //I feel as though there is a way to use reflection to be super clever here,
         //But upon thinking about it, I think it would only create more confusion than it
         //would help, since the actual properties of the scene are not that numerous,
         //and to be honest there would probably me more exceptional cases than I am willing
         //To admit, so at this juncture, I will use a elseif chain to do what I want.
         //I don't like it, but at the same time I sort of do because it is more explicit and easier
         //To work with, and an if else chain makes sense.
         //I want to use reflection so bad, but it's probably for the best that I do this in
         //The concrete way for now, and if at some point down the road, I want to change this to use reflection,
         //It will be not terribly difficult to do (at least, only as difficult as reflection is)
         LitRef novelRef;
         if (link.Link.Equals("TreeTag"))
         {
             elm.TreeTag = new LitTag(link.Tag);
         }
         else if (link.Link.Equals("UserTag"))
         {
             //TODO UserTags must be unique, not only and that should be checked somewhere here
             elm.UserTags.Add(new LitTag(link.Tag));
         }
         else if (link.Link.Equals("Character"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.References.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Place"))
         {
             novelRef = novel.AddReferenceDistinct(new LitPlace(link.Tag));
             elm.References.Add(novelRef as LitPlace);
         }
         else if (link.Link.Equals("Myth"))
         {
             novelRef = novel.AddReferenceDistinct(new LitMyth(link.Tag));
             elm.References.Add(novelRef as LitMyth);
         }
         else if (link.Link.Equals("Object"))
         {
             novelRef = novel.AddReferenceDistinct(new LitObject(link.Tag));
             elm.References.Add(novelRef as LitObject);
         }
         else if (link.Link.Equals("Actor"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.Actors.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Location"))
         {
             novelRef = novel.AddReferenceDistinct(new LitPlace(link.Tag));
             elm.Locations.Add(novelRef as LitPlace);
         }
         else if (link.Link.Equals("Speaker"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.Speakers.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Event"))
         {
             novelRef = novel.AddReferenceDistinct(new LitMyth(link.Tag));
             elm.Events.Add(novelRef as LitMyth);
         }
         else if (link.Link.Equals("Item"))
         {
             novelRef = novel.AddReferenceDistinct(new LitObject(link.Tag));
             elm.Items.Add(novelRef as LitObject);
         }
     }
 }