Beispiel #1
0
        public void ParseSingleDigit(string input, int expected)
        {
            var p      = new RomanNumeralParser();
            var result = p.Parse(input);

            result.ShouldBe(expected);
        }
Beispiel #2
0
        public List <Movie> FindByTitleCandidates(List <string> titles, out List <string> otherTitles)
        {
            var lookupTitles = new List <string>();

            otherTitles = new List <string>();

            foreach (var title in titles)
            {
                var cleanTitle  = title.CleanMovieTitle().ToLowerInvariant();
                var romanTitle  = cleanTitle;
                var arabicTitle = cleanTitle;

                foreach (var arabicRomanNumeral in RomanNumeralParser.GetArabicRomanNumeralsMapping())
                {
                    var arabicNumber = arabicRomanNumeral.ArabicNumeralAsString;
                    var romanNumber  = arabicRomanNumeral.RomanNumeral;

                    romanTitle  = romanTitle.Replace(arabicNumber, romanNumber);
                    arabicTitle = arabicTitle.Replace(romanNumber, arabicNumber);
                }

                romanTitle = romanTitle.ToLowerInvariant();

                otherTitles.AddRange(new List <string> {
                    arabicTitle, romanTitle
                });
                lookupTitles.AddRange(new List <string> {
                    cleanTitle, arabicTitle, romanTitle
                });
            }

            return(_movieRepository.FindByTitles(lookupTitles));
        }
Beispiel #3
0
        private Movie FindByTitle(string cleanTitle, int?year)
        {
            cleanTitle = cleanTitle.ToLowerInvariant();
            string cleanTitleWithRomanNumbers  = cleanTitle;
            string cleanTitleWithArabicNumbers = cleanTitle;


            foreach (ArabicRomanNumeral arabicRomanNumeral in RomanNumeralParser.GetArabicRomanNumeralsMapping())
            {
                string arabicNumber = arabicRomanNumeral.ArabicNumeralAsString;
                string romanNumber  = arabicRomanNumeral.RomanNumeral;
                cleanTitleWithRomanNumbers  = cleanTitleWithRomanNumbers.Replace(arabicNumber, romanNumber);
                cleanTitleWithArabicNumbers = cleanTitleWithArabicNumbers.Replace(romanNumber, arabicNumber);
            }

            Movie result = Query(q =>
            {
                return(q.Where(s => s.CleanTitle == cleanTitle).FirstWithYear(year));
            });

            if (result == null)
            {
                result =
                    Query(q => q.Where(movie => movie.CleanTitle == cleanTitleWithArabicNumbers).FirstWithYear(year)) ??
                    Query(q => q.Where(movie => movie.CleanTitle == cleanTitleWithRomanNumbers).FirstWithYear(year));

                if (result == null)
                {
                    /*IEnumerable<Movie> movies = All();
                     * Func<string, string> titleCleaner = title => CoreParser.CleanSeriesTitle(title.ToLower());
                     * Func<IEnumerable<AlternativeTitle>, string, bool> altTitleComparer =
                     *  (alternativeTitles, atitle) =>
                     *  alternativeTitles.Any(altTitle => altTitle.CleanTitle == atitle);*/

                    /*result = movies.Where(m => altTitleComparer(m.AlternativeTitles, cleanTitle) ||
                     *                          altTitleComparer(m.AlternativeTitles, cleanTitleWithRomanNumbers) ||
                     *                    altTitleComparer(m.AlternativeTitles, cleanTitleWithArabicNumbers)).FirstWithYear(year);*/

                    //result = Query.Join<Movie, AlternativeTitle>(JoinType.Inner, m => m._newAltTitles,
                    //(m, t) => m.Id == t.MovieId && (t.CleanTitle == cleanTitle)).FirstWithYear(year);
                    result = Query(q => q.Where <AlternativeTitle>(t =>
                                                                   t.CleanTitle == cleanTitle || t.CleanTitle == cleanTitleWithArabicNumbers ||
                                                                   t.CleanTitle == cleanTitleWithRomanNumbers)
                                   .FirstWithYear(year));
                }
            }

            return(result);

            /*return year.HasValue
             *  ? results?.FirstOrDefault(movie => movie.Year == year.Value)
             *
             *
             * : results?.FirstOrDefault();*/
        }
Beispiel #4
0
        public ParsingService(IMovieService movieService,
                              IEnumerable <IAugmentParsedMovieInfo> augmenters,
                              Logger logger)
        {
            _movieService = movieService;
            _augmenters   = augmenters;
            _logger       = logger;

            if (_arabicRomanNumeralMappings == null)
            {
                _arabicRomanNumeralMappings = RomanNumeralParser.GetArabicRomanNumeralsMapping();
            }
        }
Beispiel #5
0
        public ParsingService(IEpisodeService episodeService,
                              ISeriesService seriesService,
                              ISceneMappingService sceneMappingService,
                              IMovieService movieService,
                              IConfigService configService,
                              Logger logger)
        {
            _episodeService      = episodeService;
            _seriesService       = seriesService;
            _sceneMappingService = sceneMappingService;
            _movieService        = movieService;
            _config = configService;
            _logger = logger;

            if (_arabicRomanNumeralMappings == null)
            {
                _arabicRomanNumeralMappings = RomanNumeralParser.GetArabicRomanNumeralsMapping();
            }
        }
Beispiel #6
0
        public ParsingService(
            IMovieService movieService,
            IConfigService configService,
            IQualityDefinitionService qualityDefinitionService,
            ICustomFormatService formatService,
            IEnumerable <IAugmentParsedMovieInfo> augmenters,
            Logger logger)
        {
            _movieService             = movieService;
            _config                   = configService;
            _qualityDefinitionService = qualityDefinitionService;
            _formatService            = formatService;
            _augmenters               = augmenters;
            _logger                   = logger;

            if (_arabicRomanNumeralMappings == null)
            {
                _arabicRomanNumeralMappings = RomanNumeralParser.GetArabicRomanNumeralsMapping();
            }
        }
Beispiel #7
0
        public List <Movie> FindByTitleCandidates(string title, out string arabicTitle, out string romanTitle)
        {
            var cleanTitle = title.CleanMovieTitle().ToLowerInvariant();

            romanTitle  = cleanTitle;
            arabicTitle = cleanTitle;

            foreach (var arabicRomanNumeral in RomanNumeralParser.GetArabicRomanNumeralsMapping())
            {
                var arabicNumber = arabicRomanNumeral.ArabicNumeralAsString;
                var romanNumber  = arabicRomanNumeral.RomanNumeral;

                romanTitle  = romanTitle.Replace(arabicNumber, romanNumber);
                arabicTitle = arabicTitle.Replace(romanNumber, arabicNumber);
            }

            romanTitle = romanTitle.ToLowerInvariant();

            return(_movieRepository.FindByTitles(new List <string> {
                cleanTitle, arabicTitle, romanTitle
            }));
        }
        private static void TestTranslation(Token[] tokens, string expected)
        {
            var parser = new RomanNumeralParser();

            string result = parser.Parse(tokens);

            Assert.AreEqual(expected, result);
        }