Beispiel #1
0
        public void SubmitVisionJobTest()
        {
            string         jobId    = visionJob.JobId;
            VisionSettings settings = visionJob.Settings;
            var            response = instance.SubmitVisionJob(jobId, settings);

            Assert.IsInstanceOf <VisionJob>(response, "response is VisionJob");
            Assert.AreEqual("PROCESSING", response.State.ToString());
        }
Beispiel #2
0
 public static async Task InitializeAsync()
 {
     try
     {
         if (settings == null)
         {
             var settingsProvider = ServiceLocator.Current.GetInstance <IVisionSettingsProvider>();
             settings = await settingsProvider.GetSettingsAsync();
         }
     }
     catch { }
 }
Beispiel #3
0
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            SimpleIoc.Default.Register <CognitiveClient>(() =>
            {
                VisionSettings visionSettings = null;
                using (var stream = typeof(ViewModelLocator).GetTypeInfo().Assembly.GetManifestResourceStream(Constants.VisionSettingsFile))
                {
                    using (var reader = new StreamReader(stream))
                        visionSettings = JsonConvert.DeserializeObject <VisionSettings>(reader.ReadToEnd());
                }

                var visionSettingsProvider = new SimpleVisionSettingsProvider(visionSettings);
                var cognitiveClient        = new CognitiveClient(visionSettingsProvider);

                var cognitiveSettings = cognitiveClient.Settings;
                cognitiveSettings.EmotionSubscriptionKey    = ServiceKeys.EmotionSubscriptionKey;
                cognitiveSettings.VisionSubscriptionKey     = ServiceKeys.VisionSubscriptionKey;
                cognitiveSettings.FaceSubscriptionKey       = ServiceKeys.FaceSubscriptionKey;
                cognitiveSettings.TranslatorSubscriptionKey = ServiceKeys.TranslatorSubscriptionKey;

                return(cognitiveClient);
            });

            SimpleIoc.Default.Register <ISpeechService>(() =>
            {
                var language = GetLanguage();
                var service  = new SpeechService {
                    Language = language
                };
                return(service);
            });

            SimpleIoc.Default.Register <Services.IDialogService, Services.DialogService>();
            SimpleIoc.Default.Register <IStreamingService, StreamingService>();
            SimpleIoc.Default.Register <ISettingsService, SettingsService>();
            SimpleIoc.Default.Register <INetworkService, NetworkService>();
            SimpleIoc.Default.Register <ILauncherService, LauncherService>();
            SimpleIoc.Default.Register <IAppService, AppService>();
            SimpleIoc.Default.Register <IMediaPicker, MediaPicker>();

            SimpleIoc.Default.Register <MainViewModel>();
            SimpleIoc.Default.Register <SettingsViewModel>();
            SimpleIoc.Default.Register <AboutViewModel>();
            SimpleIoc.Default.Register <RecognizeTextViewModel>();
            SimpleIoc.Default.Register <PrivacyViewModel>();

            OnInitialize();
        }
Beispiel #4
0
        public void CreateVisionJobTest()
        {
            VisionSettings visionSettings = new VisionSettings();

            visionSettings.Vendor = VisionSettings.VendorEnum.GOOGLEVISION;
            List <VisionSettings.DetectionTypesEnum> detectionTypes = new List <VisionSettings.DetectionTypesEnum>();

            detectionTypes.Add(VisionSettings.DetectionTypesEnum.LABEL);
            visionSettings.DetectionTypes  = detectionTypes;
            visionSettings.StorageProvider = VisionSettings.StorageProviderEnum.SUPPLIER;

            visionJob = instance.CreateVisionJob(visionSettings);
            Assert.IsInstanceOf <VisionJob> (visionJob, "response is VisionJob");
            Assert.AreEqual("UPLOADRESOURCES", visionJob.State.ToString());
        }
Beispiel #5
0
        public static bool IsValid(this AnalysisResult result, out Caption rawDescription, out Caption filteredDescription, VisionSettings settings = null)
        {
            rawDescription      = result.Description.Captions.FirstOrDefault();
            filteredDescription = null;

            // If there is no settings, all the descriptions are valid.
            if (settings == null)
            {
                filteredDescription = rawDescription;
                return(true);
            }

            if (rawDescription?.Confidence >= settings.MinimumConfidence)
            {
                var text         = rawDescription.Text;
                var replacedText = settings.DescriptionsToReplace.FirstOrDefault(d => d.Key.EqualsIgnoreCase(text)).Value;

                if (!string.IsNullOrWhiteSpace(replacedText))
                {
                    text = replacedText;
                }

                var textToRemove = settings.DescriptionsToRemove.FirstOrDefault(d => text.ContainsIgnoreCase(d));
                var filteredText = !string.IsNullOrWhiteSpace(textToRemove) ? text.ReplaceIgnoreCase(textToRemove, string.Empty).Trim() : text;

                if (!settings.InvalidDescriptions.Any(d => filteredText.ContainsIgnoreCase(d)))
                {
                    filteredDescription = new Caption
                    {
                        Text       = filteredText,
                        Confidence = rawDescription.Confidence
                    };

                    return(true);
                }
            }

            return(false);
        }
