Ejemplo n.º 1
0
        public Album(int id, string title, DateTime releaseDate, int score, LabelVendor labelVendor, string coverName, DateTime creationDate, Artist artist, Reviewer reviewer, IEnumerable<string> albumSimilarAlbums, string albumType, string rawAlbumMusicGenre, StyleDefinition processedAlbumMusicGenre, Review chronique)
        {
            Review = chronique;
            Review.Product = this;

            Id = id;
            Title = title;
            ReleaseDate = releaseDate;
            Score = score;
            LabelVendor = labelVendor;
            CoverName = coverName;
            AlbumType = albumType;
            RawAlbumMusicGenre = rawAlbumMusicGenre;
            ProcessedAlbumMusicGenre = processedAlbumMusicGenre;
            Artist = artist;
            Reviewer = reviewer;
            var tmpSimilarAlbums = albumSimilarAlbums.Select(x => x.Replace("<i>", "").Replace("</i>", ""));
            RawSimilarAlbums = tmpSimilarAlbums.Where(x => x.ToUpperInvariant() != title.ToUpperInvariant()).Distinct().ToList();
            CreationDate = creationDate;
        }
Ejemplo n.º 2
0
        public static IList<string> IntegrateExistingStylesAndAlterations(string textToParse, StyleDefinition styleDef, bool doStylesFirst)
        {
            if (string.IsNullOrEmpty(textToParse))
            {
                return new List<string>();
            }

            var styleParts = new List<string>();
            styleParts.AddRange(textToParse.ToUpperInvariant().Split(SplittingStrings.ToArray(), StringSplitOptions.RemoveEmptyEntries));
            styleParts = styleParts.Where(x => SplittingStrings.Where(y => y.Trim().ToUpperInvariant().Contains(x.Trim().ToUpperInvariant())).Count() == 0).ToList();
            var partsToRemove = new List<string>();

            int? idx = null;

            foreach (var part in styleParts)
            {
                #region search main style
                if (doStylesFirst)
                {
                    if (MainStylesRepository.TryRetrieveValueIndex(part, ref idx))
                    {
                        partsToRemove.Add(part);
                        if (idx.HasValue)
                        {
                            try
                            {
                                styleDef.ThrowIfAddMainStyleIsForbidden();
                            }
                            catch (InvalidMusicStyleParsingException)
                            {
                                var message = string.Format("while parsing style part '{0}' we detect too many main styles. string '{1}' will be ignored", textToParse, part);
                                Logging.Logging.Instance.LogError(string.Format("A turnaround will happen : {0}", message), ErrorLevel.Info);
                                continue;
                            }

                            styleDef.AddMainStyleIdx(idx.Value);
                        }
                        continue;
                    }
                }
                #endregion

                #region search style alteration

                if (StyleAlterationsRepository.TryRetrieveValueIndex(part, ref idx))
                {
                    partsToRemove.Add(part);
                    if (idx.HasValue)
                    {
                        try
                        {
                            styleDef.ThrowIfAddStyleAlterationIsForbidden();
                        }
                        catch (InvalidMusicStyleParsingException)
                        {
                            var message = string.Format("while parsing style part '{0}' we detect too many style alterations. string '{1}' will be ignored", textToParse, part);
                            Logging.Logging.Instance.LogError(string.Format("A workaround will happen  : {0}", message), ErrorLevel.Info);
                            continue;
                        }
                        styleDef.AddStyleAlterationIdx(idx.Value);
                    }
                    continue;
                }
                #endregion

                #region search main style
                if (!doStylesFirst)
                {
                    if (MainStylesRepository.TryRetrieveValueIndex(part, ref idx))
                    {
                        partsToRemove.Add(part);
                        if (idx.HasValue)
                        {
                            try
                            {
                                styleDef.ThrowIfAddMainStyleIsForbidden();
                            }
                            catch (InvalidMusicStyleParsingException)
                            {
                                var message = string.Format("while parsing style part '{0}' we detect too many main styles. string '{1}' will be ignored", textToParse, part);
                                Logging.Logging.Instance.LogError(string.Format("A turnaround will happen : {0}", message), ErrorLevel.Info);
                                continue;
                            }

                            styleDef.AddMainStyleIdx(idx.Value);
                        }
                        continue;
                    }
                }
                #endregion
            }

            foreach (var part in partsToRemove)
            {
                styleParts.Remove(part);
            }
            return styleParts;
        }
