示例#1
0
        public static void WhenCaptionsAreComplexThenDescriptionDoesntChange(Caption caption, Description.Arguments arguments, string expectedDescription)
        {
            string actualDescription = Description.Get(caption, arguments);

            Assert.Equal(expectedDescription, actualDescription);
        }
示例#2
0
        public static void DescriptionsAreGenderNeutral(Caption caption, Description.Arguments arguments, string expectedDescription)
        {
            string actualDescription = Description.Get(caption, arguments);

            Assert.Equal(expectedDescription, actualDescription);
        }
示例#3
0
        public static void WhenCaptionIncludesPeopleThenDescriptionAddsArtQualifier(Caption caption, Description.Arguments arguments, string expectedDescription)
        {
            string actualDescription = Description.Get(caption, arguments);

            Assert.Equal(expectedDescription, actualDescription);
        }
示例#4
0
        public static void WhenCaptionsAreSimpleAndItemIsOldAndBlackAndWhiteThenDescriptionHasOld(Caption caption, Description.Arguments arguments, string expectedDescription)
        {
            string actualDescription = Description.Get(caption, arguments);

            Assert.Equal(expectedDescription, actualDescription);
        }
示例#5
0
        public static void WhenCaptionsAreSimpleThenDescriptionHasColor(Caption caption, Description.Arguments arguments, string expectedDescription)
        {
            string actualDescription = Description.Get(caption, arguments);

            Assert.Equal(expectedDescription, actualDescription);
        }
        public static string Get(Caption caption, Arguments arguments)
        {
            // Filter and adjust the caption
            string descriptionText = caption.Text;

            string[] stringsToRemove =
            {
                "a close up of ",
                " that is sitting on a table",
                " sitting on a table",
                " sitting on a counter",
                " on a table",
                "a vintage photo of ",
                " sitting on top of a table",
            };

            foreach (string text in stringsToRemove)
            {
                descriptionText = descriptionText.Replace(text, "");
            }

            // Capitalize the first letter
            descriptionText = char.ToUpper(descriptionText[0]) + descriptionText.Substring(1);

            string[] commonSimpleDescriptions =
            {
                "A vase",
                "A bowl",
                "A plate",
                "A knife",
                "A clock",
                "A cup of coffee",
                "A bird",
                "A tool",
                "A weapon",
                "A gun",
                "A logo",
                "A box",
                "A sign",
                "A envelope",
                "A pot",
                "A book",
                "A phone",
            };

            bool isSimple = commonSimpleDescriptions.Contains(descriptionText);

            if (isSimple)
            {
                if (arguments.isBlackAndWhite)
                {
                    if (arguments.isOld)
                    {
                        descriptionText = "An old " + descriptionText.Substring(2);
                        System.Console.WriteLine("Added 'old' to simple description");
                    }
                    else
                    {
                        // TODO: Do something clever here?
                        // I don't want to add a color here since I know the image is black and white.
                        // This might be pretty rare since black and white images are often old
                        System.Console.WriteLine("Description was simple but not old. Leaving simple description.");
                    }
                }
                else
                {
                    string color = arguments.foregroundColor.ToLower();
                    descriptionText = descriptionText.Substring(0, 2) + color + " " + descriptionText.Substring(2);
                    System.Console.WriteLine("Added color to simple description: " + color);
                }
            }

            descriptionText = NeutralizeGender(descriptionText);

            if (descriptionText.StartsWith("A person") || descriptionText.StartsWith("A group of people"))
            {
                if (arguments.isPainting)
                {
                    descriptionText = "A painting of a " + descriptionText.Substring(2);
                }
                else if (arguments.isPhoto)
                {
                    descriptionText = "A photo of a " + descriptionText.Substring(2);
                }
                else if (arguments.isSign)
                {
                    descriptionText = "A print of a " + descriptionText.Substring(2);
                }
                else
                {
                    descriptionText = "A statue of a " + descriptionText.Substring(2);
                }
            }

            return(descriptionText);
        }