Commit 6e623fba authored by Christian Willms's avatar Christian Willms
Browse files

merge

parents 59188028 87e54250
......@@ -23,7 +23,6 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<junit.version>5.0.1</junit.version>
<encoding>UTF-8</encoding>
</properties>
......@@ -45,6 +44,35 @@
</configuration>
</plugin>
<!-- THIS WORKED BUT IS NO LONGER NEEDED
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>types-library</id>
<goals><goal>jar</goal></goals>
<phase>package</phase>
<configuration>
<classifier>types-lib</classifier>
<includes>
<include>**/de/dfki/lt/hfc/types/*</include>
<include>**/de/dfki/lt/hfc/Namespace*</include>
<include>**/de/dfki/lt/hfc/WrongFormatException*</include>
</includes>
</configuration>
</execution>
<execution>
<id>everything</id>
<goals><goal>jar</goal></goals>
<phase>package</phase>
<configuration>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
......@@ -54,15 +82,6 @@
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
......@@ -80,32 +99,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<reuseForks>false</reuseForks>
<forkCount>4</forkCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.1.0-M1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
......@@ -135,28 +128,23 @@
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -363,7 +363,7 @@ public class BindingTable {
* on or not; in case it is turned off, calling this method does not have an
* effect
*/
public void expandBindingTable() {
protected void expandBindingTable() {
// if already expanded, no need to call method again, esp., since SELECT
// statements without the DISTINCT keyword use java.util.Hashset objects to
// represent duplicate elements (int arrays); otherwise (w/ DISTINCT), a
......
......@@ -2,9 +2,6 @@ package de.dfki.lt.hfc;
import java.util.*;
import gnu.trove.set.hash.*;
import org.apache.log4j.Level;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;
/**
* a collection of static methods that deal with sets and binding tables, used by the
......@@ -21,15 +18,6 @@ import org.apache.log4j.Logger;
*/
public final class Calc {
/**
* A basic LOGGER.
*/
private final static Logger LOGGER = Logger.getLogger(Calc.class.getName());
static {
LOGGER.setLevel(Level.ERROR);
}
/**
* the default hashing and equals strategy for tuples from the output set of the current
* iteration: take ALL positions of a tuple into account
......@@ -245,11 +233,10 @@ public final class Calc {
public static BindingTable restrict(BindingTable bt,
ArrayList<Integer> varvarIneqs,
ArrayList<Integer> varconstIneqs) {
LogMF.trace(LOGGER, "restrict ineqs", null);
// check whether both ineq lists are empty in order to avoid iterator
if (varvarIneqs.isEmpty() && varconstIneqs.isEmpty()){
return bt;}
// instead of using the indexToVariable, we use their positions (faster!);
if (varvarIneqs.isEmpty() && varconstIneqs.isEmpty())
return bt;
// instead of using the vars, we use their positions (faster!);
// use int[] instead of ArrayList<Integer>
int[] vv = new int[varvarIneqs.size()];
for (int i = 0; i < varvarIneqs.size(); i++) {
......@@ -286,7 +273,6 @@ public final class Calc {
}
} // outerloop block
}
bt.size();
return bt;
}
......@@ -295,10 +281,9 @@ public final class Calc {
*/
public static BindingTable restrict(BindingTable bt,
ArrayList<Predicate> predicates) {
LogMF.trace(LOGGER, "restrict predicates", null);
// no predicate: binding table does not change
if (predicates.isEmpty()){
return bt;}
if (predicates.isEmpty())
return bt;
// fundamental distinction: functional-only vs. relational-only variables;
// address the RELATIONAL case first: involved predicates will NOT undergo the double loop below
ArrayList<Predicate> allPredicates = new ArrayList<Predicate>(predicates); // do NOT modify predicates
......
......@@ -123,6 +123,7 @@ public class Configuration {
st = new StringTokenizer(line, " =:\t");
processSpecification(st);
}
br.close();
}
catch (Exception e) {
System.err.println("\nerror while reading configuration file " + configFile);
......
......@@ -3,7 +3,6 @@ package de.dfki.lt.hfc;
import java.io.*;
import java.util.*;
import java.util.concurrent.*;
import de.dfki.lt.hfc.indices.IndexingException;
import gnu.trove.set.hash.*;
import gnu.trove.map.hash.*;
......@@ -196,23 +195,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* generates a new forward chainer with the default namespace for XSD, RDF, RDFS, and OWL
* @throws IOException
* @throws FileNotFoundException
* @throws WrongFormatException
*/
public ForwardChainer(boolean verbose, String tupleFile, String ruleFile)
throws FileNotFoundException, IOException, WrongFormatException {
this();
this.verbose = verbose;
Namespace namespace = new Namespace();
this.tupleStore = new TupleStore(verbose, this.noOfAtoms, this.noOfTuples, namespace, tupleFile);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
......@@ -229,40 +211,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
* @throws WrongFormatException
* @throws FileNotFoundException
*/
public ForwardChainer(boolean verbose, String tupleFile, String ruleFile, String namespaceFile)
throws FileNotFoundException, WrongFormatException, IOException {
this();
this.verbose = verbose;
Namespace namespace = new Namespace(namespaceFile);
this.tupleStore = new TupleStore(false, this.noOfAtoms, this.noOfTuples, namespace, tupleFile);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
* @throws WrongFormatException
* @throws FileNotFoundException
*/
public ForwardChainer(String tupleFile, String ruleFile, String namespaceFile, String indexFile)
throws FileNotFoundException, WrongFormatException, IOException, IndexingException {
this();
Namespace namespace = new Namespace(namespaceFile);
IndexStore indexStore = new IndexStore(indexFile, this.verbose);
this.tupleStore = new TupleStore(this.noOfAtoms, this.noOfTuples, namespace, tupleFile, indexStore);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* generates a new forward chainer with the default namespace for XSD, RDF, RDFS, and OWL;
* noOfAtoms and noOfTuples are important parameters that affects the performance of the
......@@ -284,28 +232,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* generates a new forward chainer with the default namespace for XSD, RDF, RDFS, and OWL;
* noOfAtoms and noOfTuples are important parameters that affects the performance of the
* tuple store used by the forward chainer
* @throws IOException
* @throws FileNotFoundException
* @throws WrongFormatException
*/
public ForwardChainer(boolean verbose, int noOfAtoms, int noOfTuples, String tupleFile, String ruleFile)
throws FileNotFoundException, IOException, WrongFormatException {
this();
this.verbose = verbose;
this.noOfAtoms = noOfAtoms;
this.noOfTuples = noOfTuples;
//this.namespace = new Namespace();
this.tupleStore = new TupleStore(verbose, this.noOfAtoms, this.noOfTuples);
this.tupleStore.readTuples(tupleFile);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
......@@ -324,25 +250,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
* @throws WrongFormatException
* @throws FileNotFoundException
*/
public ForwardChainer(boolean verbose, int noOfAtoms, int noOfTuples, String tupleFile, String ruleFile, String namespaceFile)
throws FileNotFoundException, WrongFormatException, IOException {
this();
this.verbose = verbose;
this.noOfAtoms = noOfAtoms;
this.noOfTuples = noOfTuples;
Namespace namespace = new Namespace(namespaceFile);
this.tupleStore = new TupleStore(verbose, this.noOfAtoms, this.noOfTuples, namespace, tupleFile);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* assumes a default of 100,000 atoms and 500,000 tuples
......@@ -355,18 +262,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* assumes a default of 100,000 atoms and 500,000 tuples
*/
public ForwardChainer(boolean verbose, TupleStore tupleStore, RuleStore ruleStore) {
this();
this.verbose = verbose;
this.tupleStore = tupleStore;
this.ruleStore = ruleStore;
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* more options that will also affect namespace, tuple store, and rule store
* @throws IOException
......@@ -397,32 +292,6 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
public ForwardChainer(int noOfCores,
boolean verbose,
boolean rdfCheck,
boolean eqReduction,
int minNoOfArgs,
int maxNoOfArgs,
int noOfAtoms,
int noOfTuples,
String tupleFile,
String ruleFile,
String namespaceFile,
String indexFile)
throws FileNotFoundException, WrongFormatException, IOException, IndexingException {
this(noOfCores, verbose);
this.noOfAtoms = noOfAtoms;
this.noOfTuples = noOfTuples;
Namespace namespace = new Namespace(namespaceFile, verbose);
IndexStore indexStore = new IndexStore(indexFile,this.verbose);
this.tupleStore = new TupleStore(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs,
this.noOfAtoms, this.noOfTuples, namespace, tupleFile, indexStore);
this.ruleStore = new RuleStore(verbose, rdfCheck, minNoOfArgs, maxNoOfArgs,
this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* more options that will also affect namespace, tuple store, and rule store
* @throws IOException
......@@ -476,6 +345,49 @@ public final class ForwardChainer {
this.noOfTasks = this.ruleStore.allRules.size();
}
/**
* this version allows to explicitly define the namespace
* @throws IOException
* @throws WrongFormatException
* @throws FileNotFoundException
*/
public ForwardChainer(String tupleFile, String ruleFile, String namespaceFile, String indexFile)
throws FileNotFoundException, WrongFormatException, IOException, IndexingException {
this();
Namespace namespace = new Namespace(namespaceFile);
IndexStore indexStore = new IndexStore(indexFile, this.verbose);
this.tupleStore = new TupleStore(this.noOfAtoms, this.noOfTuples, namespace, tupleFile, indexStore);
this.ruleStore = new RuleStore(this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
public ForwardChainer(int noOfCores,
boolean verbose,
boolean rdfCheck,
boolean eqReduction,
int minNoOfArgs,
int maxNoOfArgs,
int noOfAtoms,
int noOfTuples,
String tupleFile,
String ruleFile,
String namespaceFile,
String indexFile)
throws FileNotFoundException, WrongFormatException, IOException, IndexingException {
this(noOfCores, verbose);
this.noOfAtoms = noOfAtoms;
this.noOfTuples = noOfTuples;
Namespace namespace = new Namespace(namespaceFile, verbose);
IndexStore indexStore = new IndexStore(indexFile,this.verbose);
this.tupleStore = new TupleStore(verbose, rdfCheck, eqReduction, minNoOfArgs, maxNoOfArgs,
this.noOfAtoms, this.noOfTuples, namespace, tupleFile, indexStore);
this.ruleStore = new RuleStore(verbose, rdfCheck, minNoOfArgs, maxNoOfArgs,
this.tupleStore, ruleFile);
this.threadPool = Executors.newFixedThreadPool(this.noOfCores);
this.noOfTasks = this.ruleStore.allRules.size();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
......@@ -634,10 +546,6 @@ public final class ForwardChainer {
* make sure that this equals obj by NOT distinguishing between first and second
*/
public boolean equals(Object obj) {
if (obj == this)
return true;
if (!(obj instanceof Pair))
return false;
Pair pair = (Pair)obj;
if (this.first.equals(pair.first) && this.second.equals(pair.second))
return true;
......
......@@ -56,22 +56,19 @@ public abstract class Operator {
return id;
}
/**
* returns the id for a given literal (e.g., a string encoding a URI, blank node,
* XSD int, XSD string, etc.);
* @return a positive int iff there exists a mapping in the tuple store between
* the literal and this int
* @return -1, otherwise
*/
public int getIdForPossiblyUnknownEntity(String literal) {
Integer id = this.tupleStore.objectToId.get(literal);
synchronized (this.tupleStore) {
return id == null ? tupleStore.putObject(literal) : id;
}
}
/**
* returns the id for a given literal (e.g., a string encoding a URI, blank node,
* XSD int, XSD string, etc.);
* @return a positive int iff there exists a mapping in the tuple store between
* the literal and this int
* @return -1, otherwise
*/
public int getIdForPossiblyUnknownEntity(String literal) {
Integer id = this.tupleStore.objectToId.get(literal);
synchronized (this.tupleStore) {
return id == null ? tupleStore.putObject(literal) : id;
}
}
/**
* returns the proxy (the representative) for a given uri which serves as the internal
......@@ -149,6 +146,4 @@ public abstract class Operator {
return this.tupleStore.allTuples;
}
}
......@@ -144,7 +144,7 @@ public final class OperatorRegistry {
* class name; if so, the operator is returned;
* if not, a new one is created, stored/registered, and returned
*/
public Operator checkAndRegister(String className) {
protected Operator checkAndRegister (String className) {
Operator op = this.nameToFo.get(className);
if (op == null)
op = register(className);
......
This diff is collapsed.
package de.dfki.lt.hfc.aggregates;
import java.util.*;
import de.dfki.lt.hfc.*;
import gnu.trove.set.hash.TIntHashSet;
/**
* an example where FilterSupers might be applied:
* SELECT ?c
* WHERE <dom:instance> <rdf:type> ?c
* AGGREGATE ?baseclass = FilterSupers ?c
*
* @author Bernd Kiefer
*/
public final class RemoveSupers extends AggregationalOperator {
/**
* the resulting binding table (1 row, 1 column) is equipped with the corresponding
* tuple store object (as available from AggregationalOperator through this.tupleStore)
* and the two parameter mapping nameToPos and nameToExternalName for potential later
* output;
* note that nameToPos and nameToExternalName of args are not used -- in fact, these
* fields are assigned the null value
*/
public BindingTable apply(BindingTable args,
SortedMap<Integer, Integer> nameToPos,
Map<Integer, String> nameToExternalName) {
// the resulting table
final BindingTable bt = new BindingTable(nameToPos, nameToExternalName, this.tupleStore);
// put all classes into a set
Iterator<int[]> it = args.iterator();
TIntHashSet classes = new TIntHashSet();
int len = 0;
while (it.hasNext()) {
int[] r = it.next();
len = len < r.length ? r.length : len;
classes.add(r[0]);
}
int[] tuple = new int[3 + len - 1];
Arrays.fill(tuple, 0);
tuple[1] = Namespace.RDFS_SUBCLASSOF_ID;
boolean change = true;
while (change) {
change = false;
int[] all = classes.toArray();
for (int i = 0; i < all.length; ++i) {
for (int j = 0; j < all.length; ++j) {
if (i == j) continue;
tuple[0] = all[i]; tuple[2] = all[j];
if (this.tupleStore.ask(tuple)) {
classes.remove(all[j]);
change = true;
}
}
}
}
classes.forEach((c) -> bt.table.add(new int[]{c}));
// add this XSD int as the only unary tuple to the resulting table
return bt;
}
}
......@@ -14,7 +14,6 @@ import org.apache.log4j.Logger;
* An index is used to significantly speed-up the query processing, which is especially useful for reasoning on streams.
*
* @see de.dfki.lt.hfc.Query
*
* Created by christian on 21/12/16.
*/
public abstract class Index<Key extends AnyType> {
......
......@@ -42,7 +42,7 @@ import java.util.*;
* @test
* CardinalityNotEqual ??(s p o) ??(p c)
* BINDING TABLE B (after LHS matching)
* ?s ?p ?o ?r ?c
* ?s ?p ?o ?r ?c
* foo q 1 _:b1 1 \ cardinality restriction
* foo q 2 _:b1 1 / violated for q on foo
* foo r 1 _:b2 1 - but OK for r on foo
......@@ -69,13 +69,15 @@ import java.util.*;
* @version Wed Mar 20 14:36:50 CET 2013
*/
public final class CardinalityNotEqual extends RelationalOperator {
/**
* this implementation of apply() assumes that args consists of exactly TWO (2)
* binding tables, the first one of length 3 (subject predicate object), and the
* second one of length 2 (predicate cardinality);
* I will destructively modify the first binding table, and will only return that
* table (args[0]), since the second table is only used for lookup
*
* @return args[0], the modified input binding table, corresponding to subject predicate object
*/
public BindingTable[] apply(BindingTable[] args) {
// obtain the right positions from mapping internalized in the binding table arguments;
......@@ -93,17 +95,17 @@ public final class CardinalityNotEqual extends RelationalOperator {
posize = index.get(spo[pos10]);
if (posize.containsKey(spo[pos11])) {
card = posize.get(spo[pos11]);