Beispiel #1
0
 public StudyResource(ScriptureReference reference, ISet <string> topics)
 {
     category       = (Category)reference.volume;
     this.reference = reference.ToString();
     referenceURL   = reference.GetURL();
     this.topics    = new SortedSet <string>(topics);
     body           = reference.GetText();
 }
        public bool Contains(ScriptureReference other)
        {
            if (Book == other.Book)
            {
                return StartChapter.GetValueOrDefault(0) >= other.StartChapter.GetValueOrDefault(0) &&
                       StartVerse.GetValueOrDefault(0) >= other.StartVerse.GetValueOrDefault(0) &&
                       EndChapter.GetValueOrDefault(999) <= other.EndChapter.GetValueOrDefault(999) &&
                       EndVerse.GetValueOrDefault(999) <= other.EndVerse.GetValueOrDefault(999);
            }

            return false;
        }
        private void autoLinkButton_Click(object sender, EventArgs e)
        {
            ScriptureReference scripture = ScriptureReference.Parse(resource.reference);

            if (scripture != null)
            {
                urlTextBox.Text = scripture.GetURL();
            }
            else
            {
                MessageBox.Show("Invalid reference for scripture.");
            }
        }
Beispiel #4
0
        public StudyResource(XmlNode node)
        {
            // Get category attribute
            XmlNode catAttr = node.Attributes.GetNamedItem("category");

            if (catAttr != null)
            {
                category = (Category)Enum.Parse(typeof(Category), catAttr.Value);
            }

            // Parse topics and body
            topics = new SortedSet <string>();
            body   = new List <StudyElement>();

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "topic")
                {
                    topics.Add(child.InnerText);
                }
                else if (child.Name == "reference")
                {
                    reference    = child.InnerText;
                    referenceURL = child.Attributes.GetNamedItem("url").Value;
                }
                else if (child.Name == "body")
                {
                    // Parse body
                    foreach (XmlNode elementNode in child.ChildNodes)
                    {
                        StudyElement element = StudyElement.FromXml(elementNode);

                        if (element != null)
                        {
                            body.Add(element);
                        }
                    }
                }
            }

            // If no category was given, attempt to guess
            if (catAttr == null && ScriptureReference.Parse(reference) is ScriptureReference parsed)
            {
                category = (Category)parsed.volume;
            }
        }
        private void webTextButton_Click(object sender, EventArgs e)
        {
            ScriptureReference scripture = ScriptureReference.Parse(resource.reference);

            if (scripture == null)
            {
                MessageBox.Show("Invalid reference.");
                return;
            }

            List <StudyElement> text = scripture.GetText();

            if (text == null)
            {
                MessageBox.Show("Failed to obtain text from web.");
                return;
            }

            resource.body.AddRange(text);
            ResourceUpdate?.Invoke(this, new EventArgs());
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // Scripture Set Test
            string       input      = null;
            ScriptureSet scriptures = new ScriptureSet();

            while (input != "")
            {
                Console.Write("Scripture Reference: ");
                input = Console.ReadLine();

                ScriptureReference reference = ScriptureReference.Parse(input);

                if (reference != null)
                {
                    Console.WriteLine("Parsed: {0}", reference);
                    scriptures.Add(reference, new SortedSet <string> {
                        "test"
                    });
                }
                else
                {
                    Console.WriteLine("Parsing failed.");
                }

                Console.WriteLine("All Scriptures: {0}\n", string.Join("; ", scriptures.allReferences));
            }

            // Web Search
            Console.Write("Search Topic: ");
            string topic = Console.ReadLine();

            while (topic != "")
            {
                List <string> pages          = WebCrawler.SearchWebByTopic(topic);
                List <string> secondaryPages = new List <string>();

                // Remove all usage of preach my gospel. Too many chapters combine several topics.
                pages.RemoveAll(x => x.Contains("preach-my-gospel"));

                Console.WriteLine("Found {0} pages referencing '{1}'", pages.Count, topic);

                int totalFound = 0;
                foreach (string page in pages)
                {
                    Console.WriteLine("Searching {0}...", page);

                    List <string>             newPages;
                    List <ScriptureReference> found = WebCrawler.SearchPageForScriptures(page, out newPages);
                    totalFound += found.Count;

                    scriptures.UnionWith(found, new SortedSet <string> {
                        topic
                    });
                    secondaryPages.AddRange(newPages);

                    System.Threading.Thread.Sleep(1000);
                }

                Console.WriteLine("Found {0} scriptures for the topic '{1}'\n", totalFound, topic);

                // Get input for next search
                Console.Write("Search Topic: ");
                topic = Console.ReadLine();
            }

            Console.WriteLine("\nAll Topics: {0}", string.Join(", ", scriptures.allTopics));
            Console.WriteLine("All Scriptures:\n{0}", string.Join("\n", scriptures.allReferences));
            Console.ReadLine();
        }