001    /**
002     * Copyright (C) 2007-2008, 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     **/
019    package org.dllearner.scripts;
020    
021    import java.util.SortedSet;
022    import java.util.TreeSet;
023    
024    import org.dllearner.kb.sparql.Cache;
025    import org.dllearner.kb.sparql.SPARQLTasks;
026    import org.dllearner.kb.sparql.SparqlEndpoint;
027    
028    /**
029     * @author Sebastian Hellmann
030     * This class is under developement and can not be completed,
031     * unless the & bug mentioned in SparqlQuery is completed
032     */
033    public class AutoDetectFilter {
034            private SPARQLTasks sparqlTasks;
035            private String resource;
036            public AutoDetectFilter(SPARQLTasks sparqlTasks, String resource) {
037                    super();
038                    this.sparqlTasks = sparqlTasks;
039                    this.resource = resource;
040            }
041            
042            public static void main(String[] args) {
043            //      String url = "http://139.18.2.37:8890/sparql";
044                    String resource = "http://dbpedia.org/resource/Angela_Merkel";
045                    //resource = "http://dbpedia.org/resource/Lutheran";
046                    AutoDetectFilter adf = new AutoDetectFilter(new SPARQLTasks(Cache.getDefaultCache(),
047                                    SparqlEndpoint.getEndpointDBpedia()),resource);
048                    
049                    adf.detect();
050            }
051            
052            public void detect(){
053                    String s1 = "SELECT * WHERE { <"+resource+"> ?predicate ?object .FILTER (!isLiteral(?object))}";
054                    String s2 = "SELECT * WHERE { <"+resource+"> ?predicate ?object .FILTER (!isLiteral(?object))." +
055                                    "?object ?p2 ?o2." +
056                                    " }";
057                    
058                    System.out.println(s1);
059                    //System.out.println(sparqlTasks.query(s2));
060                    //System.exit(0);
061                    
062                    SortedSet<String> predicates = new TreeSet<String>();
063                    SortedSet<String> objects = new TreeSet<String>();
064                    SortedSet<String> legalpreds = new TreeSet<String>();
065                    SortedSet<String> legalObjs = new TreeSet<String>();
066                    
067                    
068                    predicates = sparqlTasks.queryAsSet(s1, "predicate");
069                    objects = sparqlTasks.queryAsSet(s1, "object");
070                    legalpreds = sparqlTasks.queryAsSet(s2, "predicate");
071                    legalObjs = sparqlTasks.queryAsSet(s2, "object");
072                    
073                    
074                    System.out.println(predicates);
075                    System.out.println(legalpreds);
076                    predicates.removeAll(legalpreds);
077                    System.out.println(predicates);
078                    
079                    System.out.println(objects);
080                    System.out.println(legalObjs);
081                    objects.removeAll(legalObjs);
082                    System.out.println(objects);
083                    
084            }
085            
086    }