Strabon
changeset 1020:0e7f541cad34
a bit of cleaning in GeosparqlRDFHandlerBase
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Tue Apr 09 02:27:21 2013 +0300 (2013-04-09) |
parents | f488c7c3d433 |
children | bc46378b62b3 |
files | runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java |
line diff
1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java Tue Apr 09 02:16:25 2013 +0300 1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java Tue Apr 09 02:27:21 2013 +0300 1.3 @@ -9,7 +9,6 @@ 1.4 */ 1.5 package eu.earthobservatory.runtime.generaldb; 1.6 1.7 -import java.io.StringReader; 1.8 import java.util.Hashtable; 1.9 1.10 import org.openrdf.model.Resource; 1.11 @@ -24,15 +23,19 @@ 1.12 import org.openrdf.repository.RepositoryConnection; 1.13 import org.openrdf.repository.util.RDFInserter; 1.14 import org.openrdf.rio.RDFHandlerException; 1.15 -import org.openrdf.rio.ntriples.NTriplesParser; 1.16 import org.slf4j.Logger; 1.17 import org.slf4j.LoggerFactory; 1.18 1.19 -import eu.earthobservatory.constants.GeoConstants; 1.20 import eu.earthobservatory.vocabulary.GeoSPARQL; 1.21 import eu.earthobservatory.vocabulary.SimpleFeatures; 1.22 1.23 /** 1.24 + * This is the implementation of the RDFS Entailment Extension for 1.25 + * GeoSPARQL. All requirements of this extension are implemented 1.26 + * except for Requirement 25 identified by the URI 1.27 + * <a>http://www.opengis.net/spec/geosparql/1.0/req/rdfs-entailment-extension/bgp-rdfs-ent</a>. 1.28 + * 1.29 + * With respect to GML class hierarchy, the GML Simple Features Profile 2.0 is only supported. 1.30 * 1.31 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 1.32 * @author Konstantina Bereta <konstantina.bereta@di.uoa.gr> 1.33 @@ -43,14 +46,15 @@ 1.34 1.35 private static final boolean ENABLE_INFERENCE = false; 1.36 1.37 - private static String TYPE = RDF.TYPE.stringValue(); 1.38 - 1.39 + /** 1.40 + * Keeps a String to URI mapping for the URIs of Simple Features and GML 1.41 + */ 1.42 private Hashtable<String, URI> uriMap; 1.43 - 1.44 + 1.45 /** 1.46 - * The number of triples that the "triples" object above contains. 1.47 + * The number of triples that we inferred 1.48 */ 1.49 - private int numTriples = 0; 1.50 + private int numInfTriples = 0; 1.51 1.52 public GeosparqlRDFHandlerBase(RepositoryConnection con) { 1.53 super(con); 1.54 @@ -62,23 +66,6 @@ 1.55 } 1.56 } 1.57 1.58 - /** 1.59 - * Inserts the given URI in the hashtable of URIs 1.60 - * and retrieves the instance of class URI. 1.61 - * 1.62 - * @param uri 1.63 - * @return 1.64 - */ 1.65 - private URI getURI(String uri) { 1.66 - URI ret = null; 1.67 - if ((ret = uriMap.get(uri)) == null) { 1.68 - ret = new URIImpl(uri); 1.69 - uriMap.put(uri, ret); 1.70 - } 1.71 - 1.72 - return ret; 1.73 - } 1.74 - 1.75 @Override 1.76 public void startRDF() throws RDFHandlerException { 1.77 if (ENABLE_INFERENCE) { 1.78 @@ -90,7 +77,7 @@ 1.79 @Override 1.80 public void endRDF() throws RDFHandlerException { 1.81 if (ENABLE_INFERENCE) { 1.82 - logger.info("[Strabon.GeoSPARQLEntailment] Inferred {} triples.", numTriples); 1.83 + logger.info("[Strabon.GeoSPARQLEntailment] Inferred {} triples.", numInfTriples); 1.84 } 1.85 } 1.86 1.87 @@ -115,7 +102,7 @@ 1.88 } 1.89 1.90 super.handleStatement(stmt); 1.91 - numTriples++; 1.92 + numInfTriples++; 1.93 } 1.94 1.95 @Override 1.96 @@ -154,7 +141,7 @@ 1.97 * or 1.98 * subj rdf:type geo:Geometry 1.99 */ 1.100 - else if(pred.equals(TYPE) && (obj.equals(GeoSPARQL.Feature) || obj.equals(GeoSPARQL.Geometry))) { 1.101 + else if(pred.equals(RDF.TYPE.stringValue()) && (obj.equals(GeoSPARQL.Feature) || obj.equals(GeoSPARQL.Geometry))) { 1.102 handleInferredStatement(st.getSubject(), RDF.TYPE, getURI(GeoSPARQL.SpatialObject), st.getContext()); 1.103 } 1.104 /* 1.105 @@ -178,7 +165,7 @@ 1.106 handleInferredStatement((Resource) st.getObject(), RDF.TYPE, getURI(GeoSPARQL.SpatialObject), st.getContext()); 1.107 } 1.108 } 1.109 - else if (pred.equals(TYPE)) { 1.110 + else if (pred.equals(RDF.TYPE.stringValue())) { 1.111 /* THE FOLLOWING CORRESPONDS TO GML AND NEEDS REWRITING TO FIT THAT OF SIMPLE FEATURES */ 1.112 // // GML class hierarchy 1.113 // if (obj.equals(GeoConstants.GML_OGC + "GM_Complex") 1.114 @@ -505,33 +492,20 @@ 1.115 handleInferredStatement(getURI(GeoSPARQL.Geometry), RDFS.SUBCLASSOF, getURI(GeoSPARQL.SpatialObject), null); 1.116 } 1.117 1.118 - public static void main(String[] args) throws Exception { 1.119 - NTriplesParser parser = new NTriplesParser(); 1.120 - parser.setVerifyData(true); 1.121 - 1.122 - /*String text = 1.123 - "<http://example.org/rcc8Obj1> <http://www.opengis.net/ont/geosparql#rcc8eq> <http://example.org/rcc8Obj2> . " + 1.124 - "<http://example.org/simpleGeometry1> <http://www.opengis.net/ont/geosparql#isEmpty> _:nai . \n"+ 1.125 - "<http://example.org/ForestArea1> <http://www.opengis.net/ont/geosparql#defaultGeometry> _:b2 . \n"+ 1.126 - "<http://example.org/SpatialObject1> <http://www.opengis.net/ont/geosparql#ehIntersects> <http://example.org/SpatialObject2> . \n"; 1.127 - */ 1.128 - 1.129 - String gmltext= "<http://example.org/GM_MultiSolid> <"+TYPE+"> <"+GeoConstants.GML_OGC+"GM_Object> .\n"; 1.130 - //String sftext= "<http://example.org/Line> <"+type+"> <"+sf+"Geometry> .\n"; 1.131 + /** 1.132 + * Inserts the given URI in the hashtable of URIs 1.133 + * and retrieves the instance of class URI. 1.134 + * 1.135 + * @param uri 1.136 + * @return 1.137 + */ 1.138 + private URI getURI(String uri) { 1.139 + URI ret = null; 1.140 + if ((ret = uriMap.get(uri)) == null) { 1.141 + ret = new URIImpl(uri); 1.142 + uriMap.put(uri, ret); 1.143 + } 1.144 1.145 - StringReader reader = new StringReader(gmltext); 1.146 - 1.147 - GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(null); 1.148 - 1.149 - handler.startRDF(); 1.150 - parser.setRDFHandler(handler); 1.151 - parser.parse(reader, ""); 1.152 - handler.endRDF(); 1.153 - 1.154 - reader.close(); 1.155 - 1.156 - System.out.println("Original triples: " + gmltext); 1.157 - //System.out.println("Geometry domain list: " + handler.getgeometryDomainList()); 1.158 - //System.out.println("New triples: " + handler.getTriples()); 1.159 + return ret; 1.160 } 1.161 }