Search in sources :

Example 86 with Document

use of org.jdom2.Document in project k-9 by k9mail.

the class SettingsExporterTest method exportPreferences.

private Document exportPreferences(boolean globalSettings, Set<String> accounts) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    SettingsExporter.exportPreferences(RuntimeEnvironment.application, outputStream, globalSettings, accounts);
    Document document = parseXML(outputStream.toByteArray());
    outputStream.close();
    return document;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom2.Document)

Example 87 with Document

use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.

the class AnalyzeSentiment method main.

public static void main(String... args) throws Exception {
    // Instantiates a client
    LanguageServiceClient language = LanguageServiceClient.create();
    // The text to analyze
    String[] texts = { "I love this!", "I hate this!" };
    for (String text : texts) {
        Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();
        // Detects the sentiment of the text
        Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();
        System.out.printf("Text: \"%s\"%n", text);
        System.out.printf("Sentiment: score = %s, magnitude = %s%n", sentiment.getScore(), sentiment.getMagnitude());
    }
}
Also used : LanguageServiceClient(com.google.cloud.language.spi.v1.LanguageServiceClient) Document(com.google.cloud.language.v1.Document) Sentiment(com.google.cloud.language.v1.Sentiment)

Example 88 with Document

use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeEntitySentimentTest.

@Test
@SuppressWarnings("all")
public void analyzeEntitySentimentTest() {
    String language = "language-1613589672";
    AnalyzeEntitySentimentResponse expectedResponse = AnalyzeEntitySentimentResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    EncodingType encodingType = EncodingType.NONE;
    AnalyzeEntitySentimentResponse actualResponse = client.analyzeEntitySentiment(document, encodingType);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnalyzeEntitySentimentRequest actualRequest = (AnalyzeEntitySentimentRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
    Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Also used : AnalyzeEntitySentimentRequest(com.google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest) EncodingType(com.google.cloud.language.v1beta2.EncodingType) Document(com.google.cloud.language.v1beta2.Document) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) AnalyzeEntitySentimentResponse(com.google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse) Test(org.junit.Test)

Example 89 with Document

use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSentimentTest.

@Test
@SuppressWarnings("all")
public void analyzeSentimentTest() {
    String language = "language-1613589672";
    AnalyzeSentimentResponse expectedResponse = AnalyzeSentimentResponse.newBuilder().setLanguage(language).build();
    mockLanguageService.addResponse(expectedResponse);
    Document document = Document.newBuilder().build();
    AnalyzeSentimentResponse actualResponse = client.analyzeSentiment(document);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnalyzeSentimentRequest actualRequest = (AnalyzeSentimentRequest) actualRequests.get(0);
    Assert.assertEquals(document, actualRequest.getDocument());
}
Also used : AnalyzeSentimentResponse(com.google.cloud.language.v1beta2.AnalyzeSentimentResponse) Document(com.google.cloud.language.v1beta2.Document) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) AnalyzeSentimentRequest(com.google.cloud.language.v1beta2.AnalyzeSentimentRequest) Test(org.junit.Test)

Example 90 with Document

use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.

the class LanguageServiceClientTest method analyzeSentimentExceptionTest.

@Test
@SuppressWarnings("all")
public void analyzeSentimentExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLanguageService.addException(exception);
    try {
        Document document = Document.newBuilder().build();
        client.analyzeSentiment(document);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) Document(com.google.cloud.language.v1beta2.Document) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)86 Element (org.jdom2.Element)76 Test (org.junit.Test)33 File (java.io.File)29 DocType (org.jdom2.DocType)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 IOException (java.io.IOException)16 XMLOutputter (org.jdom2.output.XMLOutputter)15 ProcessingInstruction (org.jdom2.ProcessingInstruction)13 XmlFile (jmri.jmrit.XmlFile)11 Document (com.google.cloud.language.v1beta2.Document)10 ApiException (com.google.api.gax.grpc.ApiException)9 Document (com.google.cloud.language.v1.Document)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 ArrayList (java.util.ArrayList)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 FileOutputStream (java.io.FileOutputStream)8 JLabel (javax.swing.JLabel)7 EncodingType (com.google.cloud.language.v1.EncodingType)6