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>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0-M1</version>
<scope>test</scope>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.3</version>
</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,7 +56,6 @@ 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.);
......@@ -71,8 +70,6 @@ public abstract class Operator {
}
}
/**
* returns the proxy (the representative) for a given uri which serves as the internal
* name for a URI or a blank node
......@@ -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);
......
package de.dfki.lt.hfc;
import java.io.*;
import java.util.*;
import gnu.trove.*;
import de.dfki.lt.hfc.qrelations.QRelation;
import de.dfki.lt.hfc.qrelations.QRelationFactory;
import org.apache.commons.lang3.ArrayUtils;
// TO DO --- IMPLEMENTATION NOTE
......@@ -21,49 +23,35 @@ import gnu.trove.*;
// solution: make sure that BindingTable.table is a SortedSet before TROVE's projection
// takes place -- not sure whether this will work
import de.dfki.lt.hfc.qrelations.QRelation;
import de.dfki.lt.hfc.qrelations.QRelationFactory;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.log4j.Level;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;
/**
*
* @author (C) Hans-Ulrich Krieger
* @version Tue Jan 5 11:45:27 CET 2016
* @since JDK 1.5
* @version Tue Jan 5 11:45:27 CET 2016
*/
public class Query {
/**
* A basic LOGGER.
*/
private final static Logger LOGGER = Logger.getLogger(Query.class.getName());
static {
LOGGER.setLevel(Level.ERROR);
}
/**
* do we want proxy expansion in the resulting binding table if equivalence reduction has been
* turned on ? this field is set every time query() is called, depending on whether either SELECT
* do we want proxy expansion in the resulting binding table if equivalence reduction
* has been turned on ?
* this field is set every time query() is called, depending on whether either SELECT
* (expandProxy = false) or SELECTALL (expandProxy = true) is used
*/
private boolean expandProxy = false;
/**
* a constant that controls whether a warning is printed in case "unexpected" things happen;
* similar variables exists in class TupleStore, RuleStore, and ForwardChainer
* a constant that controls whether a warning is printed in case "unexpected" things
* happen; similar variables exists in class TupleStore, RuleStore, and ForwardChainer
*/
private boolean verbose = true;
private boolean verbose = false;
/**
* in order to query, we need a tuple store
*/
protected TupleStore tupleStore;
/**
* simple flag indicating whether an indexstore is used.
*/
......@@ -77,20 +65,34 @@ public class Query {
QRelationFactory.initFactory(tupleStore);
}
/**
* the unary constructor internalizes the tuple store that `sits'
* inside the forward chainer
*/
public Query(ForwardChainer fc) {
this.tupleStore = fc.tupleStore;
QRelationFactory.initFactory(fc.tupleStore);
}
/**
* Currently the Allen and RCC8 Relations are realized using the following notion, e.g. ?s ?p ?o
* Di "111"^^<xsd:long> "666"^^<xsd:long> TODO UPDATE EBNF reads in a QDL query and returns a
* binding table, encoding the result of the query; at the moment (= v2.3), QDL is described by
* the following EBNF: <p> <query> ::= <select> <where> [<filter>] [<aggregate>] | ASK
* <groundtuple> <select> ::= {"SELECT" | "SELECTALL"} ["DISTINCT"] {"*" | <var>^+} <var>
* ::= "?"{a-zA-Z0-9}^+ | "?_" <nwchar> ::= any NON-whitespace character <where> ::=
* "WHERE" <tuple> {"&" <tuple>}^* <tuple> ::= <literal>^+ <gtuple> ::= <constant>^+
* <literal> ::= <var> | <constant> <constant> ::= <uri> | <atom> <uri> ::= "<"
* <nwchar>^+ ">" <atom> ::= "\"" <char>^* "\"" [ "@" <langtag> | "^^" <xsdtype> ] <char>
* ::= any character, incl. whitespaces, numbers, even '\"' <langtag> ::= "de" | "en" | ...
* <xsdtype> ::= "<xsd:int>" | "<xsd:long>" | "<xsd:float>" | "<xsd:double>" | "<xsd:dateTime>"
* | "<xsd:string>" | "<xsd:boolean>" | "<xsd:date>" | "<xsd:gYear>" | "<xsd:gMonthDay>" |
* reads in a QDL query and returns a binding table, encoding the result of the query;
* at the moment (= v2.3), QDL is described by the following EBNF:
*
* <query> ::= <select> <where> [<filter>] [<aggregate>] | ASK <groundtuple>
* <select> ::= {"SELECT" | "SELECTALL"} ["DISTINCT"] {"*" | <var>^+}
* <var> ::= "?"{a-zA-Z0-9}^+ | "?_"
* <nwchar> ::= any NON-whitespace character
* <where> ::= "WHERE" <tuple> {"&" <tuple>}^*
* <tuple> ::= <literal>^+
* <gtuple> ::= <constant>^+
* <literal> ::= <var> | <constant>
* <constant> ::= <uri> | <atom>
* <uri> ::= "<" <nwchar>^+ ">"
* <atom> ::= "\"" <char>^* "\"" [ "@" <langtag> | "^^" <xsdtype> ]
* <char> ::= any character, incl. whitespaces, numbers, even '\"'
* <langtag> ::= "de" | "en" | ...
* <xsdtype> ::= "<xsd:int>" | "<xsd:long>" | "<xsd:float>" | "<xsd:double>" | "<xsd:dateTime>" |
* "<xsd:string>" | "<xsd:boolean>" | "<xsd:date>" | "<xsd:gYear>" | "<xsd:gMonthDay>" |
* "<xsd:gDay>" | "<xsd:gMonth>" | "<xsd:gYearMonth>" | "<xsd:duration>" | "<xsd:anyURI>" | ...
* <filter> ::= "FILTER" <constr> {"&" <constr>}^*
* <constr> ::= <ineq> | <predcall>
......@@ -99,23 +101,26 @@ public class Query {
* <predicate> ::= <nwchar>^+
* <aggregate> ::= "AGGREGATE" <funcall> {"&" <funcall>}^*
* <funcall> ::= <var>^+ "=" <function> <literal>^*
* <function> ::= <nwchar>^+ <p>
* <function> ::= <nwchar>^+
*
* NOTE: the reserved keywords ASK, SELECT, SELECTALL,
* DISTINCT, WHERE, FILTER, and AGGREGATE need _not_ be written uppercase <p> NOTE: it is required
* that neither filter predicates nor aggregate functions have the same name as the above reserved
* keywords <p> NOTE: _don't-care_ variables should be marked _explicitly_ by using exactly the
* identifier "?_"; this is especially important when using "*" in a SELECT; example: SELECT
* DISTINCT * WHERE ?s <rdf:type> ?_ SELECT * WHERE ?s <rdf:type> ?o ?_ ?_ when restricting the
* object position without projecting it, we explicitly write down the selected indexToVariable:
* NOTE: the reserved keywords ASK, SELECT, SELECTALL, DISTINCT, WHERE, FILTER, and AGGREGATE need
* _not_ be written uppercase
*
* NOTE: it is required that neither filter predicates nor aggregate functions have the same name
* as the above reserved keywords
*