use of annis.service.objects.RawTextWrapper in project ANNIS by korpling.
the class QueryServiceImpl method getRawText.
/**
* Fetches the raw text from the text.tab file.
*
* @param top the name of the top level corpus.
* @param docname the name of the document.
*
* @return Can be empty, if the corpus only contains media data or
* segmentations.
*/
@GET
@Path("rawtext/{top}/{docname}")
@Produces(MediaType.APPLICATION_XML)
public RawTextWrapper getRawText(@PathParam("top") String top, @PathParam("docname") String docname) {
Subject user = SecurityUtils.getSubject();
user.checkPermission("query:raw_text:" + top);
RawTextWrapper result = new RawTextWrapper();
result.setTexts(queryDao.getRawText(top, docname));
return result;
}
use of annis.service.objects.RawTextWrapper in project ANNIS by korpling.
the class Helper method getRawText.
public static RawTextWrapper getRawText(String corpusName, String documentName) {
RawTextWrapper texts = null;
try {
WebResource webResource = getAnnisWebResource();
webResource = webResource.path("query").path("rawtext").path(corpusName).path(documentName);
texts = webResource.get(RawTextWrapper.class);
} catch (UniformInterfaceException | ClientHandlerException ex) {
log.error("can not retrieve raw text");
if (!AnnisBaseUI.handleCommonError(ex, "retrieve raw text")) {
Notification.show("can not retrieve raw text", ex.getLocalizedMessage(), Notification.Type.WARNING_MESSAGE);
}
}
return texts;
}
use of annis.service.objects.RawTextWrapper in project ANNIS by korpling.
the class RawTextVisualizer method createComponent.
@Override
public Panel createComponent(VisualizerInput visInput, VisualizationToggle visToggle) {
// get config for alignment
boolean vertical = Boolean.parseBoolean(visInput.getMappings().getProperty("vertical", "true"));
// get the texts
RawTextWrapper texts = visInput.getRawText();
// create the main panel
Panel p = new Panel();
p.setSizeFull();
// some layout configuration
p.addStyleName(ChameleonTheme.PANEL_BORDERLESS);
p.addStyleName(PANEL_CLASS);
// enable webfonts
p.addStyleName(Helper.CORPUS_FONT_FORCE);
Layout l;
// if no text available inform user and exit
if (texts == null) {
Label text = new Label(NO_TEXT);
text.addStyleName(LABEL_CLASS);
text.setSizeFull();
p.setContent(text);
return p;
}
if (texts.hasMultipleTexts()) {
// set the aligmnent
if (vertical) {
l = new VerticalLayout();
} else {
l = new GridLayout(texts.getTexts().size(), 1);
}
// limit the size to the parent panel.
l.setSizeFull();
// add the texts to the layout
for (int i = 0; i < texts.getTexts().size(); i++) {
String s = texts.getTexts().get(i);
Label lblText;
// check if the text is empty
if (s == null || hasOnlyWhiteSpace(s)) {
lblText = new Label(NO_TEXT);
} else {
lblText = new Label(s, ContentMode.TEXT);
}
if (!Helper.isRTLDisabled() && CommonHelper.containsRTLText(s)) {
lblText.addStyleName("rtl");
}
lblText.setCaption("text " + (i + 1));
lblText.addStyleName(LABEL_CLASS);
lblText.setWidth(98, Sizeable.Unit.PERCENTAGE);
l.addComponent(lblText);
}
// apply the panel
p.setContent(l);
return p;
}
Label lblText;
if (texts.hasTexts() && !hasOnlyWhiteSpace(texts.getFirstText())) {
lblText = new Label(texts.getFirstText(), ContentMode.TEXT);
if (!Helper.isRTLDisabled() && CommonHelper.containsRTLText(texts.getFirstText())) {
lblText.addStyleName("rtl");
}
} else {
lblText = new Label(NO_TEXT);
}
lblText.setSizeFull();
lblText.addStyleName(LABEL_CLASS);
p.setContent(lblText);
return p;
}
use of annis.service.objects.RawTextWrapper in project ANNIS by korpling.
the class DocBrowserController method createInput.
/**
* Creates the input. It only takes the salt project or the raw text from the
* text table, never both, since the increase the performance for large texts.
*
* @param corpus the name of the toplevel corpus
* @param docName the name of the document
* @param config the visualizer configuration
* @param isUsingRawText indicates, whether the text from text table is taken,
* or if the salt project is traversed.
* @param nodeAnnoFilter A list of node annotation names for filtering the nodes or null if no filtering should be applied.
* @return a {@link VisualizerInput} input, which is usable for rendering the
* whole document.
*/
public static VisualizerInput createInput(String corpus, String docName, Visualizer config, boolean isUsingRawText, List<String> nodeAnnoFilter) {
VisualizerInput input = new VisualizerInput();
// set mappings and namespaces. some visualizer do not survive without
input.setMappings(parseMappings(config));
input.setNamespace(config.getNamespace());
String encodedToplevelCorpus = urlPathEscape.escape(corpus);
String encodedDocument = urlPathEscape.escape(docName);
if (isUsingRawText) {
WebResource w = Helper.getAnnisWebResource();
w = w.path("query").path("rawtext").path(encodedToplevelCorpus).path(encodedDocument);
RawTextWrapper rawTextWrapper = w.get(RawTextWrapper.class);
input.setRawText(rawTextWrapper);
} else {
// get the whole document wrapped in a salt project
SaltProject txt = null;
WebResource res = Helper.getAnnisWebResource().path("query").path("graph").path(encodedToplevelCorpus).path(encodedDocument);
if (nodeAnnoFilter != null) {
res = res.queryParam("filternodeanno", Joiner.on(",").join(nodeAnnoFilter));
}
txt = res.get(SaltProject.class);
if (txt != null) {
SDocument sDoc = txt.getCorpusGraphs().get(0).getDocuments().get(0);
input.setResult(sDoc);
}
}
return input;
}
Aggregations