use of com.google.cloud.language.v1.Document in project beam by apache.
the class AnnotateTextIT method analyzesLanguage.
@Test
public void analyzesLanguage() {
Document doc = Document.newBuilder().setContent(TEST_STRING).setType(Document.Type.PLAIN_TEXT).build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().setExtractSyntax(true).build();
PCollection<AnnotateTextResponse> responses = testPipeline.apply(Create.of(doc)).apply(AnnotateText.newBuilder().setFeatures(features).build());
PAssert.that(responses).satisfies(new VerifyTextAnnotationResult());
testPipeline.run().waitUntilFinish();
}
use of com.google.cloud.language.v1.Document in project beam by apache.
the class FirestoreV1FnRunQueryTest method resumeFromLastReadValue.
@Override
public void resumeFromLastReadValue() throws Exception {
TestData testData = TestData.fieldEqualsBar().setProjectId(projectId).setOrderFunction(f -> Collections.singletonList(Order.newBuilder().setDirection(Direction.ASCENDING).setField(f).build())).build();
RunQueryRequest request2 = RunQueryRequest.newBuilder().setParent(String.format("projects/%s/databases/(default)/document", projectId)).setStructuredQuery(testData.request.getStructuredQuery().toBuilder().setStartAt(Cursor.newBuilder().setBefore(false).addValues(Value.newBuilder().setStringValue("bar")))).build();
List<RunQueryResponse> responses = ImmutableList.of(testData.response1, testData.response2, testData.response3);
when(responseStream1.iterator()).thenReturn(new AbstractIterator<RunQueryResponse>() {
private int invocationCount = 1;
@Override
protected RunQueryResponse computeNext() {
int count = invocationCount++;
if (count == 1) {
return responses.get(0);
} else if (count == 2) {
return responses.get(1);
} else {
throw RETRYABLE_ERROR;
}
}
});
when(callable.call(testData.request)).thenReturn(responseStream1);
doNothing().when(attempt).checkCanRetry(any(), eq(RETRYABLE_ERROR));
when(responseStream2.iterator()).thenReturn(ImmutableList.of(responses.get(2)).iterator());
when(callable.call(request2)).thenReturn(responseStream2);
when(stub.runQueryCallable()).thenReturn(callable);
when(ff.getFirestoreStub(any())).thenReturn(stub);
when(ff.getRpcQos(any())).thenReturn(rpcQos);
when(rpcQos.newReadAttempt(any())).thenReturn(attempt);
when(attempt.awaitSafeToProceed(any())).thenReturn(true);
ArgumentCaptor<RunQueryResponse> responsesCaptor = ArgumentCaptor.forClass(RunQueryResponse.class);
doNothing().when(processContext).output(responsesCaptor.capture());
when(processContext.element()).thenReturn(testData.request);
RunQueryFn fn = new RunQueryFn(clock, ff, rpcQosOptions);
runFunction(fn);
List<RunQueryResponse> allValues = responsesCaptor.getAllValues();
assertEquals(responses, allValues);
verify(callable, times(1)).call(testData.request);
verify(callable, times(1)).call(request2);
verify(attempt, times(3)).recordStreamValue(any());
}
use of com.google.cloud.language.v1.Document in project beam by apache.
the class FirestoreTestingHelper method listDocumentsViaQuery.
Stream<String> listDocumentsViaQuery(String collectionPath) {
int index = collectionPath.lastIndexOf('/');
String parent = collectionPath.substring(0, index);
String collectionId = collectionPath.substring(index + 1);
FieldReference nameField = FieldReference.newBuilder().setFieldPath("__name__").build();
RunQueryRequest rqr = RunQueryRequest.newBuilder().setParent(parent).setStructuredQuery(StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId(collectionId)).addOrderBy(Order.newBuilder().setField(nameField).setDirection(Direction.ASCENDING).build()).setSelect(Projection.newBuilder().addFields(nameField).build())).build();
return StreamSupport.stream(rpc.runQueryCallable().call(rqr).spliterator(), false).filter(RunQueryResponse::hasDocument).map(RunQueryResponse::getDocument).map(Document::getName);
}
use of com.google.cloud.language.v1.Document in project aws-doc-sdk-examples by awsdocs.
the class SendNotifications method handleEmailMessage.
public String handleEmailMessage(String myDom) throws JDOMException, IOException, MessagingException {
String myEmail = "";
SesClient client = SesClient.builder().region(Region.US_EAST_1).build();
SAXBuilder builder = new SAXBuilder();
Document jdomDocument = builder.build(new InputSource(new StringReader(myDom)));
org.jdom2.Element root = jdomDocument.getRootElement();
// Get the list of children elements.
List<org.jdom2.Element> students = root.getChildren("Student");
for (org.jdom2.Element element : students) {
myEmail = element.getChildText("Email");
sendEmailMessage(client, myEmail);
}
client.close();
return myEmail;
}
use of com.google.cloud.language.v1.Document in project aws-doc-sdk-examples by awsdocs.
the class SendNotifications method handleTextMessage.
public String handleTextMessage(String myDom) throws JDOMException, IOException {
String mobileNum = "";
SnsClient snsClient = SnsClient.builder().region(Region.US_EAST_1).build();
SAXBuilder builder = new SAXBuilder();
Document jdomDocument = builder.build(new InputSource(new StringReader(myDom)));
org.jdom2.Element root = jdomDocument.getRootElement();
// get the list of children agent elements.
List<org.jdom2.Element> students = root.getChildren("Student");
for (org.jdom2.Element element : students) {
mobileNum = element.getChildText("Mobile");
publishTextSMS(snsClient, mobileNum);
}
snsClient.close();
return mobileNum;
}
Aggregations