def test_search_by_image_url_and_geo_box(channel): stub = service_pb2_grpc.V2Stub(channel) with SetupImage(stub) as input_: response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(ranks=[ Rank(annotation=Annotation(data=Data(image=Image( url=DOG_IMAGE_URL)))), Rank(annotation=Annotation(data=Data( geo=resources_pb2.Geo(geo_box=[ resources_pb2.GeoBoxedPoint( geo_point=resources_pb2.GeoPoint( longitude=43, latitude=54)), resources_pb2.GeoBoxedPoint( geo_point=resources_pb2.GeoPoint( longitude=45, latitude=56)), ])))), ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert len(response.hits) >= 1 assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_predicted_concept_name(channel): stub = service_pb2_grpc.V2Stub(channel) with SetupImage(stub) as input_: response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(ranks=[ Rank(annotation=Annotation(data=Data( concepts=[Concept(name="dog", value=1)]))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert len(response.hits) >= 1 assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_custom_concept_name(channel): stub = service_pb2_grpc.V2Stub(channel) with SetupImage(stub) as input_: concept_name = input_.data.concepts[0].name response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(filters=[ Filter(annotation=Annotation(data=Data( concepts=[Concept(name=concept_name, value=1)]))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_image_url(channel): stub = service_pb2_grpc.V2Stub(channel) with SetupImage(stub) as input_: response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(ranks=[ Rank(annotation=Annotation(data=Data(image=Image( url=DOG_IMAGE_URL)))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert len(response.hits) >= 1 assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_metadata(channel): stub = service_pb2_grpc.V2Stub(channel) search_metadata = struct_pb2.Struct() search_metadata.update({"another-key": {"inner-key": "inner-value"}}) with SetupImage(stub) as input_: response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(ranks=[ Rank(annotation=Annotation(data=Data( metadata=search_metadata))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert len(response.hits) >= 1 assert input_.id in [hit.input.id for hit in response.hits]
def test_search_by_geo_point_and_limit(channel): stub = service_pb2_grpc.V2Stub(channel) with SetupImage(stub) as input_: response = stub.PostInputsSearches( PostInputsSearchesRequest( searches=[ Search(query=Query(ranks=[ Rank(annotation=Annotation(data=Data( geo=resources_pb2.Geo( geo_point=resources_pb2.GeoPoint(longitude=43, latitude=56), geo_limit=resources_pb2.GeoLimit( value=1000, type="withinKilometers"), )))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(response) assert len(response.hits) >= 1 assert input_.id in [hit.input.id for hit in response.hits]
def test_post_annotations_searches(channel): stub = service_pb2_grpc.V2Stub(channel) palm_search_response = stub.PostConceptsSearches( service_pb2.PostConceptsSearchesRequest( concept_query=resources_pb2.ConceptQuery(name="palm")), metadata=metadata(), ) raise_on_failure(palm_search_response) palm_concept_id = palm_search_response.concepts[0].id water_search_response = stub.PostConceptsSearches( service_pb2.PostConceptsSearchesRequest( concept_query=resources_pb2.ConceptQuery(name="water")), metadata=metadata(), ) raise_on_failure(water_search_response) water_concept_id = water_search_response.concepts[0].id with SetupImage(stub) as input_: post_palm_annotations_response = stub.PostAnnotations( service_pb2.PostAnnotationsRequest(annotations=[ resources_pb2.Annotation( input_id=input_.id, data=resources_pb2.Data(regions=[ resources_pb2.Region( region_info=resources_pb2.RegionInfo( bounding_box=resources_pb2.BoundingBox( top_row=0, left_col=0, bottom_row=0.45, right_col=1)), data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=palm_concept_id, value=1) ]), ), ]), ), ]), metadata=metadata(), ) raise_on_failure(post_palm_annotations_response) post_water_annotations_response = stub.PostAnnotations( service_pb2.PostAnnotationsRequest(annotations=[ resources_pb2.Annotation( input_id=input_.id, data=resources_pb2.Data(regions=[ resources_pb2.Region( region_info=resources_pb2.RegionInfo( bounding_box=resources_pb2.BoundingBox( top_row=0.6, left_col=0, bottom_row=1, right_col=0.98)), data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=water_concept_id, value=1) ]), ), ]), ), ]), metadata=metadata(), ) raise_on_failure(post_water_annotations_response) post_palm_annotations_searches_response = stub.PostAnnotationsSearches( service_pb2.PostAnnotationsSearchesRequest( searches=[ Search(query=resources_pb2.Query(filters=[ resources_pb2.Filter( annotation=resources_pb2.Annotation( data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=palm_concept_id, value=1) ]))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(post_palm_annotations_searches_response) assert input_.id in [ hit.input.id for hit in post_palm_annotations_searches_response.hits ] post_water_annotations_searches_response = stub.PostAnnotationsSearches( service_pb2.PostAnnotationsSearchesRequest( searches=[ Search(query=resources_pb2.Query(filters=[ resources_pb2.Filter( annotation=resources_pb2.Annotation( data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=water_concept_id, value=1) ]))) ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(post_water_annotations_searches_response) assert input_.id in [ hit.input.id for hit in post_water_annotations_searches_response.hits ] post_palm_and_water_annotations_searches_response = stub.PostAnnotationsSearches( service_pb2.PostAnnotationsSearchesRequest( searches=[ Search(query=resources_pb2.Query(filters=[ resources_pb2.Filter( annotation=resources_pb2.Annotation( data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=palm_concept_id, value=1) ])), ), resources_pb2.Filter( annotation=resources_pb2.Annotation( data=resources_pb2.Data(concepts=[ resources_pb2.Concept(id=water_concept_id, value=1) ]))), ])) ], pagination=service_pb2.Pagination(page=1, per_page=1000), ), metadata=metadata(), ) raise_on_failure(post_palm_and_water_annotations_searches_response) # No single annotation can have two concepts, so this will return false. assert len(post_palm_and_water_annotations_searches_response.hits) == 0