
it.unitn.disi.smatch.renderers.context.BaseContextRenderer 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.common.components.Configurable;
import it.unitn.disi.common.components.ConfigurableException;
import it.unitn.disi.smatch.SMatchConstants;
import it.unitn.disi.smatch.data.trees.IBaseContext;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import java.util.Properties;
/**
* Base class for context renderers.
*
* Accepts sort parameter.
*
* @author Aliaksandr Autayeu
*/
public abstract class BaseContextRenderer extends Configurable implements IBaseContextRenderer {
private static final Logger log = Logger.getLogger(BaseContextRenderer.class);
protected long counter;
protected long total;
protected long reportInt;
protected final static String SORT_KEY = "sort";
protected boolean sort = false;
@Override
public boolean setProperties(Properties newProperties) throws ConfigurableException {
boolean result = super.setProperties(newProperties);
if (result) {
if (newProperties.containsKey(SORT_KEY)) {
sort = Boolean.parseBoolean(newProperties.getProperty(SORT_KEY));
}
}
return result;
}
public void render(E context, String fileName) throws ContextRendererException {
counter = 0;
total = context.getNodesList().size();
reportInt = (total / 20) + 1;//i.e. report every 5%
process(context, fileName);
reportStats(context);
}
protected abstract void process(E context, String fileName) throws ContextRendererException;
protected void reportStats(E context) {
if (log.isEnabledFor(Level.INFO)) {
log.info("Rendered nodes: " + context.getNodesList().size());
}
}
protected void reportProgress() {
counter++;
if ((SMatchConstants.LARGE_TASK < total) && (0 == (counter % reportInt)) && log.isEnabledFor(Level.INFO)) {
log.info(100 * counter / total + "%");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy