use of com.google.cloud.language.v1beta2.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method analyzeEntitiesTest.
@Test
@SuppressWarnings("all")
public void analyzeEntitiesTest() {
String language = "language-1613589672";
AnalyzeEntitiesResponse expectedResponse = AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build();
mockLanguageService.addResponse(expectedResponse);
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitiesResponse actualResponse = client.analyzeEntities(document, encodingType);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0);
Assert.assertEquals(document, actualRequest.getDocument());
Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
use of com.google.cloud.language.v1beta2.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());
}
}
use of com.google.cloud.language.v1beta2.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method annotateTextTest.
@Test
@SuppressWarnings("all")
public void annotateTextTest() {
String language = "language-1613589672";
AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
mockLanguageService.addResponse(expectedResponse);
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
Assert.assertEquals(document, actualRequest.getDocument());
Assert.assertEquals(features, actualRequest.getFeatures());
Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.
the class SwitchboardServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
SwitchboardEditor editor = (SwitchboardEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
// add more properties
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
panel.setAttribute("hideunconnected", (editor.hideUnconnected()) ? "yes" : "no");
panel.setAttribute("rangemin", Integer.toString(editor.getPanelMenuRangeMin()));
panel.setAttribute("rangemax", Integer.toString(editor.getPanelMenuRangeMax()));
panel.setAttribute("type", editor.getSwitchType());
panel.setAttribute("connection", editor.getSwitchManu());
panel.setAttribute("shape", editor.getSwitchShape());
panel.setAttribute("columns", Integer.toString(editor.getColumns()));
panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
log.debug("webserver Switchboard attribs ready");
Element bgColor = new Element("backgroundColor");
if (editor.getBackgroundColor() == null) {
// set to light grey
bgColor.setAttribute("red", Integer.toString(192));
bgColor.setAttribute("green", Integer.toString(192));
bgColor.setAttribute("blue", Integer.toString(192));
} else {
bgColor.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
bgColor.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
bgColor.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
}
panel.addContent(bgColor);
Element text = new Element("text");
text.setAttribute("color", editor.getDefaultTextColor());
text.setAttribute("content", "For now, Switchboards only present buttons in JMRI WebServer.");
panel.addContent(text);
// include switches, Bug: how to delete the old ones?
// call method in SwitchboardEditor
List<BeanSwitch> _switches = editor.getSwitches();
log.debug("SwbServlet N switches: {}", _switches.size());
for (BeanSwitch sub : _switches) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
log.debug("element name: {}", e.getName());
// }
try {
e.setAttribute("label", sub.getNameString());
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
if (sub.getNamedBean() == null) {
e.setAttribute("connected", "false");
log.debug("switch {} NOT connected", sub.getNameString());
} else {
// activate click action via class
e.setAttribute("connected", "true");
}
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
// read shared attribs
e.setAttribute("textcolor", editor.getDefaultTextColor());
e.setAttribute("type", editor.getSwitchType());
e.setAttribute("connection", editor.getSwitchManu());
e.setAttribute("shape", editor.getSwitchShape());
e.setAttribute("columns", Integer.toString(editor.getColumns()));
// process and add
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error reading xml panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested Switchboard [" + name + "] does not exist.");
return "ERROR Requested Switchboard [" + name + "] does not exist.";
}
}
use of com.google.cloud.language.v1beta2.Document in project JMRI by JMRI.
the class ControlPanelServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
ControlPanelEditor editor = (ControlPanelEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
if (editor.getBackgroundColor() != null) {
Element color = new Element("backgroundColor");
color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
panel.addContent(color);
}
// include contents
List<Positionable> contents = editor.getContents();
log.debug("N elements: {}", contents.size());
for (Positionable sub : contents) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
if ("signalmasticon".equals(e.getName())) {
//insert icon details into signalmast
e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
}
try {
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested ControlPanel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
}
}
Aggregations