/** * Adds all of the given {@link SearchClause}s to the request, ANDed with all of the existing clauses. * * @param clauses the clauses to AND with all of your other clauses * @return this request builder */ @NotNull public SearchInputsRequest ands(@NotNull SearchClause... clauses) { return ands(Arrays.asList(clauses)); }
@NotNull @Override public SearchInputsRequest searchInputs(@NotNull List<SearchClause> searchClauses) { return new SearchInputsRequest(this, searchClauses); }
@NotNull @Override protected String subUrl(final int page) { return buildURL("/v2/searches", page); }
@Test public void searchByConceptAndPrediction() { client.searchInputs() // Matches images we tagged as "cat", and that the API tagged as not having "dog" .ands( SearchClause.matchUserTaggedConcept(Concept.forName("cat")), SearchClause.matchConcept(Concept.forName("dog").withValue(false)) ) .getPage(1) .executeSync(); }
@Test public void searchByUserSuppliedConcept() { // Search concept by name client.searchInputs(SearchClause.matchUserTaggedConcept(Concept.forName("cat"))) .getPage(1) .executeSync(); // Search concept by ID client.searchInputs(SearchClause.matchUserTaggedConcept(Concept.forID("ai_mFqxrph2"))) .getPage(1) .executeSync(); // Search multiple concepts client.searchInputs(SearchClause.matchUserTaggedConcept(Concept.forID("cat"))) .and(SearchClause.matchUserTaggedConcept(Concept.forID("cute"))) .getPage(1) .executeSync(); // Search NOT by concept client.searchInputs(SearchClause.matchUserTaggedConcept(Concept.forID("cat").withValue(false))) .getPage(1) .executeSync(); }
@Test public void searchByReverseImage() { // Search by image (image URL represented by: String or java.net.URL) client.searchInputs(SearchClause.matchImageVisually(ClarifaiImage.of("@@sampleTrain"))) .getPage(1) .executeSync(); // Search by image (image represented by: java.io.File or byte[]) client.searchInputs(SearchClause.matchImageVisually(ClarifaiImage.of(new File("image.png")))) .getPage(1) .executeSync(); }
@NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { Search.Query.Builder searchBuilder = Search.Query.newBuilder(); for (SearchClause andClause : andClauses) { searchBuilder.addAnds(andClause.serialize()); } if (language != null) { searchBuilder.setLanguage(language); } return stub(page).postSearches(Search.PostSearchesRequest.newBuilder().setQuery(searchBuilder).build()); } }
@Retry @Test public void t17d_searchInputsWithModel_multi_language() { assertSuccess(client.searchInputs( SearchClause.matchImageURL(ClarifaiImage.of(METRO_NORTH_IMAGE_URL))).withLanguage("zh")); }
@Test public void searchByConcept() { client.searchInputs(SearchClause.matchConcept(Concept.forName("dress"))) .build() .getPage(1) .executeSync(); }
@Test public void t17e_searchInputsWithModel_geo() { assertSuccess(client.addInputs().plus( ClarifaiInput.forImage(METRO_NORTH_IMAGE_URL) .withGeo(PointF.at(90F, 23F)) )); assertSuccess( client.searchInputs(matchConcept(Concept.forID("outdoors23").withValue(true))) .and(SearchClause.matchImageURL(ClarifaiImage.of(METRO_NORTH_IMAGE_URL))) .and(SearchClause.matchGeo(PointF.at(90F, 23F), Radius.of(5, Radius.Unit.MILE))) .build() ); }
@Test public void searchByPredictedConcepts() { // Search concept by name client.searchInputs(SearchClause.matchConcept(Concept.forName("cat"))) .getPage(1) .executeSync(); // Search concept by ID client.searchInputs(SearchClause.matchConcept(Concept.forID("ai_mFqxrph2"))) .getPage(1) .executeSync(); // Search multiple concepts client.searchInputs(SearchClause.matchConcept(Concept.forID("cat"))) .and(SearchClause.matchConcept(Concept.forID("cute"))) .getPage(1) .executeSync(); // Search NOT by concept client.searchInputs(SearchClause.matchConcept(Concept.forID("cat").withValue(false))) .getPage(1) .executeSync(); }
@Test public void reverseImageSearch() { client.searchInputs(SearchClause.matchImageVisually(ClarifaiImage.of("http://i.imgur.com/HEoT5xR.png"))) .getPage(1) .executeSync(); }
@Test public void quickStartSearch() { final ClarifaiResponse<SearchInputsResult> trainImages = client.searchInputs( // Finds images that match this picture of a train OR images that match the "train" concept tag SearchClause.matchImageVisually(ClarifaiImage.of("@@sampleTrain")) ) .getPage(1) .executeSync(); }
@Test public void searchMatchURL() { // Lookup images with this URL client.searchInputs(SearchClause.matchImageURL(ClarifaiImage.of(""))) .getPage(1) .executeSync(); }
@Test public void allDataShouldBeExposedAndNotNull() { SearchInputsRequest request = client.searchInputs(SearchClause.matchImageURL( ClarifaiImage.of(imageWithNoSearchHits))); ClarifaiResponse<SearchInputsResult> response = request.getPage(1).executeSync(); assertNotNull(response.get().id()); assertNotNull(response.getStatus()); assertNotNull(response.get().searchHits()); } }