From 17bd9beaf7f358a44e5bf36a5855fe6727d506dc Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Tue, 10 May 2022 18:17:06 +0100 Subject: [pagoda] Move project to Scala This commit includes a few changes: - The repository still uses Maven to manage dependency but it is now a Scala project. - The code has been ported from OWLAPI 3.4.10 to 5.1.20 - A proof of concept program using both RSAComb and PAGOdA has been added. --- .../ox/cs/pagoda/util/ConjunctiveQueryHelper.java | 70 ----- .../cs/pagoda/util/ExponentialInterpolation.java | 33 --- src/uk/ac/ox/cs/pagoda/util/Namespace.java | 34 --- src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java | 259 ------------------- src/uk/ac/ox/cs/pagoda/util/Separator.java | 11 - src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java | 48 ---- src/uk/ac/ox/cs/pagoda/util/SparqlHelper.java | 282 --------------------- src/uk/ac/ox/cs/pagoda/util/Timer.java | 52 ---- src/uk/ac/ox/cs/pagoda/util/TurtleHelper.java | 56 ---- src/uk/ac/ox/cs/pagoda/util/UFS.java | 45 ---- src/uk/ac/ox/cs/pagoda/util/Utility.java | 251 ------------------ .../ox/cs/pagoda/util/data_structures/Graph.java | 38 --- .../ox/cs/pagoda/util/disposable/Disposable.java | 30 --- .../pagoda/util/disposable/DisposedException.java | 12 - src/uk/ac/ox/cs/pagoda/util/tuples/Tuple.java | 54 ---- .../ac/ox/cs/pagoda/util/tuples/TupleBuilder.java | 38 --- 16 files changed, 1313 deletions(-) delete mode 100644 src/uk/ac/ox/cs/pagoda/util/ConjunctiveQueryHelper.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/Namespace.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/Separator.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/SparqlHelper.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/Timer.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/TurtleHelper.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/UFS.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/Utility.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/data_structures/Graph.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/tuples/Tuple.java delete mode 100644 src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java (limited to 'src/uk/ac/ox/cs/pagoda/util') diff --git a/src/uk/ac/ox/cs/pagoda/util/ConjunctiveQueryHelper.java b/src/uk/ac/ox/cs/pagoda/util/ConjunctiveQueryHelper.java deleted file mode 100644 index 937c2c4..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/ConjunctiveQueryHelper.java +++ /dev/null @@ -1,70 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedList; - -public class ConjunctiveQueryHelper { - - public static String[][] getAnswerVariables(String queryText) { - Collection disVars = new LinkedList(), undisVars = new LinkedList(); - for (String var: getAllVariables(queryText)) - if (var.startsWith("?")) disVars.add(var.substring(1)); - else undisVars.add(var.substring(2)); - - String[] distinguishedVariables = disVars.toArray(new String[0]); - String[] undistinguishedVariables = undisVars.toArray(new String[0]); - String[] answerVariables = null; - - String uppercase = queryText.toUpperCase(); - int selectIndex = uppercase.indexOf("SELECT"); - int whereIndex = uppercase.indexOf("WHERE"); - String selectClause = queryText.substring(selectIndex + 6, whereIndex); - if (selectClause.contains("*")) answerVariables = distinguishedVariables; - else { - String[] terms = selectClause.split(" "); - int num = 0; - for (int i = 0; i < terms.length; ++i) - if (terms[i].startsWith("?")) ++num; - answerVariables = new String[num]; - for (int i = 0, j = 0; i < terms.length; ++i) - if (terms[i].startsWith("?")) - answerVariables[j++] = terms[i].substring(1); - } - - if (answerVariables != distinguishedVariables) { - int index = 0; - for (; index < answerVariables.length; ++index) { - distinguishedVariables[index] = answerVariables[index]; - disVars.remove(answerVariables[index]); - } - for (String var: disVars) - distinguishedVariables[index++] = var; - } - - return new String[][] { answerVariables, distinguishedVariables, undistinguishedVariables }; - } - - private static Collection getAllVariables(String queryText) { - Collection vars = new HashSet(); - int start, end = 0; - char ch; - while ((start = queryText.indexOf("?", end)) != -1) { - end = start + 1; - while (end + 1 < queryText.length() && (ch = queryText.charAt(end + 1)) != '\n' && ch != ' ') - ++end; - vars.add(queryText.substring(start, end + 1)); - } - - end = 0; - while ((start = queryText.indexOf("_:", end)) != -1) { - end = start + 1; - while (end + 1 < queryText.length() && (ch = queryText.charAt(end + 1)) != '\n' && ch != ' ') - ++end; - vars.add(queryText.substring(start, end + 1)); - } - - return vars; - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java b/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java deleted file mode 100644 index 1d12169..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/ExponentialInterpolation.java +++ /dev/null @@ -1,33 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -/*** - * Get an exponential function given two points. - */ -public class ExponentialInterpolation { - - private final double base; - private final double multiplicativeFactor; - - /*** - * Compute the exponential function passing for the 2 given points. - * - * @param x1 - * @param y1 - * @param x2 - * @param y2 - */ - public ExponentialInterpolation(double x1, double y1, double x2, double y2) { - base = Math.pow(y2/y1, 1 / (x2 - x1)); - multiplicativeFactor = y1 / Math.pow(base, x1); - } - - /*** - * Compute value of the function in x. - * - * @param x - * @return - */ - public double computeValue(double x) { - return multiplicativeFactor * Math.pow(base, x); - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/Namespace.java b/src/uk/ac/ox/cs/pagoda/util/Namespace.java deleted file mode 100644 index 07c8ebd..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/Namespace.java +++ /dev/null @@ -1,34 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -public class Namespace { - - public static final String RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; - public static final String RDFS_NS = "http://www.w3.org/2000/01/rdf-schema#"; - public static final String OWL_NS = "http://www.w3.org/2002/07/owl#"; - public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema#"; - public static final String SWRL_NS = "http://www.w3.org/2003/11/swrl#"; - public static final String SWRLB_NS = "http://www.w3.org/2003/11/swrlb#"; - public static final String SWRLX_NS = "http://www.w3.org/2003/11/swrlx#"; - public static final String RULEML_NS = "http://www.w3.org/2003/11/ruleml#"; - - public static final String RDF_TYPE_QUOTED = "<" + RDF_NS + "type>"; - public static final String RDF_TYPE = RDF_NS + "type"; - public static final String RDF_TYPE_ABBR = "rdf:type"; - - public static final String EQUALITY = OWL_NS + "sameAs"; - public static final String EQUALITY_QUOTED = "<" + EQUALITY + ">"; - public static final String EQUALITY_ABBR = "owl:sameAs"; - - public static final String INEQUALITY = OWL_NS + "differentFrom"; - public static final String INEQUALITY_ABBR = "owl:differentFrom"; - public static final String INEQUALITY_QUOTED = "<" + INEQUALITY + ">"; - - public static final String RDF_PLAIN_LITERAL = RDF_NS + "PlainLiteral"; - public static final String XSD_STRING = XSD_NS + "string"; - - public static final String PAGODA_ANONY = "http://www.cs.ox.ac.uk/PAGOdA/skolemised#"; - public static final String PAGODA_AUX = "http://www.cs.ox.ac.uk/PAGOdA/auxiliary#"; - public static final String KARMA_ANONY = "http://www.cs.ox.ac.uk/KARMA/anonymous"; - public static final String PAGODA_ORIGINAL = PAGODA_AUX + "Original"; - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java deleted file mode 100644 index 2b52a89..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java +++ /dev/null @@ -1,259 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import org.apache.log4j.Logger; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; - -public class PagodaProperties { - - public enum SkolemUpperBoundOptions {DISABLED, BEFORE_SUMMARISATION, AFTER_SUMMARISATION} - - public static final String DEFAULT_CONFIG_FILE = "_default_pagoda.properties"; - public static final String CONFIG_FILE = "pagoda.properties"; - public static final boolean DEFAULT_DEBUG = false; - private static final boolean DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND; - private static final SkolemUpperBoundOptions DEFAULT_SKOLEM_UPPER_BOUND; - private static final int DEFAULT_SKOLEM_DEPTH; - private static final boolean DEFAULT_TO_CALL_HERMIT; - private static final Path DEFAULT_STATISTICS_DIR; - private static final long DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE; - - public static boolean shellModeDefault = false; - private static boolean debug = DEFAULT_DEBUG; - - static { - Logger logger = Logger.getLogger("PagodaProperties"); - - boolean defaultUseAlwaysSimpleUpperBound = false; - SkolemUpperBoundOptions defaultSkolemUpperBound = SkolemUpperBoundOptions.DISABLED; - int defaultSkolemDepth = 1; - boolean toCallHermit = true; - Path defaultStatisticsDir = null; - long defaultMaxTriplesInSkolemStore = 1000000; - - InputStream configStream = PagodaProperties.class.getClassLoader().getResourceAsStream(CONFIG_FILE); - - if(configStream == null) { - logger.info("Unable to find user-defined configuration file (\"" + CONFIG_FILE + "\" in classpath)"); - logger.info("Using default configuration"); - configStream = PagodaProperties.class.getClassLoader().getResourceAsStream(DEFAULT_CONFIG_FILE); - } - - try { - Properties config = new Properties(); - config.load(configStream); - configStream.close(); - - if (config.containsKey("debug")) { - debug = Boolean.parseBoolean(config.getProperty("debug")); - logger.info("Debugging mode is enabled"); - - if (config.containsKey("statisticsDir")) { - defaultStatisticsDir = Paths.get(config.getProperty("statisticsDir")); - logger.info("The directory where statistics are saved is: \"" + defaultStatisticsDir + "\""); - } - } - if (config.containsKey("useAlwaysSimpleUpperBound")) { - defaultUseAlwaysSimpleUpperBound = - Boolean.parseBoolean(config.getProperty("useAlwaysSimpleUpperBound")); - if (defaultUseAlwaysSimpleUpperBound) - logger.debug("By default the simple upper bound is always used"); - } - if (config.containsKey("skolemUpperBound")) { - defaultSkolemUpperBound = SkolemUpperBoundOptions.valueOf(config.getProperty("skolemUpperBound")); - switch (defaultSkolemUpperBound) { - case AFTER_SUMMARISATION: - logger.debug("By default the Skolem upper bound is applied AFTER Summarisation"); - break; - case BEFORE_SUMMARISATION: - logger.debug("By default the Skolem upper bound is applied BEFORE Summarisation"); - break; - default: - defaultSkolemUpperBound = SkolemUpperBoundOptions.DISABLED; - case DISABLED: - logger.debug("By default the Skolem upper bound is disabled"); - } - } - if (config.containsKey("toCallHermit")) { - toCallHermit = Boolean.parseBoolean(config.getProperty("toCallHermit")); - if (toCallHermit) - logger.debug("By default Hermit is enabled"); - else - logger.debug("By default Hermit is disabled"); - } - if (config.containsKey("skolemDepth")) { - defaultSkolemDepth = Integer.parseInt(config.getProperty("skolemDepth")); - logger.debug("By default the max skolemisation depth is " + defaultSkolemDepth); - } - if (config.containsKey("maxTriplesInSkolemStore")) { - defaultMaxTriplesInSkolemStore = Long.parseLong(config.getProperty("maxTriplesInSkolemStore")); - logger.debug("By default the maximum number of triples in the Skolem store is " + defaultMaxTriplesInSkolemStore); - } - - } catch (IOException e) { - e.printStackTrace(); - } - DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND = defaultUseAlwaysSimpleUpperBound; - DEFAULT_SKOLEM_UPPER_BOUND = defaultSkolemUpperBound; - DEFAULT_TO_CALL_HERMIT = toCallHermit; - DEFAULT_STATISTICS_DIR = defaultStatisticsDir; - DEFAULT_SKOLEM_DEPTH = defaultSkolemDepth; - DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE = defaultMaxTriplesInSkolemStore; - } - - String dataPath = null; - String ontologyPath; - String queryPath = null; - String answerPath = null; - boolean toClassify = true; - boolean toCallHermiT = DEFAULT_TO_CALL_HERMIT; - - public int getSkolemDepth() { - return skolemDepth; - } - - public void setSkolemDepth(int skolemDepth) { - this.skolemDepth = skolemDepth; - } - - int skolemDepth = DEFAULT_SKOLEM_DEPTH; - boolean shellMode = shellModeDefault; - private boolean useAlwaysSimpleUpperBound = DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND; - private SkolemUpperBoundOptions skolemUpperBound = DEFAULT_SKOLEM_UPPER_BOUND; - private Path statisticsDir = DEFAULT_STATISTICS_DIR; - private long maxTriplesInSkolemStore = DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE; - - public PagodaProperties(String path) { - java.util.Properties m_properties = new java.util.Properties(); - InputStream inputStream = null; - try { - inputStream = new FileInputStream(path); - m_properties.load(inputStream); - - setOntologyPath(m_properties.getProperty("ONTOLOGY")); - setDataPath(m_properties.getProperty("DATA")); - setQueryPath(m_properties.getProperty("QUERY")); - setAnswerPath(m_properties.getProperty("ANSWER")); - setToClassify(Boolean.parseBoolean(m_properties.getProperty("TO_CLASSIFY"))); - setToCallHermiT(Boolean.parseBoolean(m_properties.getProperty("CALL_HERMIT"))); - - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (inputStream != null) - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public PagodaProperties() { - } - - public static boolean isDebuggingMode() { - return debug; - } - - public static boolean getDefaultUseAlwaysSimpleUpperBound() { - return DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND; - } - - public static Path getDefaultStatisticsDir() { - return DEFAULT_STATISTICS_DIR; - } - - public static SkolemUpperBoundOptions getDefaultSkolemUpperBound() { - return DEFAULT_SKOLEM_UPPER_BOUND; - } - - public String getDataPath() { - return dataPath; - } - - public void setDataPath(String path) { - dataPath = path; - } - - public String getOntologyPath() { - return ontologyPath; - } - - public void setOntologyPath(String path) { - ontologyPath = path; - } - - public String getQueryPath() { - return queryPath; - } - - public void setQueryPath(String path) { - queryPath = path; - } - - public String getAnswerPath() { - return answerPath; - } - - public void setAnswerPath(String path) { - answerPath = path; - } - - public boolean getToClassify() { - return toClassify; - } - - public void setToClassify(boolean flag) { - toClassify = flag; - } - - public boolean getToCallHermiT() { - return toCallHermiT; - } - - public void setToCallHermiT(boolean flag) { - toCallHermiT = flag; - } - - public boolean getShellMode() { - return shellMode; - } - - public void setShellMode(boolean flag) { - shellMode = flag; - } - - public boolean getUseAlwaysSimpleUpperBound() { - return useAlwaysSimpleUpperBound; - } - - public void setUseAlwaysSimpleUpperBound(boolean flag) { - useAlwaysSimpleUpperBound = flag; - } - - public SkolemUpperBoundOptions getSkolemUpperBound() { - return skolemUpperBound; - } - - public void setSkolemUpperBound(SkolemUpperBoundOptions flag) { - skolemUpperBound = flag; - } - - public Path getStatisticsDir() { - return statisticsDir; - } - - public void setStatisticsDir(Path statisticsDir) { - this.statisticsDir = statisticsDir; - } - - public long getMaxTriplesInSkolemStore() { - return maxTriplesInSkolemStore; - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/Separator.java b/src/uk/ac/ox/cs/pagoda/util/Separator.java deleted file mode 100644 index 1e6ad9c..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/Separator.java +++ /dev/null @@ -1,11 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -public class Separator { - - public static final String FILE = System.getProperty("file.separator"); - public static final String LINE = System.getProperty("line.separator"); - public static final String INDIVIDUAL = "\t"; - public static final String QUERY = "---------------------------------------------"; - - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java b/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java deleted file mode 100644 index 3c4aad7..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java +++ /dev/null @@ -1,48 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import uk.ac.ox.cs.pagoda.util.disposable.Disposable; - -public class SimpleProgressBar extends Disposable { - - private final String name; - private int lastPercent; - private int maxValue; - - public SimpleProgressBar() { - this(""); - } - - public SimpleProgressBar(String name) { - this(name, 100); - } - - public SimpleProgressBar(String name, int maxValue) { - this.name = name; - this.maxValue = maxValue; - } - - public void update(int value) { - int percent = value * 100 / maxValue; - StringBuilder template = new StringBuilder("\r" + name + " ["); - for (int i = 0; i < 50; i++) { - if (i < percent * .5) { - template.append("="); - } else if (i == percent * .5) { - template.append(">"); - } else { - template.append(" "); - } - } - template.append("] %s "); - System.out.printf(template.toString(), percent + "%"); - System.out.flush(); - lastPercent = percent; - } - - @Override - public void dispose() { - super.dispose(); - - System.out.println(); - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/SparqlHelper.java b/src/uk/ac/ox/cs/pagoda/util/SparqlHelper.java deleted file mode 100644 index 1e53b9c..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/SparqlHelper.java +++ /dev/null @@ -1,282 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import com.hp.hpl.jena.graph.Node; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.sparql.core.TriplePath; -import com.hp.hpl.jena.sparql.core.Var; -import com.hp.hpl.jena.sparql.syntax.*; -import org.semanticweb.HermiT.model.*; -import uk.ac.ox.cs.pagoda.MyPrefixes; -import uk.ac.ox.cs.pagoda.hermit.RuleHelper; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -public class SparqlHelper { - - public static String getSPARQLQuery(Atom[] atoms, String... vars) { - Set undistinguishedVars = new HashSet(); - for (int i = 0; i < atoms.length; ++i) { - atoms[i].getVariables(undistinguishedVars); - } - int xIndex = 1; - while (undistinguishedVars.contains(Variable.create("X" + xIndex))) ++xIndex; - - for (String var: vars) - if (var != null && !var.isEmpty()) - undistinguishedVars.remove(Variable.create(var)); - - StringBuffer buffer = new StringBuffer(); - if (vars.length > 0) - buffer.append("SELECT DISTINCT "); - else - buffer.append("SELECT *"); - for (int i = 0; i < vars.length; ++i) { - if (vars[i] != null && !vars[i].isEmpty()) - buffer.append("?").append(vars[i]).append(" "); - } - buffer.append( " WHERE {"); - for (Atom atom: atoms) - if (atom.getDLPredicate() instanceof AtLeastConcept) { - AtLeastConcept atLeast = (AtLeastConcept) atom.getDLPredicate(); - int number = atLeast.getNumber(); - for (int i = 0; i < number; ++i) { - Variable newVar = Variable.create("X" + (xIndex + i)); - - Atom tAtom; - if (atLeast.getOnRole() instanceof AtomicRole) - tAtom = Atom.create( - (AtomicRole) atLeast.getOnRole(), - atom.getArgument(0), - newVar); - else - tAtom = Atom.create( - (AtomicRole) atLeast.getOnRole().getInverse(), - newVar, - atom.getArgument(0)); - buffer.append(" "); - buffer.append(toSPARQLClause(tAtom, undistinguishedVars)); - buffer.append(" ."); - - if (!atLeast.getToConcept().equals(AtomicConcept.THING)) { - if (atLeast.getToConcept() instanceof AtomicConcept); - - tAtom = Atom.create((AtomicConcept) atLeast.getToConcept(), newVar); - buffer.append(" "); - buffer.append(toSPARQLClause(tAtom, undistinguishedVars)); - buffer.append(" ."); - } - } - - for (int i = 0; i < number; ++i) - for (int j = i + 1; j < number; ++j) { - Atom tAtom = Atom.create(Inequality.INSTANCE, Variable.create("X" + (xIndex + i)), Variable.create("X" + (xIndex + j))); - buffer.append(" "); - buffer.append(toSPARQLClause(tAtom, undistinguishedVars)); - buffer.append(" ."); - } - - xIndex += number; - } - else { - buffer.append(" "); - buffer.append(toSPARQLClause(atom, undistinguishedVars)); - buffer.append(" ."); - } - buffer.append(" ").append("}"); - return buffer.toString(); - } - - private static String toSPARQLClause(Atom atom, Set undisVars ) { - DLPredicate predicate = atom.getDLPredicate(); - String r, a, b; - - if (predicate instanceof Equality || predicate instanceof AnnotatedEquality) - atom = Atom.create(predicate = AtomicRole.create(Namespace.EQUALITY), atom.getArgument(0), atom.getArgument(1)); - else if (predicate instanceof Inequality) - atom = Atom.create(predicate = AtomicRole.create(Namespace.INEQUALITY), atom.getArgument(0), atom.getArgument(1)); - - if (predicate instanceof AtomicConcept) { - r = Namespace.RDF_TYPE_QUOTED; - a = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(getName(atom.getArgument(0), undisVars)); - b = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(RuleHelper.getText(predicate)); - } - else if (predicate instanceof AtomicRole) { - r = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(RuleHelper.getText(predicate)); - a = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(getName(atom.getArgument(0), undisVars)); - b = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(getName(atom.getArgument(1), undisVars)); - } - else if (predicate instanceof AtomicDataRange) { - r = Namespace.RDF_TYPE_QUOTED; - a = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(getName(atom.getArgument(0), undisVars)); - b = MyPrefixes.PAGOdAPrefixes.getQuotedIRI(RuleHelper.getText(predicate)); - } - else { - Utility.logError("error!!!!!!!!!!!"); - return null; - } - - return a + " " + r + " " + b; - } - - private static String getName(Term t, Set undisVars) { - if (t instanceof Variable) - if (undisVars.contains(t)) - return "_:" + ((Variable) t).getName(); - else return "?" + ((Variable) t).getName(); - return MyPrefixes.PAGOdAPrefixes.abbreviateIRI(t.toString()); - } - - public static Query parse(String text, Collection vars, Collection atoms) { - Query query = QueryFactory.create(text); - if (vars != null) { - vars.clear(); - for (Var var: query.getProjectVars()) - vars.add(var.getName()); - } - ElementVisitor visitor = new MySparqlElementVisitor(atoms); - query.getQueryPattern().visit(visitor); - return query; - } - -} - -class MySparqlElementVisitor implements ElementVisitor { - - Collection atoms; - - public MySparqlElementVisitor(Collection atoms) { - this.atoms = atoms; - } - - @Override - public void visit(ElementSubQuery el) { - Utility.logError("ElmentSubQuery: " + el); - } - - @Override - public void visit(ElementService el) { - // TODO Auto-generated method stub - Utility.logError("ElementService: " + el); - } - - @Override - public void visit(ElementMinus el) { - // TODO Auto-generated method stub - Utility.logError("ElementMinus: " + el); - } - - @Override - public void visit(ElementNotExists el) { - // TODO Auto-generated method stub - Utility.logError("ElementNotExists: " + el); - } - - @Override - public void visit(ElementExists el) { - // TODO Auto-generated method stub - Utility.logError("ElementExists: " + el); - } - - @Override - public void visit(ElementNamedGraph el) { - // TODO Auto-generated method stub - Utility.logError("ElementNamedGraph: " + el); - } - - @Override - public void visit(ElementDataset el) { - // TODO Auto-generated method stub - Utility.logError("ElementDataset: " + el); - } - - @Override - public void visit(ElementGroup el) { - // TODO Auto-generated method stub - for (Element e: el.getElements()) - e.visit(this); - } - - @Override - public void visit(ElementOptional el) { - // TODO Auto-generated method stub - Utility.logError("ElementOptional: " + el); - } - - @Override - public void visit(ElementUnion el) { - // TODO Auto-generated method stub - Utility.logError("ElementUnion: " + el); - } - - @Override - public void visit(ElementBind el) { - // TODO Auto-generated method stub - Utility.logError("ElementBind: " + el); - } - - @Override - public void visit(ElementAssign el) { - // TODO Auto-generated method stub - Utility.logError("ElementAssign: " + el); - } - - @Override - public void visit(ElementFilter el) { - // TODO Auto-generated method stub - Utility.logError("ElementFilter: " + el); - } - - @Override - public void visit(ElementPathBlock el) { - // TODO Auto-generated method stub - for (TriplePath p: el.getPattern().getList()) { - if (p.getPredicate().isVariable()) { - AtomicRole r = AtomicRole.create("?" + p.getPredicate().getName()); - Term a = getTerm(p.getSubject()), b = getTerm(p.getObject()); - atoms.add(Atom.create(r, a, b)); - } - else if (p.getPredicate().getURI().equals(Namespace.RDF_TYPE) && !p.getObject().isVariable()) { - AtomicConcept A = AtomicConcept.create(p.getObject().getURI()); - Term c = getTerm(p.getSubject()); - atoms.add(Atom.create(A, c)); - } - else { - AtomicRole r = AtomicRole.create(p.getPredicate().getURI()); - Term a = getTerm(p.getSubject()), b = getTerm(p.getObject()); - atoms.add(Atom.create(r, a, b)); - } - } - } - - private Term getTerm(Node node) { - if (node.isVariable()) - return Variable.create(node.getName()); - if (node.isLiteral()) - if (node.getLiteralDatatypeURI() == null) - return Constant.create(node.getLiteralLexicalForm(), Namespace.XSD_STRING); - else - return Constant.create(node.getLiteralLexicalForm(), node.getLiteralDatatypeURI()); - - - if (node.isURI()) - return Individual.create(node.getURI()); - Utility.logError("unknown node: " + node); - return null; - } - - @Override - public void visit(ElementTriplesBlock el) { - // TODO Auto-generated method stub - - Utility.logError("ElementTriplesBlock: " + el); - } - - @Override - public void visit(ElementData el) { - // TODO Auto-generated method stub - - } -} \ No newline at end of file diff --git a/src/uk/ac/ox/cs/pagoda/util/Timer.java b/src/uk/ac/ox/cs/pagoda/util/Timer.java deleted file mode 100644 index d1814a4..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/Timer.java +++ /dev/null @@ -1,52 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -public class Timer { - - double pastTime = 0; - boolean active = false; - - long startTime; - - public Timer() { - resume(); - } - - public void resume() { - if (active) return; - startTime = System.currentTimeMillis();; - active = true; - } - - public double duration() { - double time = pastTime; - if (active) - time += (System.currentTimeMillis() - startTime) / 1000.; - return time; - } - - public void pause() { - if (!active) return ; - pastTime = duration(); - active = false; - } - - public double reset() { - double ret = duration(); - pastTime = 0; - active = false; - resume(); - return ret; - } - - double timeout = -1; - - public boolean timeOut() { - if (timeout < 0) return false; - return duration() > timeout; - } - - public void setTimeout(double timeout) { - this.timeout = timeout; - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/TurtleHelper.java b/src/uk/ac/ox/cs/pagoda/util/TurtleHelper.java deleted file mode 100644 index 6887b9f..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/TurtleHelper.java +++ /dev/null @@ -1,56 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import java.io.*; - -public class TurtleHelper { - - public static void simplify(String tempFile, String outputPath) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile))); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath))); - - String line, sub = null, pred = null, obj = null; - char lastSymbol = '.', symbol; - String[] seg; - while ((line = reader.readLine()) != null) { - if (line.trim().isEmpty() || line.startsWith("#") || line.startsWith("@base")) - continue; - - if (line.startsWith("@")) { - writer.write(line); - writer.newLine(); - continue; - } - - - symbol = line.charAt(line.length() - 1); - - if (lastSymbol == '.') { - seg = line.split(" "); - sub = seg[0]; - pred = seg[1]; - obj = seg[2]; - } - else if (lastSymbol == ';') { - line = line.substring(sub.length() + 1); - seg = line.split(" "); - pred = seg[0]; - obj = seg[1]; - } - else if (lastSymbol == ',') { - line = line.substring(sub.length() + pred.length() + 2); - obj = line.substring(0, line.lastIndexOf(' ')); - } - else Utility.logError("ERROR"); - - lastSymbol = symbol; - if (pred.equals("rdf:type") && obj.startsWith("owl:")) - continue; - - writer.write(sub + " " + pred + " " + obj + " .\n"); - } - - reader.close(); - writer.close(); - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/UFS.java b/src/uk/ac/ox/cs/pagoda/util/UFS.java deleted file mode 100644 index 0869fb7..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/UFS.java +++ /dev/null @@ -1,45 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class UFS { - - private Map groups = new HashMap(); - - public boolean merge(T t1, T t2) { - t1 = find(t1); t2 = find(t2); - if (t1.equals(t2)) return false; - if (t2.toString().contains("cs.ox.ac.uk")) - groups.put(t2, t1); - else - groups.put(t1, t2); - return true; - } - - public Set keySet() { - return groups.keySet(); - } - - public T find(T u) { - T v, w = u; - while ((v = groups.get(u)) != null) - u = v; - - while ((v = groups.get(w)) != null) { - groups.put(w, u); - w = v; - } - - return u; - } - - public void clear() { - groups.clear(); - } - - public boolean isEmpty() { - return groups.isEmpty(); - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/Utility.java b/src/uk/ac/ox/cs/pagoda/util/Utility.java deleted file mode 100644 index cef4abd..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/Utility.java +++ /dev/null @@ -1,251 +0,0 @@ -package uk.ac.ox.cs.pagoda.util; - -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.semanticweb.HermiT.model.Atom; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.text.SimpleDateFormat; -import java.util.*; - -public class Utility { - - public static final String JAVA_FILE_SEPARATOR = "/"; - public static final String FILE_SEPARATOR = System.getProperty("file.separator"); - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - public static final int TEST = -1; - public static final int FLY = 0; - public static final int UOBM = 1; - public static final int LUBM = 2; - public static final int AEO = 3; - public static final int WINE = 4; - private static final String TEMP_DIR_PATH = "pagoda_tmp"; - static Stack outs = new Stack(); - private static Logger LOGS; - private static String tempDir; - private static int asciiX = (int) 'X'; - private static StringBuilder logMessage = new StringBuilder(); - - static { - LOGS = Logger.getLogger("Pagoda"); - LOGS.setLevel(Level.DEBUG); - } - - static { - outs.push(System.out); - } - - static { - - } - - public static String getGlobalTempDirAbsolutePath() { - if(tempDir == null) { - try { - Path path = Files.createTempDirectory(TEMP_DIR_PATH); - tempDir = path.toString(); - new File(tempDir).deleteOnExit(); - } catch(IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - return tempDir; - } - - public static Set toSet(Atom[] data) { - HashSet ret = new HashSet(); - for(Atom element : data) - ret.add(element); - return ret; - } - - public static boolean redirectSystemOut() - { - String stamp = new SimpleDateFormat( "HH:mm:ss").format(new Date()); - return redirectCurrentOut("./console" + stamp + ".txt"); - } - - public static boolean redirectCurrentOut(String fileName) - { - File file = new File(fileName); - PrintStream out; - try { - out = new PrintStream(new FileOutputStream(file)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return false; - } - outs.push(out); - System.setOut(out); - return true; - } - - public static void closeCurrentOut() { - if (!outs.isEmpty()) - outs.pop().close(); - - if(!outs.isEmpty()) - System.setOut(outs.peek()); - } - - public static void sparql2expression(String input, String output) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input))); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output))); - boolean first; - String line, query; - while ((line = reader.readLine()) != null) { - if (line.startsWith("^")) { - for (int i = 0; i < 4; ++i) - line = reader.readLine(); - first = true; - query = ""; - while ((line = reader.readLine()) != null && !line.startsWith("}")) - if (first) { - first = false; - query = expression(line.trim()); - } - else query += ", " + expression(line.trim()); - writer.write(query); - writer.newLine(); - } - } - reader.close(); - writer.close(); - } - - private static String expression(String line) { - String[] parts = line.split(" "); - if (parts[1].equals("rdf:type")) { - return parts[2] + "(?" + variableIndex(parts[0]) + ")"; - } - else return parts[1] + "(?" + variableIndex(parts[0]) + ",?" + variableIndex(parts[2]) + ")"; - } - - private static int variableIndex(String exp) { - char var = exp.charAt(1); - return (int)var - asciiX; - } - - public static String readLine(BufferedReader reader) throws IOException { - String line = reader.readLine(); - if (line == null) - return null; - return line.trim(); - } - - public static String getTextfromFile(String fileName) throws FileNotFoundException { - Scanner scanner = new Scanner(new File(fileName)); - String program = scanner.useDelimiter("\\Z").next(); - scanner.close(); - return program; - } - - public static String[] getPattern(BufferedReader answerReader) throws IOException { - String lastLine = readLine(answerReader), line; - while ((line = readLine(answerReader)) != null && !line.startsWith("---------")) - lastLine = line; - return lastLine.split(" "); - } - - public static void removeRecursively(File file) { - if (!file.exists()) return; - - if (file.isDirectory()) - for (File tFile: file.listFiles()) - removeRecursively(tFile); - file.delete(); - } - - public static void removeRecursively(String fileName) { - removeRecursively(new File(fileName)); - } - - public static Collection getQueryTexts(String fileName) throws IOException { - BufferedReader queryReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); - String line; - Collection queryTexts = new LinkedList(); - while (true) { - while((line = queryReader.readLine()) != null && ((line = line.trim()).isEmpty() || line.startsWith("#"))) ; - if (line == null) { - queryReader.close(); - return queryTexts; - } - - StringBuffer query = new StringBuffer(); - if (!line.startsWith("^[")) - query.append(line).append(LINE_SEPARATOR); - - while((line = queryReader.readLine()) != null && !line.trim().endsWith("}")) - query.append(line).append(LINE_SEPARATOR); - query.append(line); - queryTexts.add(query.toString()); - } - } - - /** - * - * @param answerReader - * @return all lines before the next empty line - * @throws IOException - */ - public static Collection getLines(BufferedReader answerReader) throws IOException { - Collection answerTuples = new LinkedList(); - String line; - while ((line = answerReader.readLine()) != null) { - line = line.trim(); - if (line.isEmpty()) - break; - answerTuples.add(line); - } - return answerTuples; - } - - private static String getLogMessage(Object[] messages) { - if (messages.length == 1) return messages[0].toString(); - else { - logMessage.setLength(0); - for (int i = 0; i < messages.length; ++i) { - if (logMessage.length() != 0) - logMessage.append(LINE_SEPARATOR); - logMessage.append(messages[i]); - } - return logMessage.toString(); - } - - } - - public static void setLogLevel(Level level) { - LOGS.setLevel(level); - } - - public static void logInfo(Object... messages) { - if (LOGS != null) - LOGS.info(getLogMessage(messages)); - } - - public static void logTrace(Object... messages) { - if (LOGS != null) - LOGS.trace(getLogMessage(messages)); - } - - public static void logDebug(Object... messages) { - if (LOGS != null) - LOGS.debug(getLogMessage(messages)); - } - - public static void logError(Object... messages) { - if (LOGS != null) - LOGS.error(getLogMessage(messages)); - } - - public static String toFileIRI(String path) { - String iri; - if (path.startsWith(FILE_SEPARATOR)) iri = "file:" + path; - else iri = "file:\\\\\\" + path; - return iri.replace(FILE_SEPARATOR, JAVA_FILE_SEPARATOR).replace(" ", "%20"); - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/data_structures/Graph.java b/src/uk/ac/ox/cs/pagoda/util/data_structures/Graph.java deleted file mode 100644 index 4f454df..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/data_structures/Graph.java +++ /dev/null @@ -1,38 +0,0 @@ -package uk.ac.ox.cs.pagoda.util.data_structures; - -import java.util.*; - -public class Graph { - - private final boolean isDirected; - - private Map> outEdgesOf = new HashMap<>(); - public Graph(boolean isDirected) { - this.isDirected = isDirected; - } - - public Graph() { - this(false); - } - public void addNode(V v) { - if(!outEdgesOf.containsKey(v)) - outEdgesOf.put(v, new HashSet()); - } - - public void addEdge(V v, V u) { - addNode(v); - addNode(u); - outEdgesOf.get(v).add(u); - - if(isDirected) - outEdgesOf.get(u).add(v); - } - - public Iterator getOutNeighbors(V v) { - return outEdgesOf.get(v).iterator(); - } - - public boolean isDirected() { - return isDirected; - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java b/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java deleted file mode 100644 index 4015b66..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java +++ /dev/null @@ -1,30 +0,0 @@ -package uk.ac.ox.cs.pagoda.util.disposable; - - -/** - * Every public method of a subclass of this class, - * as first instruction, should check if the object has already been disposed - * and, if so, should throw a DisposedException. - */ -public abstract class Disposable { - - private boolean disposed = false; - - /** - * This method must be called after the use of the object. - *

- * Every overriding method must call super.dispose() as first instruction. - */ - public void dispose() { - if(isDisposed()) throw new AlreadyDisposedException(); - disposed = true; - } - - public final boolean isDisposed() { - return disposed; - } - - private class AlreadyDisposedException extends RuntimeException { - } - -} diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java b/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java deleted file mode 100644 index eb8c039..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java +++ /dev/null @@ -1,12 +0,0 @@ -package uk.ac.ox.cs.pagoda.util.disposable; - -public class DisposedException extends RuntimeException { - - public DisposedException() { - super(); - } - - public DisposedException(String msg) { - super(msg); - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/tuples/Tuple.java b/src/uk/ac/ox/cs/pagoda/util/tuples/Tuple.java deleted file mode 100644 index 0a5983c..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/tuples/Tuple.java +++ /dev/null @@ -1,54 +0,0 @@ -package uk.ac.ox.cs.pagoda.util.tuples; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.Spliterator; -import java.util.function.Consumer; - -public class Tuple implements Iterable { - - final ArrayList elements = new ArrayList<>(); - - Tuple() { } - - @SafeVarargs - public Tuple(T... elements) { - Collections.addAll(this.elements, elements); - } - - public Tuple(Iterable iterable) { - for (T t : iterable) { - this.elements.add(t); - } - } - - public T get(int i) { - return elements.get(i); - } - - @Override - public Iterator iterator() { - return elements.iterator(); - } - - @Override - public void forEach(Consumer action) { - elements.forEach(action); - } - - @Override - public Spliterator spliterator() { - return elements.spliterator(); - } - - @Override - public int hashCode() { - return elements.hashCode() + getClass().hashCode(); - } - - @Override - public String toString() { - return elements.toString(); - } -} diff --git a/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java b/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java deleted file mode 100644 index 172e249..0000000 --- a/src/uk/ac/ox/cs/pagoda/util/tuples/TupleBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -package uk.ac.ox.cs.pagoda.util.tuples; - -import java.util.Collections; - -/** - * Allows to create an immutable Tuple in a non-atomic way. - * It can create only one Tuple. - * */ -public class TupleBuilder { - - private Tuple tuple = new Tuple(); - - private boolean building = true; - - public TupleBuilder append(T t) { - if(building) { - tuple.elements.add(t); - return this; - } - return null; - } - - public TupleBuilder append(T[] t) { - if(building) { - Collections.addAll(tuple.elements, t); - return this; - } - return null; - } - - public Tuple build() { - if(building) { - building = false; - return tuple; - } - return null; - } -} -- cgit v1.2.3