use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsIT method getProfileWithText.
/**
* Gets the profile with text.
*
* @throws Exception the exception
*/
@Test
public void getProfileWithText() throws Exception {
File file = new File(RESOURCE + "en.txt");
String englishText = getStringFromInputStream(new FileInputStream(file));
ProfileOptions options = new ProfileOptions.Builder().text(englishText).build();
Profile profile = service.profile(options).execute();
Assert.assertNotNull(profile);
Assert.assertNotNull(profile.getProcessedLanguage());
Assert.assertNotNull(profile.getValues());
Assert.assertNotNull(profile.getNeeds());
Assert.assertNotNull(profile.getPersonality());
}
use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsTest method testGetProfileWithContent.
/**
* Test get profile with content.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testGetProfileWithContent() throws InterruptedException {
final Content content = new Content.Builder().addContentItem(contentItem).build();
final ProfileOptions options = new ProfileOptions.Builder().content(content).build();
server.enqueue(jsonResponse(profile));
final Profile profile = service.profile(options).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(PROFILE_PATH + "?version=2016-10-19", request.getPath());
assertEquals("POST", request.getMethod());
assertNotNull(profile);
assertEquals(this.profile, profile);
}
use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsTest method testGetProfileWithEnglishText.
/**
* Test get profile with English text.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testGetProfileWithEnglishText() throws InterruptedException {
final ProfileOptions options = new ProfileOptions.Builder().text(text).contentLanguage(ProfileOptions.ContentLanguage.EN).build();
server.enqueue(jsonResponse(profile));
final Profile profile = service.profile(options).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(PROFILE_PATH + "?version=2016-10-19", request.getPath());
assertEquals("POST", request.getMethod());
assertEquals("en", request.getHeader(HttpHeaders.CONTENT_LANGUAGE));
assertEquals(HttpMediaType.TEXT.toString(), request.getHeader(HttpHeaders.CONTENT_TYPE));
assertEquals(text, request.getBody().readUtf8());
assertNotNull(profile);
assertEquals(this.profile, profile);
}
use of com.walmartlabs.concord.runtime.v2.model.Profile in project java-sdk by watson-developer-cloud.
the class PersonalityInsightsTest method testGetProfileWithSpanishText.
/**
* Test get profile with spanish text.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testGetProfileWithSpanishText() throws InterruptedException {
final ProfileOptions options = new ProfileOptions.Builder().text(text).contentLanguage(ProfileOptions.ContentLanguage.ES).consumptionPreferences(true).rawScores(true).build();
server.enqueue(jsonResponse(profile));
final Profile profile = service.profile(options).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(PROFILE_PATH + "?version=2016-10-19&raw_scores=true&consumption_preferences=true", request.getPath());
assertEquals("POST", request.getMethod());
assertEquals("es", request.getHeader(HttpHeaders.CONTENT_LANGUAGE));
assertEquals(HttpMediaType.TEXT.toString(), request.getHeader(HttpHeaders.CONTENT_TYPE));
assertEquals(text, request.getBody().readUtf8());
assertNotNull(profile);
assertEquals(profile, this.profile);
}
use of com.walmartlabs.concord.runtime.v2.model.Profile in project concord by walmartlabs.
the class Run method call.
@Override
public Integer call() throws Exception {
sourceDir = sourceDir.normalize().toAbsolutePath();
Path targetDir;
if (Files.isRegularFile(sourceDir)) {
Path src = sourceDir.toAbsolutePath();
System.out.println("Running a single Concord file: " + src);
targetDir = Files.createTempDirectory("payload");
Files.copy(src, targetDir.resolve("concord.yml"), StandardCopyOption.REPLACE_EXISTING);
} else if (Files.isDirectory(sourceDir)) {
targetDir = sourceDir.resolve("target");
if (cleanup && Files.exists(targetDir)) {
if (verbose) {
System.out.println("Cleaning target directory");
}
IOUtils.deleteRecursively(targetDir);
}
// copy everything into target except target
IOUtils.copy(sourceDir, targetDir, "^target$", new CopyNotifier(verbose ? 0 : 100), StandardCopyOption.REPLACE_EXISTING);
} else {
throw new IllegalArgumentException("Not a directory or single Concord YAML file: " + sourceDir);
}
DependencyManager dependencyManager = initDependencyManager();
ImportManager importManager = new ImportManagerFactory(dependencyManager, new CliRepositoryExporter(repoCacheDir), Collections.emptySet()).create();
ProjectLoaderV2.Result loadResult;
try {
loadResult = new ProjectLoaderV2(importManager).load(targetDir, new CliImportsNormalizer(importsSource, verbose, defaultVersion), verbose ? new CliImportsListener() : null);
} catch (ImportProcessingException e) {
ObjectMapper om = new ObjectMapper();
System.err.println("Error while processing import " + om.writeValueAsString(e.getImport()) + ": " + e.getMessage());
return -1;
} catch (Exception e) {
System.err.println("Error while loading " + targetDir);
e.printStackTrace();
return -1;
}
ProcessDefinition processDefinition = loadResult.getProjectDefinition();
UUID instanceId = UUID.randomUUID();
if (verbose && !extraVars.isEmpty()) {
System.out.println("Additional variables: " + extraVars);
}
if (verbose && !profiles.isEmpty()) {
System.out.println("Active profiles: " + profiles);
}
ProcessConfiguration cfg = from(processDefinition.configuration()).entryPoint(entryPoint).instanceId(instanceId).build();
RunnerConfiguration runnerCfg = RunnerConfiguration.builder().dependencies(new DependencyResolver(dependencyManager, verbose).resolveDeps(processDefinition)).debug(cfg.debug()).build();
Map<String, Object> profileArgs = getProfilesArguments(processDefinition, profiles);
Map<String, Object> args = ConfigurationUtils.deepMerge(cfg.arguments(), profileArgs, extraVars);
if (verbose) {
System.out.println("Process arguments: " + args);
}
args.put(Constants.Context.TX_ID_KEY, instanceId.toString());
args.put(Constants.Context.WORK_DIR_KEY, targetDir.toAbsolutePath().toString());
if (effectiveYaml) {
Map<String, List<Step>> flows = new HashMap<>(processDefinition.flows());
for (String ap : profiles) {
Profile p = processDefinition.profiles().get(ap);
if (p != null) {
flows.putAll(p.flows());
}
}
ProcessDefinition pd = ProcessDefinition.builder().from(processDefinition).configuration(ProcessDefinitionConfiguration.builder().from(processDefinition.configuration()).arguments(args).build()).flows(flows).imports(Imports.builder().build()).profiles(Collections.emptyMap()).build();
ProjectSerializerV2 serializer = new ProjectSerializerV2();
serializer.write(pd, System.out);
return 0;
}
System.out.println("Starting...");
Injector injector = new InjectorFactory(new WorkingDirectory(targetDir), runnerCfg, () -> cfg, new ProcessDependenciesModule(targetDir, runnerCfg.dependencies(), cfg.debug()), new CliServicesModule(secretStoreDir, targetDir, new VaultProvider(vaultDir, vaultId), dependencyManager)).create();
Runner runner = injector.getInstance(Runner.class);
if (cfg.debug()) {
System.out.println("Available tasks: " + injector.getInstance(TaskProviders.class).names());
}
try {
runner.start(cfg, processDefinition, args);
} catch (Exception e) {
if (verbose) {
System.err.print("Error: ");
e.printStackTrace(System.err);
} else {
System.err.println("Error: " + e.getMessage());
}
return 1;
}
System.out.println("...done!");
return 0;
}
Aggregations