use of org.corpus_tools.salt.core.SLayer in project ANNIS by korpling.
the class VakyarthaDependencyTree method printHTMLOutput.
public void printHTMLOutput(VisualizerInput input, Writer writer, Map<SNode, Integer> selectedNodes) {
SDocumentGraph sDocumentGraph = input.getSResult().getDocumentGraph();
for (SNode n : sDocumentGraph.getNodes()) {
if (selectNode(n)) {
RelannisNodeFeature feat = (RelannisNodeFeature) n.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
int tokenIdx = feat != null ? (int) feat.getTokenIndex() : -1;
selectedNodes.put(n, tokenIdx);
}
}
Map<SNode, Integer> node2Int = new HashMap<SNode, Integer>();
int count = 0;
for (SNode tok : selectedNodes.keySet()) {
node2Int.put(tok, count++);
}
try {
println("<html>", writer);
println("<head>", writer);
LinkedList<String> fontsText = new LinkedList<String>();
LinkedList<String> fontsDep = new LinkedList<String>();
if (input.getFont() != null) {
fontsText.add(input.getFont().getName());
fontsDep.add(input.getFont().getName());
println("<link href=\"" + input.getFont().getUrl() + "\" rel=\"stylesheet\" type=\"text/css\" >", writer);
}
fontsText.add("sans-serif");
fontsDep.add("serif");
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/jquery.js") + "\"></script>", writer);
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/raphael-min.js") + "\"></script>", writer);
println("<script type=\"text/javascript\" src=\"" + input.getResourcePath("vakyartha/vakyarthaDependency.js") + "\"></script>", writer);
// output the data for the javascript
println("<script type=\"text/javascript\">", writer);
println("fcolors={};", writer);
println("shownfeatures=[\"t\"];", writer);
println("tokens=new Object();", writer);
count = 0;
for (SNode node : selectedNodes.keySet()) {
JSONObject vakyarthaObject = new JSONObject();
String completeAnnotation = getAnnotation(node);
String annotationValue = completeAnnotation.replaceFirst(".*=", "");
String text = getText(node, input);
// decide, if the visualization is token based.
if (mappings.containsKey(MAPPING_NODE_KEY)) {
vakyarthaObject.put("t", annotationValue);
} else {
vakyarthaObject.put("t", text);
}
vakyarthaObject.put("annotation", annotationValue);
vakyarthaObject.put("text", text);
vakyarthaObject.put("tooltip", completeAnnotation);
JSONObject govs = new JSONObject();
List<SRelation<SNode, SNode>> sEdges = node.getGraph().getInRelations(node.getId());
for (SRelation<? extends SNode, ? extends SNode> e : sEdges) {
if (e instanceof SPointingRelation) {
SPointingRelation sRelation = (SPointingRelation) e;
boolean includeEdge = true;
// check layer
if (input.getNamespace() != null) {
// must be included in the layer in order to be included
includeEdge = false;
if (sRelation.getLayers() != null) {
for (SLayer layer : sRelation.getLayers()) {
if (input.getNamespace().equals(layer.getName())) {
includeEdge = true;
break;
}
}
}
}
if (includeEdge) {
SNode source = (SNode) sRelation.getSource();
String label = "";
for (SAnnotation anno : sRelation.getAnnotations()) {
label = anno.getValue_STEXT();
break;
}
if (sRelation.getSource() != null && node2Int.containsKey(source)) {
govs.put(String.valueOf(node2Int.get(source)), label);
}
}
}
// end if pointing relation
}
vakyarthaObject.put("govs", govs);
JSONObject attris = new JSONObject();
JSONObject tAttris = new JSONObject();
String tokenColor = "black";
if (input.getMarkedAndCovered().containsKey(node)) {
tokenColor = MatchedNodeColors.getHTMLColorByMatch(input.getMarkedAndCovered().get(node));
}
tAttris.put("fill", tokenColor);
tAttris.put("font", "11px " + StringUtils.join(fontsText, ","));
attris.put("t", tAttris);
JSONObject depAttris = new JSONObject();
depAttris.put("fill", "#999");
depAttris.put("font-style", "italic");
depAttris.put("font", "12px " + StringUtils.join(fontsDep, ","));
attris.put("deptext", depAttris);
vakyarthaObject.put("attris", attris);
writer.append("tokens[").append("" + count++).append("]=");
writer.append(vakyarthaObject.toString().replaceAll("\n", " "));
writer.append(";\n");
}
println("</script>", writer);
println("</head>", writer);
println("<body id=\"holder\">", writer);
// the div to render the javascript to
// println(
// "<div id=\"holder\"> </div>",
// writer);
println("</body>", writer);
println("</html>", writer);
} catch (JSONException ex) {
log.error(null, ex);
} catch (IOException ex) {
log.error(null, ex);
}
}
use of org.corpus_tools.salt.core.SLayer in project ANNIS by korpling.
the class PDFPageHelper method getPageFromAnnotation.
/**
* Returns the value of page annotiation for a node. It takes the visualizer
* mappings into account. If no mapping is used, this definition is used: {@link
* #PAGE_NUMBER_ANNOATATION_NAME}
*/
public String getPageFromAnnotation(SNode node) {
if (node != null && node.getAnnotations() != null) {
Set<SLayer> layers = node.getLayers();
String nodeNamespace = null;
if (layers != null) {
for (SLayer l : layers) {
nodeNamespace = l.getName();
}
for (SAnnotation anno : node.getAnnotations()) {
if ((nodeNamespace == null || input.getNamespace() == null) && getPDFPageAnnotationName().equals(anno.getName())) {
return anno.getValue_STEXT();
} else if (nodeNamespace.equals(input.getNamespace()) && getPDFPageAnnotationName().equals(anno.getName())) {
return anno.getValue_STEXT();
}
}
}
}
return null;
}
use of org.corpus_tools.salt.core.SLayer in project ANNIS by korpling.
the class ResolverProviderImpl method getResolverEntries.
@Override
public ResolverEntry[] getResolverEntries(SDocument doc) {
HashSet<ResolverEntry> visSet = new HashSet<ResolverEntry>();
// create a request for resolver entries
HashSet<SingleResolverRequest> resolverRequests = new HashSet<SingleResolverRequest>();
Set<String> nodeLayers = new HashSet<String>();
for (SNode n : doc.getDocumentGraph().getNodes()) {
for (SLayer layer : n.getLayers()) {
nodeLayers.add(layer.getName());
}
}
Set<String> edgeLayers = new HashSet<String>();
for (SRelation<SNode, SNode> e : doc.getDocumentGraph().getRelations()) {
for (SLayer layer : e.getLayers()) {
try {
edgeLayers.add(layer.getName());
} catch (NullPointerException ex) {
log.warn("NullPointerException when using Salt, was trying to get layer name", ex);
}
}
}
for (String ns : nodeLayers) {
resolverRequests.add(new SingleResolverRequest(doc.getGraph().getRoots().get(0).getName(), ns, ResolverEntry.ElementType.node));
}
for (String ns : edgeLayers) {
resolverRequests.add(new SingleResolverRequest(doc.getGraph().getRoots().get(0).getName(), ns, ResolverEntry.ElementType.edge));
}
// query with this resolver request and make sure it is unique
if (cacheResolver.containsKey(resolverRequests)) {
visSet.addAll(cacheResolver.get(resolverRequests));
} else {
List<ResolverEntry> resolverList = new LinkedList<ResolverEntry>();
WebResource resResolver = Helper.getAnnisWebResource().path("query").path("resolver");
for (SingleResolverRequest r : resolverRequests) {
List<ResolverEntry> tmp;
String corpusName = urlPathEscape.escape(r.getCorpusName());
String namespace = r.getNamespace();
String type = r.getType() == null ? null : r.getType().toString();
if (corpusName != null && namespace != null && type != null) {
WebResource res = resResolver.path(corpusName).path(namespace).path(type);
try {
tmp = res.get(new ResolverEntryListType());
resolverList.addAll(tmp);
} catch (UniformInterfaceException | ClientHandlerException ex) {
if (!AnnisBaseUI.handleCommonError(ex, "query resolver entries")) {
log.error("could not query resolver entries: " + res.toString(), ex);
}
}
}
}
visSet.addAll(resolverList);
cacheResolver.put(resolverRequests, resolverList);
}
// sort everything
ResolverEntry[] visArray = visSet.toArray(new ResolverEntry[visSet.size()]);
Arrays.sort(visArray, new ResolverEntryComparator());
return visArray;
}
use of org.corpus_tools.salt.core.SLayer in project ANNIS by korpling.
the class SaltAnnotateExtractor method handleArtificialDominanceRelation.
/**
* In ANNIS there is a special combined dominance component which has an empty
* name, but which should not directly be included in the Salt graph.
*
* This functions checks if a dominance relation with empty name has a
* "mirror" relation which is inside the same layer and between the same nodes
* but has an relation name. If yes the original dominance relation is an
* artificial one. The function will return true in this case and update the
* mirror relation to include information about the artificial dominance
* relation.
*
* @param graph
* @param rel
* @parem layer
* @param componentID
* @param pre
* @return True if the dominance relation was an artificial one
*/
private boolean handleArtificialDominanceRelation(SDocumentGraph graph, SNode source, SNode target, SRelation rel, SLayer layer, long componentID, long pre) {
List<SRelation<SNode, SNode>> mirrorRelations = graph.getRelations(source.getId(), target.getId());
if (mirrorRelations != null && mirrorRelations.size() > 0) {
for (Relation mirror : mirrorRelations) {
if (mirror != rel && mirror instanceof SRelation) {
// check layer
SRelation mirrorRel = (SRelation) mirror;
Set<SLayer> mirrorLayers = mirrorRel.getLayers();
if (mirrorLayers != null) {
for (SLayer mirrorLayer : mirrorLayers) {
if (mirrorLayer == layer) {
// adjust the feature of the mirror relation to include
// information about the artificial dominance relation
RelannisEdgeFeature mirrorFeat = RelannisEdgeFeature.extract(mirrorRel);
mirrorFeat.setArtificialDominanceComponent(componentID);
mirrorFeat.setArtificialDominancePre(pre);
mirrorRel.removeLabel(ANNIS_NS, FEAT_RELANNIS_EDGE);
mirrorRel.createFeature(ANNIS_NS, FEAT_RELANNIS_EDGE, mirrorFeat);
return true;
}
}
}
}
}
}
return false;
}
use of org.corpus_tools.salt.core.SLayer in project ANNIS by korpling.
the class SaltAnnotateExtractor method mapLayer.
private void mapLayer(SStructuredNode node, SDocumentGraph graph, ResultSet resultSet) throws SQLException {
String namespace = stringValue(resultSet, NODE_TABLE, "namespace");
List<SLayer> layerList = graph.getLayerByName(namespace);
SLayer layer = (layerList != null && layerList.size() > 0) ? layerList.get(0) : null;
if (layer == null) {
layer = SaltFactory.createSLayer();
layer.setName(namespace);
graph.addLayer(layer);
}
node.addLayer(layer);
}
Aggregations