Beispiel #6
0
        public static bool IsValid(this AnalysisResult result, out Caption rawDescription, out Caption filteredDescription, VisionSettings settings = null)
        {
            rawDescription      = result.Description.Captions.FirstOrDefault();
            filteredDescription = null;

            // If there is no settings, all the descriptions are valid.
            if (settings == null)
            {
                filteredDescription = rawDescription;
                return(true);
            }

            if (rawDescription?.Confidence >= settings.MinimumConfidence)
            {
                var text         = rawDescription.Text;
                var replacedText = settings.DescriptionsToReplace.FirstOrDefault(d => text.StartsWithIgnoreCase(d.Key));

                if (!string.IsNullOrWhiteSpace(replacedText.Key))
                {
                    // Checks whether to replace or substitute the text.
                    if (text.EqualsIgnoreCase(replacedText.Key))
                    {
                        text = replacedText.Value;
                    }
                    else
                    {
                        text = text.ReplaceIgnoreCase(replacedText.Key, replacedText.Value).Trim();
                    }
                }

                var textToRemove = settings.DescriptionsToRemove.FirstOrDefault(d => text.ContainsIgnoreCase(d));
                var filteredText = !string.IsNullOrWhiteSpace(textToRemove) ? text.ReplaceIgnoreCase(textToRemove, string.Empty).Trim() : text;
                filteredText = char.ToUpper(filteredText[0]) + filteredText.Substring(1);

                if (!settings.InvalidDescriptions.Any(d => filteredText.ContainsIgnoreCase(d)))
                {
                    filteredDescription = new Caption
                    {
                        Text       = filteredText,
                        Confidence = rawDescription.Confidence
                    };

                    return(true);
                }
            }

            return(false);
        }
Beispiel #7
0
        public static bool IsValid(this AnalysisResult result, out Caption rawDescription, out Caption filteredDescription, VisionSettings settings = null)
        {
            rawDescription      = result.Description.Captions.FirstOrDefault();
            filteredDescription = null;

            var detailNode = result.Categories.FirstOrDefault()?.Detail;

            if (detailNode != null)
            {
                // Retrieves landmarks name and confidence, if any.
                var details   = JToken.Parse(detailNode.ToString());
                var landmarks = details["landmarks"];
                if (landmarks.Any())
                {
                    var name       = landmarks[0]["name"]?.Value <string>();
                    var confidence = landmarks[0]["confidence"]?.Value <double>();

                    if (name != null && confidence.GetValueOrDefault() > settings?.MinimumConfidence)
                    {
                        filteredDescription = new Caption
                        {
                            Text       = name,
                            Confidence = confidence.Value
                        };

                        return(true);
                    }
                }
            }

            // If there is no settings, all the descriptions are valid.
            if (settings == null)
            {
                filteredDescription = rawDescription;
                return(true);
            }

            if (rawDescription?.Confidence >= settings.MinimumConfidence)
            {
                var text         = rawDescription.Text;
                var replacedText = settings.DescriptionsToReplace.FirstOrDefault(d => text.StartsWithIgnoreCase(d.Key));

                if (!string.IsNullOrWhiteSpace(replacedText.Key))
                {
                    // Checks whether to replace or substitute the text.
                    if (text.EqualsIgnoreCase(replacedText.Key))
                    {
                        text = replacedText.Value;
                    }
                    else
                    {
                        text = text.ReplaceIgnoreCase(replacedText.Key, replacedText.Value).Trim();
                    }
                }

                var textToRemove = settings.DescriptionsToRemove.FirstOrDefault(d => text.ContainsIgnoreCase(d));
                var filteredText = !string.IsNullOrWhiteSpace(textToRemove) ? text.ReplaceIgnoreCase(textToRemove, string.Empty).Trim() : text;
                filteredText = char.ToUpper(filteredText[0]) + filteredText.Substring(1);

                if (!settings.InvalidDescriptions.Any(d => filteredText.ContainsIgnoreCase(d)))
                {
                    filteredDescription = new Caption
                    {
                        Text       = filteredText,
                        Confidence = rawDescription.Confidence
                    };

                    return(true);
                }
            }

            return(false);
        }