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.kb.manipulator; 020 021import java.util.SortedSet; 022 023import org.dllearner.kb.extraction.Node; 024import org.dllearner.utilities.datastructures.RDFNodeTuple; 025import org.dllearner.utilities.owl.OWLVocabulary; 026 027import org.apache.jena.rdf.model.Literal; 028import org.apache.jena.rdf.model.RDFNode; 029import org.apache.jena.rdf.model.impl.ResourceImpl; 030 031 032public class DBpediaNavigatorOtherRule extends Rule{ 033 034 035 public DBpediaNavigatorOtherRule(Months month){ 036 super(month); 037 } 038 // Set<String> classproperties; 039 040 @Override 041 public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ 042 float lat=0; 043 float lng=0; 044 RDFNode clazz = null; 045 RDFNodeTuple typeTuple = null; 046 for (RDFNodeTuple tuple : tuples) { 047 048 if (tuple.a.toString().equals(OWLVocabulary.RDF_TYPE)){ 049 clazz = tuple.b; 050 typeTuple = tuple; 051 } 052 053 054 if (tuple.a.toString().equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat") && tuple.b.isLiteral()){ 055 lat = ((Literal) tuple.b).getFloat(); 056 //lat=Float.parseFloat(tuple.b.toString().substring(0,tuple.b.toString().indexOf("^^"))); 057 } 058 if (tuple.a.toString().equals("http://www.w3.org/2003/01/geo/wgs84_pos#long") && tuple.b.isLiteral()) { 059 lng = ((Literal) tuple.b).getFloat(); 060 //lng=Float.parseFloat(tuple.b.toString().substring(0,tuple.b.toString().indexOf("^^"))); 061 } 062 063 }//end for 064 if (clazz.toString().equals("http://dbpedia.org/class/yago/City108524735")){ 065 String newType = getTypeToCoordinates(lat, lng); 066 tuples.add(new RDFNodeTuple(new ResourceImpl(OWLVocabulary.RDF_TYPE),new ResourceImpl(newType))); 067 //tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); 068 tuples.remove(typeTuple); 069 } 070 071 return tuples; 072 } 073 074 public static String getTypeToCoordinates(float lat, float lng){ 075 if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ 076 if (lat>50&&lat<52&&lng>12&&lng<13){ 077 return "http://dbpedia.org/class/custom/City_in_Saxony"; 078 } 079 else return "http://dbpedia.org/class/custom/City_in_Europe"; 080 } 081 else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ 082 if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ 083 return "http://dbpedia.org/class/custom/City_in_Egypt"; 084 } 085 else return "http://dbpedia.org/class/custom/City_in_Africa"; 086 } 087 else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ 088 return "http://dbpedia.org/class/custom/City_in_Asia"; 089 } 090 else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ 091 return "http://dbpedia.org/class/custom/City_in_Australia"; 092 } 093 else if (lng>-168.4&&lng<-19.7&&lat>6.6){ 094 return "http://dbpedia.org/class/custom/City_in_North_America"; 095 } 096 else if (lng>-81.56&&lng<-34.1&&lat<6.6){ 097 return "http://dbpedia.org/class/custom/City_in_South_America"; 098 } 099 else return "http://dbpedia.org/class/custom/City_in_World"; 100 } 101 102 @Override 103 public void logJamon(){ 104 105 } 106 107}