
de.citec.scie.web.exporter.html.HtmlFormater Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservice Show documentation
Show all versions of webservice Show documentation
Module providing the webservice interface based on the Jetty
embedded webserver and the FreeMarker template engine. Defines a simple
format for providing textual annotations and produced output in HTML or
JSON. This module has no dependencies to the other SCIE modules (except
for the PDF text extractor) or the UIMA framework and thus can be used
in any context, where text is annotated by an algorithm and should be
presented to an end user.
The newest version!
/*
* SCIE -- Spinal Cord Injury Information Extraction
* Copyright (C) 2013, 2014
* Raphael Dickfelder, Jan Göpfert, Benjamin Paaßen, Andreas Stöckel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.scie.web.exporter.html;
import de.citec.scie.web.analysis.AbstractAnalysisResult;
import de.citec.scie.web.exporter.generic.NestedWriterFormater;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
/**
*
* @author Andreas Stöckel -- [email protected]
*/
public class HtmlFormater implements NestedWriterFormater {
private final AbstractAnalysisResult result;
private final Set groups = new TreeSet<>();
public HtmlFormater(AbstractAnalysisResult result) {
this.result = result;
}
public static String entityName(int idx) {
return "e" + idx;
}
public static String groupName(int gid) {
return "o" + gid;
}
public static String escapeCharacterStatic(char c) {
switch (c) {
case '\n':
return "
\n";
case '<':
return "<";
case '&':
return "&";
default:
return Character.toString(c);
}
}
@Override
public String escapeCharacter(char c) {
return escapeCharacterStatic(c);
}
public static String escapeString(String s) {
StringBuilder sb = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
sb.append(escapeCharacterStatic(s.charAt(i)));
}
return sb.toString();
}
@Override
public String openTag(Collection indices, int gid, boolean first) {
final StringBuilder sb = new StringBuilder();
groups.add(gid);
sb.append("");
return sb.toString();
}
@Override
public String closeTag(Collection indices, int gid, boolean last) {
return " ";
}
public Set getGroups() {
return groups;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy