public async Task SearchByGeoPointAndRadiusShouldBeSuccessful() { ClarifaiResponse <List <IClarifaiInput> > addInputResponse = await Client.AddInputs( new ClarifaiURLImage( CAT1, positiveConcepts : new List <Concept> { new Concept("cat") }, allowDuplicateUrl : true, geo : new GeoPoint(30, 40))) .ExecuteAsync(); AssertResponseSuccess(addInputResponse); string inputID = addInputResponse.Get()[0].ID; try { await WaitForSpecificInputsUpload(inputID); ClarifaiResponse <SearchInputsResult> response = await Client.SearchInputs(new List <SearchBy> { SearchBy.Geo(new GeoPoint(31, 41), new GeoRadius(1.5M, GeoRadius.RadiusUnit.WithinDegrees)) }) .ExecuteAsync(); AssertResponseSuccess(response); Assert.NotNull(response.Get().SearchHits); } finally { ClarifaiResponse <EmptyResponse> deleteInputResponse = await Client.DeleteInputs(inputID).ExecuteAsync(); AssertResponseSuccess(deleteInputResponse); } }
public async Task SearchByTwoGeoPointsShouldBeSuccessful() { ClarifaiResponse <List <IClarifaiInput> > addInputResponse = await Client.AddInputs( new ClarifaiURLImage( CAT1, positiveConcepts : new List <Concept> { new Concept("cat") }, allowDuplicateUrl : true, geo : new GeoPoint(30, 40))) .ExecuteAsync(); Assert.True(addInputResponse.IsSuccessful); try { ClarifaiResponse <SearchInputsResult> response = await Client.SearchInputs(new List <SearchBy> { SearchBy.Geo(new GeoPoint(29, 39), new GeoPoint(31, 41)) }) .ExecuteAsync(); Assert.True(response.IsSuccessful); Assert.NotNull(response.Get().SearchHits); } finally { string id = addInputResponse.Get()[0].ID; ClarifaiResponse <EmptyResponse> deleteInputResponse = await Client.DeleteInputs(id).ExecuteAsync(); Assert.True(deleteInputResponse.IsSuccessful); } }
public async Task SearchInputsByGeoLocationRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""hits"": [ { ""score"": 0.99, ""input"": { ""id"": ""@inputID"", ""created_at"": ""2016-11-22T17:06:02Z"", ""data"": { ""image"": { ""url"": ""@inputURL"" } }, ""status"": { ""code"": 30000, ""description"": ""Download complete"" } } } ] } "); var client = new ClarifaiClient(httpClient); var response = await client.SearchInputs(SearchBy.Geo(new GeoPoint(1.5M, -1), new GeoRadius(1, GeoRadius.RadiusUnit.WithinKilometers))) .ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""query"": { ""ands"": [ { ""input"": { ""data"": { ""geo"": { ""geo_point"": { ""longitude"": 1.5, ""latitude"": -1.0 }, ""geo_limit"": { ""type"": ""withinKilometers"", ""value"": 1.0 } } } } } ] } }"); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); List <SearchHit> searchHits = response.Get().SearchHits; Assert.AreEqual(1, searchHits.Count); Assert.AreEqual("@inputID", searchHits[0].Input.ID); IClarifaiInput input = searchHits[0].Input; Assert.AreEqual(InputType.Image, input.Type); Assert.AreEqual(InputForm.URL, input.Form); ClarifaiURLImage image = (ClarifaiURLImage)input; Assert.AreEqual("@inputURL", image.URL); }