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.datastructures;
020
021import java.io.PrintWriter;
022import java.util.Comparator;
023import java.util.List;
024import java.util.Map;
025import java.util.Set;
026
027import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl;
028import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy;
029import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeSubsumptionStrategy;
030import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.NodeType;
031import org.semanticweb.owlapi.model.OWLClassExpression;
032
033import org.apache.jena.datatypes.RDFDatatype;
034import org.apache.jena.query.Query;
035import org.apache.jena.rdf.model.Literal;
036
037/**
038 * 
039 * @author Lorenz Bühmann
040 *
041 */
042public interface QueryTree<N> {
043        
044         /**
045     * Gets the "content" of this tree node.
046     * @return The user content of this node.
047     */
048    N getUserObject();
049    
050    void setUserObject(N userObject);
051    
052    /**
053     * Set the ID of the current node
054     * @param id the ID
055     */
056    void setId(int id);
057    
058    /**
059     * @return the ID of the tree node in the whole tree
060     */
061    int getId();
062    
063    boolean isEmpty();
064    
065    QueryTree<N> getNodeById(int nodeId);
066    
067    boolean sameType(QueryTree<N> tree);
068        
069    boolean isLiteralNode();
070    
071    void setIsLiteralNode(boolean isLiteralNode);
072    
073    boolean isResourceNode();
074    
075    void setIsResourceNode(boolean isResourceNode);
076    
077    boolean isVarNode();
078    
079    void setVarNode(boolean isVarNode);
080
081    QueryTree<N> getParent();
082    
083    List<QueryTree<N>> getChildren();
084    
085    List<QueryTree<N>> getChildren(Object edge);
086    
087    List<QueryTree<N>> getChildrenClosure();
088
089    Object getEdge(QueryTree<N> child);
090    
091    void addChild(QueryTreeImpl<N> child);
092    
093    void addChild(QueryTreeImpl<N> child, int position);
094    
095    void addChild(QueryTreeImpl<N> child, Object edge);
096    
097    void addChild(QueryTree<N> child, Object edge);
098    
099    void addChild(QueryTreeImpl<N> child, Object edge, int position);
100    
101    int removeChild(QueryTreeImpl<N> child);
102    
103    Set<Object> getEdges();
104    
105    void sortChildren(Comparator<QueryTree<N>> comparator);
106
107    int getChildCount();
108    
109    int getMaxDepth();
110
111    boolean isRoot();
112
113    boolean isLeaf();
114    
115    boolean isSubsumedBy(QueryTree<N> tree);
116    
117    boolean isSubsumedBy(QueryTree<N> tree, boolean stopAfterError);
118    
119    boolean isSameTreeAs(QueryTree<N> tree);
120    
121    void tag();
122    
123    boolean isTagged();
124
125    QueryTree<N> getRoot();
126    
127    List<QueryTree<N>> getLeafs();
128
129    List<QueryTree<N>> getPathToRoot();
130
131    List<N> getUserObjectPathToRoot();
132    
133    void dump();
134    
135    String getStringRepresentation();
136
137    void dump(PrintWriter writer);
138
139    void dump(PrintWriter writer, int indent);
140
141    Set<N> getUserObjectClosure();
142
143    List<N> fillDepthFirst();
144    
145    String toSPARQLQueryString();
146    
147    String toSPARQLQueryString(boolean filterMeaninglessProperties, boolean useNumericalFilters);
148    
149    String toSPARQLQueryString(boolean filterMeaninglessProperties, boolean useNumericalFilters, Map<String, String> prefixMap);
150    
151    Query toSPARQLQuery();
152    
153    OWLClassExpression asOWLClassExpression();
154    
155    int getTriplePatternCount();
156    
157    Query toQuery();
158    
159    RDFDatatype getDatatype();
160    
161    Set<Literal> getLiterals();
162    
163    void setParent(QueryTree<N> parent);
164
165        /**
166         * @param edge
167         */
168        void removeChildren(Object edge);
169
170        /**
171         * @param stopIfChildIsResourceNode
172         * @return
173         */
174        String getStringRepresentation(boolean stopIfChildIsResourceNode);
175
176        /**
177         * @param literalNodeConversionStrategy
178         * @return
179         */
180        OWLClassExpression asOWLClassExpression(LiteralNodeConversionStrategy literalNodeConversionStrategy);
181
182        /**
183         * @param tree
184         * @param s
185         * @return
186         */
187        boolean isSubsumedBy(QueryTree<N> tree, LiteralNodeSubsumptionStrategy s);
188
189        /**
190         * @return
191         */
192        NodeType getNodeType();
193    
194}