001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.algorithms.qtl.impl;
020
021import org.apache.jena.rdf.model.Model;
022import org.apache.jena.rdf.model.Resource;
023import org.apache.jena.rdf.model.Statement;
024import org.dllearner.algorithms.qtl.datastructures.impl.RDFResourceTree;
025
026import java.util.function.Predicate;
027
028/**
029 * @author Lorenz Buehmann
030 *
031 */
032public interface QueryTreeFactory {
033
034        /**
035         * Generates a query tree with the given resource as root and the edges based on the data contained in the model.
036         *
037         * @param resource the resource URI which is supposed to be the root of the query tree
038         * @param model the data
039         * @return the query tree
040         */
041        default RDFResourceTree getQueryTree(String resource, Model model) {
042                return getQueryTree(model.getResource(resource), model);
043        }
044
045        /**
046         * Generates a query tree with the given resource as root and the edges based on the data contained in the model.
047         *
048         * @param resource the resource which is supposed to be the root of the query tree
049         * @param model the data
050         * @return the query tree
051         */
052        default RDFResourceTree getQueryTree(Resource resource, Model model) {
053                return getQueryTree(resource, model, maxDepth());
054        }
055
056        /**
057         * Generates a query tree with the given resource as root and the edges based on the data contained in the model.
058         *
059         * @param resource the resource URI which is supposed to be the root of the query tree
060         * @param model the data
061         * @param maxDepth the maximum depth of the query tree
062         * @return the query tree
063         */
064        default RDFResourceTree getQueryTree(String resource, Model model, int maxDepth) {
065                return getQueryTree(model.getResource(resource), model, maxDepth);
066        }
067
068        /**
069         * Generates a query tree with the given resource as root and the edges based on the data contained in the model.
070         *
071         * @param resource the resource which is supposed to be the root of the query tree
072         * @param model the data
073         * @param maxDepth the maximum depth of the query tree
074         * @return the query tree
075         */
076        RDFResourceTree getQueryTree(Resource resource, Model model, int maxDepth);
077
078        /**
079         * @return the maximum depth of the generated query trees (Default: 3)
080         */
081        default int maxDepth() {
082                return 3;
083        }
084
085        /**
086         * @param maxDepth the maximum depth of the generated query trees
087         */
088        void setMaxDepth(int maxDepth);
089
090        /**
091         * Adds a set of filters that will be applied on the model before the creation of the query tree.
092         *
093         * @param dropFilters the filters
094         */
095        @SuppressWarnings("unchecked")
096        void addDropFilters(Predicate<Statement>... dropFilters);
097
098}