Commit b950b7e1 authored by Christian Willms's avatar Christian Willms
Browse files

Added slf4j logger

parent beffd63d
......@@ -139,6 +139,16 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
</project>
package de.dfki.lt.hfc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.lang.reflect.*;
......@@ -17,7 +20,11 @@ import java.lang.reflect.*;
* @version Thu Jan 14 14:57:24 CET 2010
*/
public final class AggregateRegistry {
/**
* A basic LOGGER.
*/
private static final Logger logger = LoggerFactory.getLogger(AggregateRegistry.class);
/**
* all (custom) aggregates should be put in package de.dfki.lt.hfc.aggregates
*/
......@@ -102,7 +109,7 @@ public final class AggregateRegistry {
if (AggregateRegistry.EXIT_WHEN_REGISTRATION_FAILS)
throw new RuntimeException("FATAL ERROR");
else
System.out.println(" registering aggregate " + className + " fails");
logger.info(" registering aggregate " + className + " fails");
return null;
}
}
......
package de.dfki.lt.hfc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.*;
......@@ -107,6 +110,11 @@ public class Configuration {
private HashSet<String> files = new HashSet<String>();
/**
* A basic LOGGER.
*/
private static final Logger logger = LoggerFactory.getLogger(Configuration.class);
/**
* the unary constructor takes a config file as explained above
*/
......@@ -126,7 +134,7 @@ public class Configuration {
br.close();
}
catch (Exception e) {
System.err.println("\nerror while reading configuration file " + configFile);
logger.error("\nerror while reading configuration file " + configFile);
throw new RuntimeException("FATAL ERROR");
}
}
......@@ -179,7 +187,7 @@ public class Configuration {
private void processNames(String namespaceFile)
throws FileNotFoundException, WrongFormatException, IOException {
if (this.files.contains(namespaceFile)) {
System.out.println(namespaceFile + " used twice");
logger.info(namespaceFile + " used twice");
return;
}
if (this.namespace == null)
......@@ -196,7 +204,7 @@ public class Configuration {
*/
private void processTuples(String tupleFile) throws FileNotFoundException, IOException, WrongFormatException {
if (this.files.contains(tupleFile)) {
System.out.println(tupleFile + " used twice");
logger.info(tupleFile + " used twice");
return;
}
if (this.tupleStore == null) {
......@@ -216,7 +224,7 @@ public class Configuration {
*/
private void processRules(String ruleFile) throws IOException {
if (this.files.contains(ruleFile)) {
System.out.println(ruleFile + " used twice");
logger.info(ruleFile + " used twice");
return;
}
if (this.ruleStore == null) {
......
......@@ -6,6 +6,8 @@ import java.util.concurrent.*;
import de.dfki.lt.hfc.indices.IndexingException;
import gnu.trove.set.hash.*;
import gnu.trove.map.hash.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* generates a tuple store, a rule store, and a namespace object in order to
......@@ -26,6 +28,11 @@ import gnu.trove.map.hash.*;
*/
public final class ForwardChainer {
/**
* A basic LOGGER.
*/
private static final Logger logger = LoggerFactory.getLogger(ForwardChainer.class);
/**q
* HFC version number string
*/
......@@ -155,11 +162,11 @@ public final class ForwardChainer {
*/
private void init() {
if (this.verbose) {
System.out.println();
System.out.println(" Welcome to HFC, HUK's Forward Chainer");
System.out.println(" " + ForwardChainer.INFO);
System.out.println(" # CPU cores: " + this.noOfCores);
System.out.println(" " + this.toString());
//System.out.println();
logger.info(" Welcome to HFC, HUK's Forward Chainer");
logger.info(" " + ForwardChainer.INFO);
logger.info(" # CPU cores: " + this.noOfCores);
logger.info(" " + this.toString());
}
}
......@@ -793,8 +800,8 @@ public final class ForwardChainer {
Set<Integer> rhsvars = rule.rhsVariables; // proper RHS vars w/o BN vars
Set<Integer> bnvars = rule.blankNodeVariables;
if (this.verbose) {
synchronized (System.out) {
System.out.println(" " + rule.name + ": " + rule.megaCluster.old.size() +
synchronized (logger) {
logger.info(" " + rule.name + ": " + rule.megaCluster.old.size() +
" " + rule.megaCluster.delta.size());
}
}
......@@ -882,8 +889,8 @@ public final class ForwardChainer {
// do not execute rules which have a priority less or equal 0
if (rule.priority <= 0) {
if (this.verbose)
synchronized (System.out) {
System.out.println(" " + rule.name + ": off");
synchronized (logger) {
logger.info(" " + rule.name + ": off");
}
return;
}
......@@ -892,8 +899,8 @@ public final class ForwardChainer {
// and check whether rule is applicable on local grounds
if (! rule.isApplicable) {
if (this.verbose)
synchronized (System.out) {
System.out.println(" " + rule.name + ": local");
synchronized (logger) {
logger.info(" " + rule.name + ": local");
}
return;
}
......@@ -901,8 +908,8 @@ public final class ForwardChainer {
executeGlobalMatch(rule);
if (! rule.isApplicable) {
if (this.verbose)
synchronized (System.out) {
System.out.println(" " + rule.name + ": global");
synchronized (logger) {
logger.info(" " + rule.name + ": global");
}
return;
}
......@@ -910,8 +917,8 @@ public final class ForwardChainer {
applyTests(rule);
if (! rule.isApplicable) {
if (this.verbose)
synchronized (System.out) {
System.out.println(" " + rule.name + ": tests");
synchronized (logger) {
logger.info(" " + rule.name + ": tests");
}
return;
}
......@@ -919,8 +926,8 @@ public final class ForwardChainer {
prepareInstantiation(rule);
if (! rule.isApplicable) {
if (this.verbose)
synchronized (System.out) {
System.out.println(" " + rule.name + ": cluster");
synchronized (logger) {
logger.info(" " + rule.name + ": cluster");
}
return;
}
......@@ -955,14 +962,14 @@ public final class ForwardChainer {
public boolean computeClosure(int noOfIterations, boolean cleanUpRepository) {
int noOfAllTuples = this.tupleStore.allTuples.size();
if (this.verbose)
System.out.println("\n number of all tuples: " + noOfAllTuples + "\n");
logger.info("\n number of all tuples: " + noOfAllTuples + "\n");
int currentIteration = 0;
long time = System.currentTimeMillis();
long fullTime = time;
boolean newInfo = false;
int noOfNewTuples = 0;
if (this.verbose)
System.out.println(" rule name: old new OR failure stage");
logger.info(" rule name: old new OR failure stage");
// increment generation counter for deletion here AND also at the very end
boolean notContained;
++this.tupleStore.generation;
......@@ -972,7 +979,7 @@ public final class ForwardChainer {
// increment number of local iterations wrt. computeClosure()
++currentIteration;
if (this.verbose)
System.out.println(" " + currentIteration);
logger.info(" " + currentIteration);
// execute all rules (quasi) in parallel, taking advantage of multi-core CPUs
this.doneSignal = new CountDownLatch(this.noOfTasks); // = #rules
try {
......@@ -980,7 +987,7 @@ public final class ForwardChainer {
this.doneSignal.await(); // wait for all tasks to finish
}
catch (InterruptedException ie) {
System.out.println(ie);
logger.error(ie.toString());
}
// add rule-generated tuples to set of all tuples and update the index
newInfo = false;
......@@ -993,7 +1000,7 @@ public final class ForwardChainer {
}
}
if (this.verbose) {
System.out.println(" " + noOfNewTuples + "/" + this.tupleStore.allTuples.size() +
logger.info(" " + noOfNewTuples + "/" + this.tupleStore.allTuples.size() +
" (" + (System.currentTimeMillis() - time) + "msec)");
time = System.currentTimeMillis();
}
......@@ -1005,18 +1012,18 @@ public final class ForwardChainer {
++this.tupleStore.generation;
// some statistics
if (this.verbose) {
System.out.println("\n number of all tuples: " + this.tupleStore.allTuples.size());
System.out.println(" " + (this.tupleStore.allTuples.size() - noOfAllTuples) +
logger.info("\n number of all tuples: " + this.tupleStore.allTuples.size());
logger.info(" " + (this.tupleStore.allTuples.size() - noOfAllTuples) +
" tuples generated");
System.out.println(" closure computation took " + (System.currentTimeMillis() - fullTime) + "msec");
logger.info(" closure computation took " + (System.currentTimeMillis() - fullTime) + "msec");
}
// possibly cleanup
if (this.tupleStore.equivalenceClassReduction && this.cleanUpRepository) {
if (this.verbose) { System.out.print("\n cleaning up repository ... "); }
if (this.verbose) { logger.info("\n cleaning up repository ... "); }
this.tupleStore.cleanUpTupleStore();
if (this.verbose) {
System.out.println("done");
System.out.println(" number of all tuples: " + this.tupleStore.allTuples.size());
logger.info("done");
logger.info(" number of all tuples: " + this.tupleStore.allTuples.size());
}
}
// and finally the `answer'
......@@ -1048,7 +1055,7 @@ public final class ForwardChainer {
// is newTuples a subset of allTuples
if (newTuples.isEmpty()) {
if (this.verbose)
System.out.println("\n no tuples generated");
logger.info("\n no tuples generated");
return false;
}
for (int[] tuple : newTuples) {
......@@ -1158,8 +1165,8 @@ public final class ForwardChainer {
public void shutdown() {
this.threadPool.shutdown();
if (this.verbose) {
System.out.println("\n shutting down thread pool ...");
System.out.println(" exiting ...\n");
logger.info("\n shutting down thread pool ...");
logger.info(" exiting ...\n");
}
System.exit(0);
}
......@@ -1171,7 +1178,7 @@ public final class ForwardChainer {
public void shutdownNoExit() {
this.threadPool.shutdown();
if (this.verbose) {
System.out.println(" shutting down thread pool ...");
logger.info(" shutting down thread pool ...");
}
}
......@@ -1325,12 +1332,12 @@ public final class ForwardChainer {
for (int[] tuple : this.tupleStore.allTuples)
this.tupleStore.tupleToGeneration.put(tuple, 0);
if (this.verbose)
System.out.println(" tuple deletion enabled");
logger.info(" tuple deletion enabled");
return true;
}
else {
if (this.verbose)
System.out.println(" tuple deletion can no longer be enabled, since closure computation was already called");
logger.info(" tuple deletion can no longer be enabled, since closure computation was already called");
return false;
}
}
......@@ -1372,7 +1379,7 @@ public final class ForwardChainer {
if ((tgen % 2) != 0)
return false;
if (this.verbose)
System.out.print("\n falling back to generation " + tgen + " ... ");
logger.info("\n falling back to generation " + tgen + " ... ");
// remove tuple from the tuple store, also removes tuple-to-generation mapping, if enabled
this.tupleStore.removeTuple(tuple);
// remove potentially dependent materialized tuples: first, determine the relevant tuples
......@@ -1395,8 +1402,8 @@ public final class ForwardChainer {
compress(1);
// and finally call closure computation again, even for only this single tuple
if (this.verbose) {
System.out.println("done");
System.out.println(" calling closure computation again ...");
logger.info("done");
logger.info(" calling closure computation again ...");
}
computeClosure();
// check whether tuple is still in the set of all tuples, i.e., someone tried to delete an
......@@ -1451,7 +1458,7 @@ public final class ForwardChainer {
if (lowest == Integer.MAX_VALUE)
return false;
if (this.verbose)
System.out.print("\n falling back to generation " + lowest + " ... ");
logger.info("\n falling back to generation " + lowest + " ... ");
// return value = true iff card(tuples) == card(toBeDeleted)
boolean result = (tuples.size() == toBeDeleted.size());
// delete the uploaded tuples from tuples
......@@ -1471,8 +1478,8 @@ public final class ForwardChainer {
}
compress(1);
if (this.verbose) {
System.out.println("done");
System.out.println(" calling closure computation again ...");
logger.info("done");
logger.info(" calling closure computation again ...");
}
computeClosure();
return result;
......@@ -1514,7 +1521,7 @@ public final class ForwardChainer {
return true;
}
catch (Exception e) {
System.err.println(e);
logger.error(e.toString());
// if something went wrong during the transaction, iterate over the remembered tuples and
// redo the insertions, not necessarily _all_ tuples
for (int[] tuple : added)
......@@ -1559,7 +1566,7 @@ public final class ForwardChainer {
return true;
}
catch (Exception e) {
System.err.println(e);
logger.error(e.toString());
// if something went wrong during transaction, iterate over removed tuples
// and undo the deletions
for (Map.Entry<int[], Integer> entry : tuple2generation.entrySet())
......@@ -1612,7 +1619,7 @@ public final class ForwardChainer {
if (lowest == Integer.MAX_VALUE)
return false;
if (this.verbose)
System.out.print("\n falling back to generation " + lowest + " ... ");
logger.info("\n falling back to generation " + lowest + " ... ");
// return value = true iff card(tuples) == card(toBeDeleted)
boolean result = (tuples.size() == toBeDeleted.size());
// delete the uploaded tuples from tuples and record their generation
......@@ -1638,8 +1645,8 @@ public final class ForwardChainer {
// throw away auxiliary data structures and do NOT individually remove tuples
compress(1);
if (this.verbose) {
System.out.println("done");
System.out.println(" calling closure computation again ...");
logger.info("done");
logger.info(" calling closure computation again ...");
}
// call closure computation again to reestablish the entailed tuples and auxiliary structures
computeClosure();
......@@ -1670,7 +1677,7 @@ public final class ForwardChainer {
return true;
}
catch (Exception e) {
System.err.println(e);
logger.error(e.toString());
// if something went wrong during transaction, iterate over removed tuples
// and undo the deletions
this.tupleStore.generation = oldGeneration;
......@@ -1705,7 +1712,7 @@ public final class ForwardChainer {
return true;
}
catch (Exception e) {
System.err.println(e);
logger.error(e.toString());
// undo the effects of the closure computation
for (int[] tuple : this.tupleStore.allTuples) {
if (this.tupleStore.tupleToGeneration.get(tuple) == deleteThatGeneration)
......@@ -1759,7 +1766,7 @@ public final class ForwardChainer {
Query q = new Query(fc.tupleStore);
// different binder vars in aggregates
BindingTable bt = q.query("SELECT DISTINCT ?p WHERE ?s ?p ?o FILTER ?p != <rdf:type> AGGREGATE ?number = Count ?p & ?subject = Identity ?p");
System.out.println(bt);
logger.info(bt.toString());
fc.shutdown();
/*
......
......@@ -9,9 +9,15 @@ import java.util.List;
import java.util.Map;
import de.dfki.lt.hfc.types.XsdLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Hfc {
/**
* A basic LOGGER.
*/
private static final Logger logger = LoggerFactory.getLogger(Hfc.class);
/**
* I'm making _all_ the potentially relevant object directly accessable
*/
......@@ -72,7 +78,7 @@ public class Hfc {
// the fields for the rule store and forward chainer are assigned values
// the first time rules are uploaded to HFC
public void customizeHfc(Map<String, String> settings) {
System.out.println("HFC settings: " + settings);
logger.info("HFC settings: " + settings);
// make the settings available via protected fields in this class;
// alphabetical order:
for (Map.Entry<String, String> pair : settings.entrySet()) {
......@@ -130,7 +136,7 @@ public class Hfc {
break;
default :
if (this.verbose)
System.out.println(" unknown setting option: " + pair.getKey());
logger.info(" unknown setting option: " + pair.getKey());
break;
}
}
......
......@@ -7,9 +7,8 @@ import gnu.trove.set.hash.TCustomHashSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Level;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link IndexLookup} is created while parsing queries in case the {@link IndexStore}
......@@ -21,11 +20,8 @@ public class IndexLookup {
/**
* A basic LOGGER.
*/
private final static Logger LOGGER = Logger.getLogger(IndexLookup.class.getName());
private final static Logger logger = LoggerFactory.getLogger(IndexLookup.class.getName());
static {
LOGGER.setLevel(Level.ERROR);
}
private TupleStore tupleStore;
final Index index;
......@@ -79,7 +75,7 @@ public class IndexLookup {
* @param bindingTable the {@link BindingTable} to be populated.
*/
void apply(BindingTable bindingTable) {
LogMF.debug(LOGGER, "Apply Lookup with relation {0} on index {1}", relation, this.index);
logger.debug("Apply Lookup with relation {0} on index {1}", relation, this.index);
Set<int[]> result = new HashSet<>();
// The actual index lookup, depending on whether or not relations are used
if (relation != null) {
......
......@@ -5,9 +5,9 @@ import de.dfki.lt.hfc.indices.Index;
import de.dfki.lt.hfc.indices.AdvancedIndex;
import de.dfki.lt.hfc.qrelations.QRelation;
import de.dfki.lt.hfc.types.AnyType;
import org.apache.log4j.Level;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.BufferedWriter;
......@@ -35,11 +35,9 @@ public class IndexStore {
/**
* A basic LOGGER.
*/
private final static Logger LOGGER = Logger.getLogger(IndexStore.class.getName());
private static final Logger logger = LoggerFactory.getLogger(IndexStore.class);
static {
LOGGER.setLevel(Level.ERROR);
}
// last '.' char is OK!
public static final String INDEX_PATH = "de.dfki.lt.hfc.indices.";
......@@ -96,9 +94,9 @@ public class IndexStore {
* Creates a new instance of {@link IndexStore} according to the specification in the given file.
*/
public IndexStore(String indexFile, boolean verbose) throws IndexingException {
LogMF.debug(LOGGER, "Initializing indexStore ...", null);
logger.debug("Initializing indexStore ...");
readIndex(indexFile);
LogMF.debug(LOGGER, "... successfully initialized", null);
logger.debug( "... successfully initialized");
}
......@@ -111,7 +109,7 @@ public class IndexStore {
* @return A Set of tuples associated with the given key/the given date.
*/
public Set<int[]> lookup(AnyType key) {
LogMF.debug(LOGGER, "Lookup key: {0} ", key);
logger.debug( "Lookup key: {0} ", key);
return this.primaryIndex.search(key);
}
......@@ -125,7 +123,7 @@ public class IndexStore {
* @return The values associated with all keys between the given ones.
*/
public Set<int[]> lookup(AnyType key1, AnyType key2) {
LogMF.debug(LOGGER, "Lookup interval: {0} - {1} ", key1, key2);
logger.debug( "Lookup interval: {0} - {1} ", key1, key2);
if (secundaryIndex != null) {
return this.secundaryIndex.searchInterval(key1, key2);
}
......@@ -156,7 +154,7 @@ public class IndexStore {
try {
this.primIndexKey = Class.forName(TYPE_PATH + splitline[1].trim());
} catch (ClassNotFoundException e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
break;
}
......@@ -164,7 +162,7 @@ public class IndexStore {
try {
this.secIndexKey = Class.forName(TYPE_PATH + splitline[1].trim());
} catch (ClassNotFoundException e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
break;
}
......@@ -195,7 +193,7 @@ public class IndexStore {
this.primIndexBackend = Class.forName(INDEX_PATH + splitline[1].trim());
} catch (ClassNotFoundException e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
break;
}
......@@ -204,7 +202,7 @@ public class IndexStore {
this.secIndexBackend = Class.forName(INDEX_PATH + splitline[1].trim());
} catch (ClassNotFoundException e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
break;
}
......@@ -212,13 +210,13 @@ public class IndexStore {
if (splitline[0].trim().startsWith("#")) {
continue;
}
LOGGER.error("Unknown parameter" + line );
logger.warn("Unknown parameter" + line );
}
}
}
bufferedReader.close();
} catch (IOException e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
//check whether all necessary values are present
if (primIndexBackend == null || position_prime_start == -1 || primIndexKey == null) {
......@@ -240,7 +238,7 @@ public class IndexStore {
.newInstance(secIndexKey, position_second_start, position_second_end);
}
} catch (Exception e) {
LOGGER.error(e.getStackTrace());
logger.error(e.getStackTrace().toString());
}
}
......@@ -253,7 +251,7 @@ public class IndexStore {
try (BufferedWriter writer = Files.newBufferedWriter(path)) {