001    /**
002     * Copyright (C) 2007-2011, 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    
020    package org.dllearner.kb.sparql;
021    
022    import java.net.URL;
023    import java.util.LinkedList;
024    import java.util.List;
025    
026    /**
027     * One sparql endpoint configuration,
028     * made to comply with Jena.
029     * 
030     * @author Sebastian Hellmann
031     *
032     */
033    public class SparqlEndpoint {
034            URL url;
035            List<String> defaultGraphURIs;
036            List<String> namedGraphURIs;
037            
038            //public HashMap<String, String> parameters = new HashMap<String, String>();
039    
040            public SparqlEndpoint(URL u) {
041                    this.url = u;
042                    this.defaultGraphURIs=new LinkedList<String>();
043                    this.namedGraphURIs=new LinkedList<String>();
044            }
045            
046            public SparqlEndpoint(URL u, List<String> defaultGraphURIs, List<String> namedGraphURIs) {
047                    this.url = u;
048                    this.defaultGraphURIs=defaultGraphURIs;
049                    this.namedGraphURIs=namedGraphURIs;
050            }
051            
052            public URL getURL() {
053                    return this.url;
054            }
055            
056            public String getHTTPRequest() {
057                    String ret = this.url.toString()+"?";
058                    ret += (defaultGraphURIs.isEmpty())?"":"default-graph-uri="+defaultGraphURIs.get(0)+"&";
059                    ret += "query="; 
060                    return ret;
061            }
062    
063            public List<String> getDefaultGraphURIs() {
064                    return defaultGraphURIs;
065            }
066    
067            public List<String> getNamedGraphURIs() {
068                    return namedGraphURIs;
069            }
070            
071            @Override
072            public String toString(){
073                    return getHTTPRequest();
074            }
075            
076            
077            public static SparqlEndpoint getEndpointByName(String name) {
078    
079                    name = name.toUpperCase();
080                    
081                    if (name.equals("DBPEDIA")) {
082                            return getEndpointDBpedia();
083                    } else if (name.equals("LOCALDBPEDIA")) {
084                            return getEndpointLOCALDBpedia();
085                    } else if (name.equals("LOCALGEONAMES")) {
086                            return getEndpointLOCALGeonames();
087                    } else if (name.equals("LOCALGEODATA")) {
088                            return getEndpointLOCALGeoData();
089                    } else if (name.equals("LOCALJOSECKI") || name.equals("LOCALJOSEKI") ) {
090                            return getEndpointlocalJoseki();
091                    } else if (name.equals("LOCALJOSEKIBIBLE")||name.equals("LOCALJOSECKIBIBLE")) {
092                            return getEndpointLocalJosekiBible();
093                    } else if (name.equals("GOVTRACK")) {
094                            return getEndpointGovTrack();
095                    } else if (name.equals("SPARQLETTE")) {
096                            return getEndpointSparqlette();
097                    } else if (name.equals("SWCONFERENCE")) {
098                            return getEndpointSWConference();
099                    } else if (name.equals("REVYU")) {
100                            return getEndpointRevyu();
101                    } else if (name.equals("MYOPENLINK")) {
102                            return getEndpointMyOpenlink();
103                    } else if (name.equals("FACTBOOK")) {
104                            return getEndpointWorldFactBook();
105                    } else if (name.equals("DBLP")) {
106                            return getEndpointDBLP();
107                    } else if (name.equals("MUSICBRAINZ")) {
108                            return getEndpointMusicbrainz();
109                    } else {
110                            return null;
111                            }
112            }
113            
114            
115            public static List<SparqlEndpoint> listEndpoints() {
116                    LinkedList<SparqlEndpoint> ll =new LinkedList<SparqlEndpoint>();
117                    ll.add(getEndpointDBLP());
118                    ll.add(getEndpointDBpedia());
119                    ll.add(getEndpointDOAPspace());
120                    ll.add(getEndpointGovTrack());
121                    ll.add(getEndpointJamendo());
122                    ll.add(getEndpointJohnPeel());
123                    ll.add(getEndpointlocalJoseki());
124                    ll.add(getEndpointMagnaTune());
125                    ll.add(getEndpointMusicbrainz());
126                    ll.add(getEndpointMyOpenlink());
127                    ll.add(getEndpointRevyu());
128                    ll.add(getEndpointSWConference());
129                    ll.add(getEndpointUSCensus());
130                    ll.add(getEndpointWorldFactBook());
131                    ll.add(getEndpointRiese());
132                    ll.add(getEndpointTalisBlogs());
133                    ll.add(getEndpointSWSchool());
134                    ll.add(getEndpointSparqlette());
135                    ll.add(getEndpointLOCALDBpedia());
136                    return ll;
137            }
138            
139            public static SparqlEndpoint getEndpointDBpedia() {
140                    URL u = null;
141                    try { 
142                            u = new URL("http://dbpedia.org/sparql");
143    //                      u = new URL("http://dbpedia.openlinksw.com:8890/sparql");
144                    } catch (Exception e) {
145                            e.printStackTrace();
146                    }
147                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
148                    defaultGraphURIs.add("http://dbpedia.org");
149                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
150            }
151            
152            public static SparqlEndpoint getEndpointLOCALDBpedia() {
153                    URL u = null;
154                    try { 
155                            u = new URL("http://139.18.2.37:8890/sparql");
156                    } catch (Exception e) {
157                            e.printStackTrace();
158                    }
159                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
160                    defaultGraphURIs.add("http://dbpedia.org");
161                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
162            }
163            
164            public static SparqlEndpoint getEndpointDBpediaAKSW() {
165                    URL u = null;
166                    try { 
167                            u = new URL("http://dbpedia.aksw.org:8890/sparql");
168                    } catch (Exception e) {
169                            e.printStackTrace();
170                    }
171                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
172                    defaultGraphURIs.add("http://dbpedia.org");
173                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
174            }
175            
176            public static SparqlEndpoint getEndpointDBpediaLiveAKSW() {
177                    URL u = null;
178                    try { 
179    //                      u = new URL("http://dbpedia.aksw.org:8899/sparql");
180                            u = new URL("http://live.dbpedia.org/sparql");
181                    } catch (Exception e) {
182                            e.printStackTrace();
183                    }
184                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
185                    defaultGraphURIs.add("http://dbpedia.org");
186                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
187            }
188            
189            public static SparqlEndpoint getEndpointDBpediaHanne() {
190                    URL u = null;
191                    try { 
192                            u = new URL("http://hanne.aksw.org:8892/sparql");
193                    } catch (Exception e) {
194                            e.printStackTrace();
195                    }
196                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
197                    defaultGraphURIs.add("http://dbpedia.org");
198                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
199            }
200            
201            public static SparqlEndpoint getEndpointDBpediaLiveOpenLink() {
202                    URL u = null;
203                    try { 
204                            u = new URL("http://dbpedia-live.openlinksw.com/sparql");
205                    } catch (Exception e) {
206                            e.printStackTrace();
207                    }
208                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
209                    defaultGraphURIs.add("http://dbpedia.org");
210                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
211            }
212            
213            public static SparqlEndpoint getEndpointLinkedGeoData() {
214                    URL u = null;
215                    try { 
216                            u = new URL("http://linkedgeodata.org/sparql");
217                    } catch (Exception e) {
218                            e.printStackTrace();
219                    }
220                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
221                    //TODO defaultGraphURIs.add("http://geonames.org");
222                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
223            }       
224    
225            public static SparqlEndpoint getEndpointLOCALGeonames() {
226                    URL u = null;
227                    try { 
228                            u = new URL("http://139.18.2.37:8890/sparql");
229                    } catch (Exception e) {
230                            e.printStackTrace();
231                    }
232                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
233                    defaultGraphURIs.add("http://geonames.org");
234                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
235            }       
236            
237            public static SparqlEndpoint getEndpointLOCALGeoData() {
238                    URL u = null;
239                    try { 
240                            u = new URL("http://139.18.2.37:8890/sparql");
241                    } catch (Exception e) {
242                            e.printStackTrace();
243                    }
244                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
245                    defaultGraphURIs.add("http://linkedgeodata.org");
246                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
247            }               
248            
249            public static SparqlEndpoint getEndpointlocalJoseki() {
250                    URL u = null;
251                    try { 
252                            u = new URL("http://localhost:2020/books");
253                    } catch (Exception e) {
254                            e.printStackTrace();
255                    }
256                    return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
257            }
258            
259            public static SparqlEndpoint getEndpointLocalJosekiBible() {
260                    URL u = null;
261                    try { 
262                            u = new URL("http://localhost:2020/bible");
263                    } catch (Exception e) {
264                            e.printStackTrace();
265                    }
266                    return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
267            }
268            
269            public static SparqlEndpoint getEndpointWorldFactBook() {
270                    URL u = null;
271                    try { 
272                            u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql");
273                    } catch (Exception e) {
274                            e.printStackTrace();
275                    }
276                    return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
277            }
278            
279    
280            public static SparqlEndpoint getEndpointGovTrack() {
281                    URL u = null;
282                    try { 
283                            u = new URL("http://www.rdfabout.com/sparql");
284                    } catch (Exception e) {
285                            e.printStackTrace();
286                    }
287                    return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
288            }
289            
290            public static SparqlEndpoint getEndpointRevyu() {
291                    URL u = null;
292                    try { 
293                            u = new URL("http://revyu.com/sparql");
294                    } catch (Exception e) {
295                            e.printStackTrace();
296                    }
297                    return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
298            }
299            
300            public static SparqlEndpoint getEndpointMyOpenlink() {
301                    URL u = null;
302                    try { 
303                            u = new URL("http://myopenlink.net:8890/sparql/");
304                    } catch (Exception e) {
305                            e.printStackTrace();
306                    }
307                    LinkedList<String> defaultGraphURIs=new LinkedList<String>();
308                    defaultGraphURIs.add("http://myopenlink.net/dataspace");
309                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
310    
311                    }
312            
313            public static SparqlEndpoint getEndpointDOAPspace() {
314                    URL u = null;
315                    try { 
316                            u = new URL("http://doapspace.org/sparql");
317                    } catch (Exception e) {
318                            e.printStackTrace();
319                    }
320                    
321                    return new SparqlEndpoint(u);
322    
323                    }
324            
325            public static SparqlEndpoint getEndpointJohnPeel() {
326                    URL u = null;
327                    try { 
328                            u = new URL("http://dbtune.org:3030/sparql/");
329                    } catch (Exception e) {
330                            e.printStackTrace();
331                    }
332                    
333                    return new SparqlEndpoint(u);
334    
335                    }
336            
337            
338            
339                    public static SparqlEndpoint getEndpointSWConference() {
340                    URL u = null;
341                    try { 
342                            u = new URL("http://data.semanticweb.org:8080/openrdf-sesame/repositories/SWC");
343                    } catch (Exception e) {
344                            e.printStackTrace();
345                    }
346                    
347                    return new SparqlEndpoint(u);
348    
349                    }
350            // returns strange xml
351            /*
352            public static SpecificSparqlEndpoint dbtune() {
353                    URL u = null;
354                    HashMap<String, String> m = new HashMap<String, String>();
355                    // m.put("default-graph-uri", "http://dbpedia.org");
356                    // m.put("format", "application/sparql-results.xml");
357                    //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 
358                    http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D
359                            &resultFormat=xml
360                            &resourceFormat=ns&entailment=none
361                            http://dbtune.org:2020/evaluateQuery    
362                            ?repository=default&serialization=rdfxml&queryLanguage=SPARQL
363                                            &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D
364                            &resultFormat=xml
365                            &resourceFormat=ns&entailment=none
366                    try {
367                            u = new URL("http://dbtune.org:2020/sparql/");
368                    } catch (Exception e) {
369                            e.printStackTrace();
370                    }
371                    return new SpecificSparqlEndpoint(u, "dbtune.org", m);
372            }*/
373            
374             public static SparqlEndpoint getEndpointJamendo() {
375                            URL u = null;
376                            try { 
377                                    u = new URL("http://dbtune.org:2105/sparql/");
378                            } catch (Exception e) {
379                                    e.printStackTrace();
380                            }
381                            return new SparqlEndpoint(u);
382                    }
383            
384             
385                     
386             public static SparqlEndpoint getEndpointMagnaTune() {
387                    URL u = null;
388                    try { 
389                            u = new URL("http://dbtune.org:2020/sparql/");
390                    } catch (Exception e) {
391                            e.printStackTrace();
392                    }
393                    return new SparqlEndpoint(u);
394            }
395            
396             
397             public static SparqlEndpoint getEndpointMusicbrainz() {
398                     URL u = null;
399                     try { 
400                             u = new URL("http://dbtune.org/musicbrainz/sparql");
401                     } catch (Exception e) {
402                             e.printStackTrace();
403                     }
404                     return new SparqlEndpoint(u);
405             }
406             
407             public static SparqlEndpoint getEndpointRiese() {
408                     URL u = null;
409                     try { 
410                             u = new URL("http://riese.joanneum.at:3020/");
411                     } catch (Exception e) {
412                             e.printStackTrace();
413                     }
414                     return new SparqlEndpoint(u);
415             }
416            
417             
418             public static SparqlEndpoint getEndpointUSCensus() {
419                     URL u = null;
420                     try { 
421                             u = new URL("http://www.rdfabout.com/sparql");
422                     } catch (Exception e) {
423                             e.printStackTrace();
424                     }
425                     LinkedList<String> defaultGraphURIs=new LinkedList<String>();
426                            defaultGraphURIs.add("http://www.rdfabout.com/rdf/schema/census/");
427                    return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
428             }
429             
430             
431            
432             
433            /*
434             * it only has 4 classes
435             */
436             public static SparqlEndpoint getEndpointDBLP() {
437                    URL u = null;
438                    try { 
439                            u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql");
440                    } catch (Exception e) {
441                            e.printStackTrace();
442                    }
443                    return new SparqlEndpoint(u);
444            }
445             
446             
447             public static SparqlEndpoint getEndpointTalisBlogs() {
448                            URL u = null;
449                            try { 
450                                    u = new URL("http://api.talis.com/stores/talisians/services/sparql");
451                            } catch (Exception e) {
452                                    e.printStackTrace();
453                            }
454                            return new SparqlEndpoint(u);
455                    }
456             
457             public static SparqlEndpoint getEndpointSparqlette() {
458                            URL u = null;
459                            try { 
460                                    u = new URL("http://www.wasab.dk/morten/2005/04/sparqlette/");
461                            } catch (Exception e) {
462                                    e.printStackTrace();
463                            }
464                            return new SparqlEndpoint(u);
465                    }
466             
467             
468             
469             public static SparqlEndpoint getEndpointSWSchool() {
470                            URL u = null;
471                            try { 
472                                    u = new URL("http://sparql.semantic-web.at/snorql/");
473                            } catch (Exception e) {
474                                    e.printStackTrace();
475                            }
476                            return new SparqlEndpoint(u);
477                    }
478             
479            
480            
481            
482    
483    }