Search in sources :

Example 1 with RawTextWrapper

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;
}
Also used : RawTextWrapper(annis.service.objects.RawTextWrapper) Subject(org.apache.shiro.subject.Subject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with RawTextWrapper

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;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) RawTextWrapper(annis.service.objects.RawTextWrapper) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource) WebResource(com.sun.jersey.api.client.WebResource)

Example 3 with RawTextWrapper

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;
}
Also used : Panel(com.vaadin.ui.Panel) GridLayout(com.vaadin.ui.GridLayout) VerticalLayout(com.vaadin.ui.VerticalLayout) Layout(com.vaadin.ui.Layout) GridLayout(com.vaadin.ui.GridLayout) RawTextWrapper(annis.service.objects.RawTextWrapper) Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 4 with RawTextWrapper

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;
}
Also used : VisualizerInput(annis.libgui.visualizers.VisualizerInput) RawTextWrapper(annis.service.objects.RawTextWrapper) WebResource(com.sun.jersey.api.client.WebResource) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject)

Aggregations

RawTextWrapper (annis.service.objects.RawTextWrapper)4 WebResource (com.sun.jersey.api.client.WebResource)2 VisualizerInput (annis.libgui.visualizers.VisualizerInput)1 AsyncWebResource (com.sun.jersey.api.client.AsyncWebResource)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 GridLayout (com.vaadin.ui.GridLayout)1 Label (com.vaadin.ui.Label)1 Layout (com.vaadin.ui.Layout)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Subject (org.apache.shiro.subject.Subject)1 SDocument (org.corpus_tools.salt.common.SDocument)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1