use of com.ibm.watson.compare_comply.v1.model.Location in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testTrainingOperations.
/**
* Test training operations.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testTrainingOperations() throws FileNotFoundException {
String testCollectionId = createTestCollection();
// start by adding images for training
FileWithMetadata giraffeFileZip = new FileWithMetadata.Builder().data(new File(GIRAFFE_POSITIVE_EXAMPLES_PATH)).contentType(HttpMediaType.APPLICATION_ZIP).build();
AddImagesOptions addImagesOptions = new AddImagesOptions.Builder().addImagesFile(giraffeFileZip).collectionId(testCollectionId).build();
ImageDetailsList imageDetailsList = service.addImages(addImagesOptions).execute().getResult();
String imageIdForTraining = null;
Set<String> addedImageIds = new HashSet<>();
for (ImageDetails imageDetails : imageDetailsList.getImages()) {
addedImageIds.add(imageDetails.getImageId());
if (imageIdForTraining == null) {
imageIdForTraining = imageDetails.getImageId();
}
}
try {
Long top = 64L;
Long left = 270L;
Long width = 755L;
Long height = 784L;
Location testLocation = new Location.Builder().top(top).left(left).width(width).height(height).build();
TrainingDataObject trainingDataObject = new TrainingDataObject.Builder().object(GIRAFFE_CLASSNAME).location(testLocation).build();
// test adding training data
AddImageTrainingDataOptions addTrainingDataOptions = new AddImageTrainingDataOptions.Builder().collectionId(testCollectionId).addObjects(trainingDataObject).imageId(imageIdForTraining).build();
TrainingDataObjects trainingDataObjects = service.addImageTrainingData(addTrainingDataOptions).execute().getResult();
assertNotNull(trainingDataObjects);
assertEquals(GIRAFFE_CLASSNAME, trainingDataObjects.getObjects().get(0).object());
assertEquals(top, trainingDataObjects.getObjects().get(0).location().top());
assertEquals(left, trainingDataObjects.getObjects().get(0).location().left());
assertEquals(width, trainingDataObjects.getObjects().get(0).location().width());
assertEquals(height, trainingDataObjects.getObjects().get(0).location().height());
// test train
TrainOptions trainOptions = new TrainOptions.Builder().collectionId(testCollectionId).build();
Collection trainingCollection = service.train(trainOptions).execute().getResult();
assertNotNull(trainingCollection);
assertTrue(trainingCollection.getTrainingStatus().getObjects().inProgress() || trainingCollection.getTrainingStatus().getObjects().ready());
} finally {
// delete images we added earlier
for (String imageId : addedImageIds) {
DeleteImageOptions deleteImageOptions = new DeleteImageOptions.Builder().collectionId(testCollectionId).imageId(imageId).build();
service.deleteImage(deleteImageOptions).execute();
}
deleteTestCollection(testCollectionId);
}
}
use of com.ibm.watson.compare_comply.v1.model.Location in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testAddImageTrainingDataWOptions.
@Test
public void testAddImageTrainingDataWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"objects\": [{\"object\": \"object\", \"location\": {\"top\": 3, \"left\": 4, \"width\": 5, \"height\": 6}}]}";
String addImageTrainingDataPath = "/v4/collections/testString/images/testString/training_data";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the Location model
Location locationModel = new Location.Builder().top(Long.valueOf("26")).left(Long.valueOf("26")).width(Long.valueOf("26")).height(Long.valueOf("26")).build();
// Construct an instance of the TrainingDataObject model
TrainingDataObject trainingDataObjectModel = new TrainingDataObject.Builder().object("testString").location(locationModel).build();
// Construct an instance of the AddImageTrainingDataOptions model
AddImageTrainingDataOptions addImageTrainingDataOptionsModel = new AddImageTrainingDataOptions.Builder().collectionId("testString").imageId("testString").objects(new java.util.ArrayList<TrainingDataObject>(java.util.Arrays.asList(trainingDataObjectModel))).build();
// Invoke operation with valid options model (positive test)
Response<TrainingDataObjects> response = visualRecognitionService.addImageTrainingData(addImageTrainingDataOptionsModel).execute();
assertNotNull(response);
TrainingDataObjects responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, addImageTrainingDataPath);
}
use of com.ibm.watson.compare_comply.v1.model.Location in project synthea by synthetichealth.
the class FhirR4PatientHome method getPatientHome.
/**
* Provides the one and only patient home Location.
* @return a Location resource
*/
public static Location getPatientHome() {
if (patientHome == null) {
patientHome = new Location();
patientHome.setMode(org.hl7.fhir.r4.model.Location.LocationMode.KIND);
patientHome.setStatus(Location.LocationStatus.ACTIVE);
patientHome.setPhysicalType(new CodeableConcept().addCoding(new Coding().setCode(LocationPhysicalType.HO.toCode()).setSystem(LocationPhysicalType.HO.getSystem()).setDisplay(LocationPhysicalType.HO.getDisplay())));
patientHome.setDescription("Patient's Home");
// Not really generating a random UUID. Given that this is not tied to a particular provider
// or person, this just makes up a person with a hardcoded random seed.
patientHome.setId(new Person(1).randUUID().toString());
}
return patientHome;
}
use of com.ibm.watson.compare_comply.v1.model.Location in project metacat by Netflix.
the class S3ConnectorInfoConverter method fromStorageInfo.
/**
* Converts from storage info to s3 location.
* @param storageInfo storage info
* @return location
*/
Location fromStorageInfo(final StorageInfo storageInfo) {
final Location result = new Location();
if (storageInfo != null) {
result.setUri(storageInfo.getUri());
final Info info = new Info();
info.setLocation(result);
info.setOwner(storageInfo.getOwner());
info.setInputFormat(storageInfo.getInputFormat());
info.setOutputFormat(storageInfo.getOutputFormat());
info.setSerializationLib(storageInfo.getSerializationLib());
final Map<String, String> parameters = Maps.newHashMap();
if (storageInfo.getParameters() != null) {
parameters.putAll(storageInfo.getParameters());
}
if (storageInfo.getSerdeInfoParameters() != null) {
parameters.putAll(storageInfo.getSerdeInfoParameters());
}
info.setParameters(parameters);
result.setInfo(info);
}
return result;
}
use of com.ibm.watson.compare_comply.v1.model.Location in project metacat by Netflix.
the class S3ConnectorInfoConverter method fromTableInfo.
@Override
public Table fromTableInfo(final TableInfo tableInfo) {
final Table result = new Table();
result.setName(tableInfo.getName().getTableName());
final Location location = toLocation(tableInfo);
if (location != null) {
result.setLocation(location);
location.setTable(result);
}
return result;
}
Aggregations