
it.unitn.disi.smatch.renderers.context.TabContextRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of s-match Show documentation
Show all versions of s-match Show documentation
A version of S-Match semantic matching framework for Open Data
The newest version!
package it.unitn.disi.smatch.renderers.context;
import it.unitn.disi.smatch.data.trees.*;
import it.unitn.disi.smatch.loaders.ILoader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
/**
* Renders a context in a tab-indented file.
*
* @author Aliaksandr Autayeu
*/
public class TabContextRenderer extends BaseFileContextRenderer>> {
@SuppressWarnings({"unchecked"})
protected void process(IBaseContext> context, BufferedWriter out) throws IOException, ContextRendererException {
ArrayList> nodeQ = new ArrayList>();
String level = "";
nodeQ.add(context.getRoot());
IBaseNode curNode;
String line;
while (!nodeQ.isEmpty()) {
curNode = nodeQ.remove(0);
if (null == curNode) {
level = level.substring(1);
} else {
line = level + curNode.getNodeData().getName() + "\n";
out.write(line);
reportProgress();
if (curNode.getChildCount() > 0) {
level = level + "\t";
nodeQ.add(0, null);
Iterator children;
if (sort) {
ArrayList childrenList = new ArrayList(curNode.getChildrenList());
Collections.sort(childrenList, Node.NODE_NAME_COMPARATOR);
children = childrenList.iterator();
} else {
children = curNode.getChildren();
}
int idx = 0;
//adding to the top of the queue
while (children.hasNext()) {
nodeQ.add(idx, children.next());
idx++;
}
}
}
}
reportStats(context);
}
public String getDescription() {
return ILoader.TXT_FILES;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy