use of annis.model.AnnisNode in project ANNIS by korpling.
the class PartiturVisualizer method addTimeAttribute.
private String addTimeAttribute(long nodeId) {
DetectHoles detectHoles = new DetectHoles(token);
AnnisNode root = null;
TimeHelper t = new TimeHelper(token);
for (AnnisNode n : nodes) {
if (n.getId() == nodeId) {
root = n;
break;
}
}
// some calculations for index shifting
AnnisNode leftNode = detectHoles.getLeftBorder(root);
AnnisNode rightNode = detectHoles.getRightBorder(root);
return t.getTimeAnno(leftNode, rightNode);
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class AomAnnotateExtractor method mapNode.
public AnnisNode mapNode(ResultSet resultSet, TableAccessStrategy tableAccessStrategy, Map<Long, ComponentEntry> spans) throws SQLException {
AnnisNode annisNode = new AnnisNode(longValue(resultSet, NODE_TABLE, "id", tableAccessStrategy));
annisNode.setCorpus(longValue(resultSet, NODE_TABLE, "corpus_ref", tableAccessStrategy));
annisNode.setTextId(longValue(resultSet, NODE_TABLE, "text_ref", tableAccessStrategy));
annisNode.setLeft(longValue(resultSet, NODE_TABLE, "left", tableAccessStrategy));
annisNode.setRight(longValue(resultSet, NODE_TABLE, "right", tableAccessStrategy));
annisNode.setNamespace(stringValue(resultSet, NODE_TABLE, "namespace", tableAccessStrategy));
annisNode.setName(stringValue(resultSet, NODE_TABLE, "name", tableAccessStrategy));
annisNode.setTokenIndex(longValue(resultSet, NODE_TABLE, "token_index", tableAccessStrategy));
if (resultSet.wasNull())
annisNode.setTokenIndex(null);
annisNode.setSpannedText(stringValue(resultSet, NODE_TABLE, "span", tableAccessStrategy));
annisNode.setLeftToken(longValue(resultSet, NODE_TABLE, "left_token", tableAccessStrategy));
annisNode.setRightToken(longValue(resultSet, NODE_TABLE, "right_token", tableAccessStrategy));
String typeAsString = stringValue(resultSet, COMPONENT_TABLE, "type", tableAccessStrategy);
if (spans != null && "c".equals(typeAsString)) {
ComponentEntry entry = new ComponentEntry(longValue(resultSet, COMPONENT_TABLE, "id", tableAccessStrategy), typeAsString.charAt(0), stringValue(resultSet, COMPONENT_TABLE, "namespace", tableAccessStrategy), stringValue(resultSet, COMPONENT_TABLE, "name", tableAccessStrategy));
spans.put(annisNode.getId(), entry);
}
return annisNode;
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class GeneralTextExporter method convertText.
public void convertText(AnnisResultSet queryResult, List<String> keys, Map<String, String> args, Writer out, int offset) throws IOException {
Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();
List<String> metaKeys = new LinkedList<>();
if (args.containsKey("metakeys")) {
Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
for (String s : it) {
metaKeys.add(s);
}
}
int counter = 0;
for (AnnisResult annisResult : queryResult) {
Set<Long> matchedNodeIds = annisResult.getGraph().getMatchedNodeIds();
counter++;
out.append((counter + offset) + ". ");
List<AnnisNode> tok = annisResult.getGraph().getTokens();
for (AnnisNode annisNode : tok) {
Long tokID = annisNode.getId();
if (matchedNodeIds.contains(tokID)) {
out.append("[");
out.append(annisNode.getSpannedText());
out.append("]");
} else {
out.append(annisNode.getSpannedText());
}
// for (Annotation annotation : annisNode.getNodeAnnotations()){
// out.append("/"+annotation.getValue());
// }
out.append(" ");
}
out.append("\n");
if (!metaKeys.isEmpty()) {
String[] path = annisResult.getPath();
appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
}
out.append("\n");
}
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class GridExporter method convertText.
@Override
public void convertText(AnnisResultSet queryResult, List<String> keys, Map<String, String> args, Writer out, int offset) throws IOException {
Map<String, Map<String, Annotation>> metadataCache = new HashMap<>();
boolean showNumbers = true;
if (args.containsKey("numbers")) {
String arg = args.get("numbers");
if (arg.equalsIgnoreCase("false") || arg.equalsIgnoreCase("0") || arg.equalsIgnoreCase("off")) {
showNumbers = false;
}
}
List<String> metaKeys = new LinkedList<>();
if (args.containsKey("metakeys")) {
Iterable<String> it = Splitter.on(",").trimResults().split(args.get("metakeys"));
for (String s : it) {
metaKeys.add(s);
}
}
int counter = 0;
for (AnnisResult annisResult : queryResult) {
HashMap<String, TreeMap<Long, Span>> annos = new HashMap<>();
counter++;
out.append((counter + offset) + ".");
long tokenOffset = annisResult.getGraph().getTokens().get(0).getTokenIndex() - 1;
for (AnnisNode resolveNode : annisResult.getGraph().getNodes()) {
for (Annotation resolveAnnotation : resolveNode.getNodeAnnotations()) {
String k = resolveAnnotation.getName();
if (annos.get(k) == null) {
annos.put(k, new TreeMap<Long, Span>());
}
// create a separate span for every annotation
annos.get(k).put(resolveNode.getLeftToken(), new Span(resolveNode.getLeftToken(), resolveNode.getRightToken(), resolveAnnotation.getValue()));
}
}
for (String k : keys) {
if ("tok".equals(k)) {
out.append("\t" + k + "\t ");
for (AnnisNode annisNode : annisResult.getGraph().getTokens()) {
out.append(annisNode.getSpannedText() + " ");
}
out.append("\n");
} else {
if (annos.get(k) != null) {
out.append("\t" + k + "\t ");
for (Span s : annos.get(k).values()) {
out.append(s.getValue());
if (showNumbers) {
long leftIndex = Math.max(1, s.getStart() - tokenOffset);
long rightIndex = s.getEnd() - tokenOffset;
out.append("[" + leftIndex + "-" + rightIndex + "]");
}
out.append(" ");
}
out.append("\n");
}
}
}
if (!metaKeys.isEmpty()) {
String[] path = annisResult.getPath();
super.appendMetaData(out, metaKeys, path[path.length - 1], annisResult.getDocumentName(), metadataCache);
}
out.append("\n\n");
}
}
use of annis.model.AnnisNode in project ANNIS by korpling.
the class ProielDependecyTree method writeAllNodes.
private void writeAllNodes() {
for (AnnisNode n : input.getResult().getGraph().getNodes()) {
boolean isDepNode = false;
String word = null;
for (Annotation anno : n.getNodeAnnotations()) {
if ("tiger".equals(anno.getNamespace()) && "word".equals(anno.getName())) {
isDepNode = true;
word = anno.getValue();
break;
}
}
if (isDepNode) {
writeNode(n, word);
}
}
}
Aggregations