Ejemplo n.º 3
0
        public bool TryParse(string style, int reviewId, ref StyleDefinition fieldDefinition)
        {
            if (string.IsNullOrEmpty(style))
            {
                throw new ArgumentNullException("style");
            }

            var workingStyle = StylesRepository.MusicGenresRepository.ReplaceReplacements(style.Trim(new[] { ',', ' ', '\t', ';', '.' }));

            try
            {
                var musicTypesIdxs = new List <int>();

                //reconnaissances des types de musique
                string beforeTypeString = workingStyle;
                string afterTypeString  = null;
                string workingStyleForMusicTypeRecognition = workingStyle;

                int?musicTypeIdx;
                do
                {
                    musicTypeIdx = StylesRepository.TryRecognizeMusicType(ref workingStyleForMusicTypeRecognition, ref beforeTypeString, ref afterTypeString);
                    if (musicTypeIdx.HasValue)
                    {
                        if (!musicTypesIdxs.Contains(musicTypeIdx.Value))
                        {
                            musicTypesIdxs.Add(musicTypeIdx.Value);
                        }
                    }
                } while (musicTypeIdx.HasValue);

                fieldDefinition = new StyleDefinition(musicTypesIdxs);

                var beforeTypeRemainingParts = StylesRepository.IntegrateExistingStylesAndAlterations(beforeTypeString, fieldDefinition, true);
                var afterTypeRemainingParts  = StylesRepository.IntegrateExistingStylesAndAlterations(afterTypeString, fieldDefinition, false);

                //Dernière chance pour trouver un type de musique
                if (musicTypesIdxs.Count == 0)
                {
                    var lastChanceMusicType = StylesRepository.GetLastChanceMusicType(fieldDefinition.MainStyles);
                    if (lastChanceMusicType.HasValue)
                    {
                        fieldDefinition.AttachMusicType(lastChanceMusicType.Value);
                    }
                    else if (fieldDefinition.MainStyles.Count > 0)
                    {
                        var message = string.Format("while parsing style '{0}' we can't detect any music genre. We assume that 'Metal' is the main genre of this album", style);
                        Logging.Logging.Instance.LogError(string.Format("A turnaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        fieldDefinition.AttachMusicType(0);
                    }
                    else
                    {
                        var message = string.Format("cannot parse style '{0}' : no existing music type could have been recognized", style);
                        Logging.Logging.Instance.LogError(string.Format("Une erreur est survenue lors de l'extraction du style de la review  {0} : {1}", reviewId, message), ErrorLevel.Warning);
                        return(false);
                    }
                }

                // Creation des nouveaux styles
                foreach (var newMainStyle in beforeTypeRemainingParts)
                {
                    try
                    {
                        fieldDefinition.ThrowIfAddMainStyleIsForbidden();
                    }
                    catch (InvalidMusicStyleParsingException)
                    {
                        var message = string.Format("while parsing style '{0}' we detect too many main styles. string '{1}' will be considered as a style alteration", style, newMainStyle);
                        Logging.Logging.Instance.LogError(string.Format("A turnaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        afterTypeRemainingParts.Insert(0, newMainStyle);
                        continue;
                    }
                    fieldDefinition.AddMainStyleIdx(StylesRepository.MainStylesRepository.AddOrRetrieveValueIndex(newMainStyle));
                }

                //Attachement des styles
                if (fieldDefinition.MusicTypes.Count == 1)
                {
                    foreach (var mainStyleIdx in fieldDefinition.MainStylesIdxs)
                    {
                        StyleDefinition.AttachMainStyleToMusicType(mainStyleIdx, fieldDefinition.MusicTypesIdxs[0]);
                    }
                }

                // Creation des nouvelles altérations
                foreach (var newAlteration in afterTypeRemainingParts)
                {
                    try
                    {
                        fieldDefinition.ThrowIfAddStyleAlterationIsForbidden();
                    }
                    catch (InvalidMusicStyleParsingException)
                    {
                        var message = string.Format("while parsing style '{0}' we detect too many style alterations. string '{1}' will be abandonned", style, newAlteration);
                        Logging.Logging.Instance.LogError(string.Format("A workaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        continue;
                    }
                    fieldDefinition.AddStyleAlterationIdx(StylesRepository.StyleAlterationsRepository.AddOrRetrieveValueIndex(newAlteration));
                }

                return(true);
            }
            catch (Exception e)
            {
                var message = string.Format("cannot parse style '{0}'\n : {1}", style, e.Message);
                Logging.Logging.Instance.LogError(string.Format("Une erreur est survenue lors de l'extraction du style de la review  {0} : {1}", reviewId, message), ErrorLevel.Warning);
                return(false);
            }
        }
Ejemplo n.º 4
0
 public StyleDefinition ConvertToDestFieldDefinition(StyleDefinition fieldDefinition)
 {
     return(fieldDefinition);
 }
        public bool TryParse(string style, int reviewId, ref StyleDefinition fieldDefinition)
        {
            if (string.IsNullOrEmpty(style))
            {
                throw new ArgumentNullException("style");
            }

            var workingStyle = StylesRepository.MusicGenresRepository.ReplaceReplacements(style.Trim(new[] { ',', ' ', '\t', ';', '.' }));

            try
            {
                var musicTypesIdxs = new List<int>();

                //reconnaissances des types de musique
                string beforeTypeString = workingStyle;
                string afterTypeString = null;
                string workingStyleForMusicTypeRecognition = workingStyle;

                int? musicTypeIdx;
                do
                {
                    musicTypeIdx = StylesRepository.TryRecognizeMusicType(ref workingStyleForMusicTypeRecognition, ref beforeTypeString, ref afterTypeString);
                    if (musicTypeIdx.HasValue)
                    {
                        if (!musicTypesIdxs.Contains(musicTypeIdx.Value))
                        {
                            musicTypesIdxs.Add(musicTypeIdx.Value);
                        }
                    }
                } while (musicTypeIdx.HasValue);

                fieldDefinition = new StyleDefinition(musicTypesIdxs);

                var beforeTypeRemainingParts = StylesRepository.IntegrateExistingStylesAndAlterations(beforeTypeString, fieldDefinition, true);
                var afterTypeRemainingParts = StylesRepository.IntegrateExistingStylesAndAlterations(afterTypeString, fieldDefinition, false);

                //Dernière chance pour trouver un type de musique
                if (musicTypesIdxs.Count == 0)
                {
                    var lastChanceMusicType = StylesRepository.GetLastChanceMusicType(fieldDefinition.MainStyles);
                    if (lastChanceMusicType.HasValue)
                    {
                        fieldDefinition.AttachMusicType(lastChanceMusicType.Value);
                    }
                    else if (fieldDefinition.MainStyles.Count > 0)
                    {
                        var message = string.Format("while parsing style '{0}' we can't detect any music genre. We assume that 'Metal' is the main genre of this album", style);
                        Logging.Logging.Instance.LogError(string.Format("A turnaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        fieldDefinition.AttachMusicType(0);
                    }
                    else
                    {
                        var message = string.Format("cannot parse style '{0}' : no existing music type could have been recognized", style);
                        Logging.Logging.Instance.LogError(string.Format("Une erreur est survenue lors de l'extraction du style de la review  {0} : {1}", reviewId, message), ErrorLevel.Warning);
                        return false;
                    }
                }

                // Creation des nouveaux styles
                foreach (var newMainStyle in beforeTypeRemainingParts)
                {
                    try
                    {
                        fieldDefinition.ThrowIfAddMainStyleIsForbidden();
                    }
                    catch (InvalidMusicStyleParsingException)
                    {
                        var message = string.Format("while parsing style '{0}' we detect too many main styles. string '{1}' will be considered as a style alteration", style, newMainStyle);
                        Logging.Logging.Instance.LogError(string.Format("A turnaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        afterTypeRemainingParts.Insert(0, newMainStyle);
                        continue;
                    }
                    fieldDefinition.AddMainStyleIdx(StylesRepository.MainStylesRepository.AddOrRetrieveValueIndex(newMainStyle));
                }

                //Attachement des styles
                if (fieldDefinition.MusicTypes.Count == 1)
                {
                    foreach (var mainStyleIdx in fieldDefinition.MainStylesIdxs)
                    {
                        StyleDefinition.AttachMainStyleToMusicType(mainStyleIdx, fieldDefinition.MusicTypesIdxs[0]);
                    }
                }

                // Creation des nouvelles altérations
                foreach (var newAlteration in afterTypeRemainingParts)
                {
                    try
                    {
                        fieldDefinition.ThrowIfAddStyleAlterationIsForbidden();
                    }
                    catch (InvalidMusicStyleParsingException)
                    {
                        var message = string.Format("while parsing style '{0}' we detect too many style alterations. string '{1}' will be abandonned", style, newAlteration);
                        Logging.Logging.Instance.LogError(string.Format("A workaround will happen on review {0} : {1}", reviewId, message), ErrorLevel.Info);
                        continue;
                    }
                    fieldDefinition.AddStyleAlterationIdx(StylesRepository.StyleAlterationsRepository.AddOrRetrieveValueIndex(newAlteration));
                }

                return true;
            }
            catch (Exception e)
            {
                var message = string.Format("cannot parse style '{0}'\n : {1}", style, e.Message);
                Logging.Logging.Instance.LogError(string.Format("Une erreur est survenue lors de l'extraction du style de la review  {0} : {1}", reviewId, message), ErrorLevel.Warning);
                return false;
            }
        }
 public StyleDefinition ConvertToDestFieldDefinition(StyleDefinition fieldDefinition)
 {
     return fieldDefinition;
 }