Ejemplo n.º 1
0
 void WriteHadithVerseReferences(VerseRangeReference verseReference)
 {
     using (Xml.WriteElement("reference"))
     {
         Xml.WriteElementString("chapter", verseReference.Chapter + "");
         Xml.WriteElementString("firstVerse", verseReference.FirstVerse + "");
         Xml.WriteElementString("lastVerse", verseReference.LastVerse + "");
     }
 }
Ejemplo n.º 2
0
        public Verse GetVerse(VerseReference verseReference)
        {
            var verseRangeReference = new VerseRangeReference(
                chapter: verseReference.Chapter,
                firstVerse: verseReference.Verse,
                lastVerse: verseReference.Verse);

            return(GetVerses(new VerseRangeReference[] { verseRangeReference }).Single());
        }
Ejemplo n.º 3
0
        public ActionResult MultipleVerses(string[] translations, string verses)
        {
            ResetTranslations(ref translations);
            var references = verses.Split(',')
                             .ToList()
                             .ConvertAll(x => VerseRangeReference.Parse(x));
            var model = SharedData.Document.QuranDocument.GetVersesInRange(references);

            return(PartialView("VersesView", model));
        }
Ejemplo n.º 4
0
        public ActionResult MultipleVerses(string verses)
        {
            SetTranslationsViewBag();
            ViewBag.VerseReferences = verses;
            var references = verses.Split(',')
                             .ToList()
                             .ConvertAll(x => VerseRangeReference.Parse(x));
            var model = SharedData.Document.QuranDocument.GetVersesInRange(references);

            return(View(model));
        }
Ejemplo n.º 5
0
        void AddVerseReference(MultiPartReference hadithReference, string verseRangeReferenceText)
        {
            var verseRangeReference = VerseRangeReference.Parse(verseRangeReferenceText);
            HashSet <VerseRangeReference> verseRangeReferences;

            if (!VersesByHadith.TryGetValue(hadithReference, out verseRangeReferences))
            {
                verseRangeReferences            = new HashSet <VerseRangeReference>();
                VersesByHadith[hadithReference] = verseRangeReferences;
            }
            verseRangeReferences.Add(verseRangeReference);
        }
Ejemplo n.º 6
0
        public IEnumerable <ChapterAndVerse> GetVersesInRange(VerseRangeReference verseRangeReference)
        {
            var result = new List <ChapterAndVerse>();

            foreach (var verseReference in verseRangeReference.ToVerseReferences())
            {
                var chapter = this[verseReference.Chapter];
                var verse   = chapter[verseReference.Verse];
                result.Add(new ChapterAndVerse(chapter: chapter, verse: verse));
            }
            return(result);
        }
Ejemplo n.º 7
0
        private static IEnumerable <VerseRangeReference> AddSurroundingVerses(int?context, VerseRangeReference firstReference)
        {
            IEnumerable <VerseRangeReference> verseRangeReferences;
            int numberOfVerses    = QuranStructure.Chapter(firstReference.Chapter).NumberOfVerses;
            int firstVerse        = Math.Max(1, firstReference.FirstVerse - context.Value);
            int lastVerse         = Math.Min(numberOfVerses, firstReference.LastVerse + context.Value);
            var newVerseReference = new VerseRangeReference(
                chapter: firstReference.Chapter,
                firstVerse: firstVerse,
                lastVerse: lastVerse);

            verseRangeReferences = new[] { newVerseReference };
            return(verseRangeReferences);
        }
Ejemplo n.º 8
0
        public ActionResult Index(string verses, int?context)
        {
            IEnumerable <VerseRangeReference> verseRangeReferences = verses.Split(',')
                                                                     .ToList()
                                                                     .ConvertAll(x => VerseRangeReference.Parse(x));

            if (!verseRangeReferences.Any())
            {
                verseRangeReferences = new VerseRangeReference[] { new VerseRangeReference(1, 1, 1) }
            }
            ;

            VerseRangeReference firstReference = verseRangeReferences.First();
            bool autoScrollToSelectedVerse     = verseRangeReferences.Count() == 1 && context.HasValue && context > 0;

            if (autoScrollToSelectedVerse)
            {
                verseRangeReferences = AddSurroundingVerses(context, firstReference);
            }

            IEnumerable <Verse> retrievedVerses = VerseRepository.GetVerses(verseRangeReferences)
                                                  .OrderBy(x => x.ChapterNumber)
                                                  .ThenBy(x => x.VerseNumber);

            var displayVerses = new List <ChapterAndVerseSelection>();

            foreach (VerseRangeReference verseRangeReference in verseRangeReferences)
            {
                IEnumerable <Verse> currentSelection =
                    retrievedVerses
                    .Where(x => verseRangeReference.Includes(x.ChapterNumber, x.VerseNumber));
                var chapterAndSelection = new ChapterAndVerseSelection(ChapterRepository.Get(verseRangeReference.Chapter), currentSelection);
                displayVerses.Add(chapterAndSelection);
            }

            var viewModel = new ViewModel(
                displayVerses: displayVerses,
                selectChapterAndVerse: new SelectChapterAndVerse(
                    firstReference.Chapter,
                    firstReference.FirstVerse,
                    url: ""),
                autoScrollToSelectedVerse: autoScrollToSelectedVerse
                );

            return(View("QuranVerses", viewModel));
        }
Ejemplo n.º 9
0
        void ReadCommentary(int chapterIndex, XElement commentaryNode)
        {
            int firstVerse          = int.Parse(commentaryNode.Element("firstVerse").Value);
            int lastVerse           = int.Parse(commentaryNode.Element("lastVerse").Value);
            var verseRangeReference = new VerseRangeReference(
                chapter: chapterIndex,
                firstVerse: firstVerse,
                lastVerse: lastVerse
                );
            var text = commentaryNode.Elements("text").Select(x => x.Value);

            var comment = new TafsirComment(
                verseReference: verseRangeReference,
                text: text
                );

            Tafsir.AddComment(comment);
        }
Ejemplo n.º 10
0
        private IEnumerable <int> GetVerses(VerseRangeReference verseRangeReference)
        {
            var query = new BooleanQuery(disableCoord: true);

            query
            .FilterByType <Verse>()
            .AddNumericRangeQuery <Verse>(
                x => x.ChapterNumber,
                lowerInclusive: verseRangeReference.Chapter,
                upperInclusive: verseRangeReference.Chapter,
                occur: Occur.MUST)
            .AddNumericRangeQuery <Verse>(
                x => x.VerseNumber,
                lowerInclusive: verseRangeReference.FirstVerse,
                upperInclusive: verseRangeReference.LastVerse,
                occur: Occur.MUST);

            IndexSearcher     searcher = IndexSearcherProvider.GetIndexSearcher();
            TopDocs           docs     = searcher.Search(query, 7000);
            IEnumerable <int> verses   = docs.ScoreDocs.Select(x => x.Doc).ToArray();

            return(verses);
        }
Ejemplo n.º 11
0
 IEnumerable <VerseRangeReference> ReadVerseReferences(XElement parentNode)
 {
     return(parentNode.Elements("reference")
            .Select(x => VerseRangeReference.ParseXml(x)));
 }
Ejemplo n.º 12
0
 public TafsirComment(VerseRangeReference verseReference, IEnumerable <string> text)
 {
     this.VerseReference = verseReference;
     this.Text           = text.ToArray();
 }