Strabon
changeset 119:a932ab72a29f
geosparql inferencing
author | Konstantina Mpereta <grad1110@di.uoa.gr> |
---|---|
date | Wed Apr 04 19:37:19 2012 +0300 (2012-04-04) |
parents | e1a54ea341b2 |
children | b2667f7bc051 |
files | generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java |
line diff
1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Wed Apr 04 16:12:08 2012 +0300 1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/LiteralManager.java Wed Apr 04 19:37:19 2012 +0300 1.3 @@ -97,6 +97,7 @@ 1.4 /**********************************************/ 1.5 try { 1.6 if (XMLGSDatatypeUtil.isNumericDatatype(datatype)) { 1.7 + System.out.println("about to insert double value:"+literal.doubleValue()); 1.8 table.insertNumeric(id, label, dt, literal.doubleValue()); 1.9 } 1.10 else if (XMLGSDatatypeUtil.isCalendarDatatype(datatype)) { 1.11 @@ -104,6 +105,7 @@ 1.12 table.insertDateTime(id, label, dt, value); 1.13 } 1.14 else { 1.15 + //System.out.println("NOT NUMERIC:::"+label+" "+literal); 1.16 table.insertDatatype(id, label, dt); 1.17 1.18 /**
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Wed Apr 04 16:12:08 2012 +0300 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Wed Apr 04 19:37:19 2012 +0300 2.3 @@ -218,6 +218,7 @@ 2.4 { 2.5 labels.insert(id, label); 2.6 datatypes.insert(id, datatype); 2.7 + System.out.println("about to insert double value:"+value); 2.8 numeric.insert(id, value); 2.9 } 2.10
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/GeosparqlRDFHandlerBase.java Wed Apr 04 19:37:19 2012 +0300 3.3 @@ -0,0 +1,140 @@ 3.4 +package eu.earthobservatory.runtime.generaldb; 3.5 + 3.6 +import java.io.StringReader; 3.7 +import java.util.List; 3.8 +import java.util.Arrays; 3.9 + 3.10 +import org.openrdf.model.Statement; 3.11 +import org.openrdf.rio.helpers.RDFHandlerBase; 3.12 +import org.openrdf.rio.ntriples.NTriplesParser; 3.13 + 3.14 +public class GeosparqlRDFHandlerBase extends RDFHandlerBase { 3.15 + 3.16 + public static String geonamespace = "http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/"; 3.17 + public static String type = "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; 3.18 + public static String SpatialObject= geonamespace + "SpatialObject"; 3.19 + public static String Feature = geonamespace + "Feature"; 3.20 + public static String Geometry= geonamespace + "Geometry"; 3.21 + public static String hasGeometry = geonamespace + "hasGeometry"; 3.22 + public static String defaultGeometry = geonamespace + "defaultGeometry"; 3.23 + public static String dimension= geonamespace + "dimension"; 3.24 + public static String coordinateDimension= geonamespace + "coordinateDimension"; 3.25 + public static String spatialdimension= geonamespace + "spatialdimension"; 3.26 + public static String isEmpty= geonamespace + "isEmpty"; 3.27 + public static String isSimple= geonamespace + "isSimple"; 3.28 + public static String is3D= geonamespace + "is3D"; 3.29 + public static List <String> geometryDomainList = Arrays.asList(dimension, coordinateDimension, spatialdimension,isEmpty, isSimple, is3D); 3.30 + public static String WKTLiteral= geonamespace + "WKTLiteral"; 3.31 + public static String GMLLiteral= geonamespace + "GMLLiteral"; 3.32 + public static String asWKT= geonamespace + "asWKT"; 3.33 + public static List <String> rcc8 = Arrays.asList(geonamespace+"rcc8-eq",geonamespace+"rcc8-dc",geonamespace+"rcc8-ec",geonamespace+"rcc8-po", 3.34 + geonamespace+"rcc8-tppi", geonamespace+"rcc8-tpp",geonamespace+ "rcc8-ntpp", geonamespace+"rcc8-ntpp"); 3.35 + 3.36 + //loose check: tha elegxw an arxizei apo eh- i apo sf- i apo rcc8- (den einai ola tou rcc8) 3.37 + 3.38 + private StringBuffer triples = new StringBuffer(1024); 3.39 + 3.40 + public StringBuffer getTriples() 3.41 + { 3.42 + return triples; 3.43 + }; 3.44 + 3.45 + public List <String> getrcc8() 3.46 + { 3.47 + return rcc8; 3.48 + } 3.49 + 3.50 + public List <String> getgeometryDomainList() 3.51 + { 3.52 + return geometryDomainList; 3.53 + } 3.54 + 3.55 + public void startRDF() { triples.append("\n");}; 3.56 + 3.57 + public void endRDF() {}; 3.58 + 3.59 + 3.60 + public void handleStatement(Statement st) 3.61 + { 3.62 + String subject = st.getSubject().toString(); 3.63 + String predicate = st.getPredicate().toString(); 3.64 + String object = st.getObject().toString(); 3.65 + 3.66 + if(predicate.startsWith("http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/sf-")||predicate.startsWith(geonamespace+"eh-")|| 3.67 + rcc8.contains(predicate)) 3.68 + { 3.69 + String triple = "<"+subject+ "> "+ type +"> <"+ SpatialObject+ "> .\n" + 3.70 + "<"+object+ "> "+ type +"> <"+ SpatialObject+ "> .\n" ; 3.71 + triples.append(triple); 3.72 + } 3.73 + if(subject.equals(Feature) || subject.equals(Geometry) ) 3.74 + { 3.75 + String triple = "<"+subject+ "> "+ type +"> <"+ SpatialObject+ "> .\n"; 3.76 + triples.append(triple); 3.77 + } 3.78 + if(predicate.equals(hasGeometry)) 3.79 + { 3.80 + String triple = "<"+subject+ "> "+ type +"> <"+ Feature+ "> .\n" + 3.81 + "<"+object+ "> "+ type +"> <"+ Geometry+ "> .\n" + 3.82 + "<"+ subject+ "> "+ type +"> <"+ SpatialObject + "> .\n" + 3.83 + "<"+ object+ "> "+ type +"> <"+ SpatialObject + "> .\n"; 3.84 + triples.append(triple); 3.85 + } 3.86 + if(predicate.equals(defaultGeometry)) 3.87 + { 3.88 + String triple = "<"+subject+ "> "+ type +"> <"+ Feature+ "> .\n" + 3.89 + "<"+object+ "> "+ type +"> <"+ Geometry+ "> .\n" + 3.90 + "<"+ subject+ "> "+ type +"> <"+ SpatialObject + "> .\n"+ 3.91 + "<"+ subject+ "> <"+ hasGeometry +"> <"+ object + "> .\n"; 3.92 + triples.append(triple); 3.93 + } 3.94 + if(geometryDomainList.contains(predicate)) 3.95 + { 3.96 + String triple = "<"+subject+ "> <"+ type +"> <"+ Geometry+ "> .\n" + 3.97 + "<"+subject+ "> "+ type +"> <"+ SpatialObject+ "> .\n"; 3.98 + triples.append(triple); 3.99 + } 3.100 + //triples.append("niania\n"); 3.101 + 3.102 + } 3.103 + 3.104 + 3.105 + public static void main(String[] args) throws Exception { 3.106 + NTriplesParser parser = new NTriplesParser(); 3.107 + parser.setVerifyData(true); 3.108 + 3.109 + String text = 3.110 + "<http://example.org/rcc8Obj1> <http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/rcc8-eq> <http://example.org/rcc8Obj2> . " + 3.111 + "<http://example.org/simpleGeometry1> <http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/isEmpty> _:nai . \n"+ 3.112 + "<http://example.org/ForestArea1> <http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/defaultGeometry> _:b2 . \n"+ 3.113 + "<http://example.org/SpatialObject1> <http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/eh-intersects> <http://example.org/SpatialObject2> . \n"; 3.114 + 3.115 + StringReader reader = new StringReader(text); 3.116 + 3.117 + GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(); 3.118 + 3.119 + handler.startRDF(); 3.120 + parser.setRDFHandler(handler); 3.121 + parser.parse(reader, ""); 3.122 + handler.endRDF(); 3.123 + 3.124 + reader.close(); 3.125 + 3.126 + System.out.println("Original triples: " + text); 3.127 + //System.out.println("Geometry domain list: " + handler.getgeometryDomainList()); 3.128 + System.out.println("New triples: " + handler.getTriples()); 3.129 + } 3.130 + 3.131 + 3.132 + 3.133 + 3.134 + 3.135 + 3.136 + 3.137 + 3.138 + 3.139 + 3.140 + 3.141 + 3.142 + 3.143 +}
4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed Apr 04 16:12:08 2012 +0300 4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed Apr 04 19:37:19 2012 +0300 4.3 @@ -2,12 +2,17 @@ 4.4 4.5 import java.io.DataOutputStream; 4.6 import java.io.File; 4.7 +import java.io.FileInputStream; 4.8 import java.io.FileNotFoundException; 4.9 import java.io.FileOutputStream; 4.10 import java.io.IOException; 4.11 +import java.io.InputStream; 4.12 import java.io.OutputStream; 4.13 import java.io.OutputStreamWriter; 4.14 import java.io.StringReader; 4.15 + 4.16 +import java.io.FileReader; 4.17 +import java.io.*; 4.18 import java.net.URL; 4.19 import java.nio.charset.Charset; 4.20 import java.sql.SQLException; 4.21 @@ -42,6 +47,9 @@ 4.22 import org.openrdf.rio.RDFHandler; 4.23 import org.openrdf.rio.RDFHandlerException; 4.24 import org.openrdf.rio.RDFParseException; 4.25 +import org.openrdf.rio.RDFParser; 4.26 +import org.openrdf.rio.Rio; 4.27 +import org.openrdf.rio.ntriples.NTriplesParser; 4.28 import org.openrdf.rio.ntriples.NTriplesWriter; 4.29 import org.openrdf.sail.helpers.SailBase; 4.30 4.31 @@ -713,7 +721,7 @@ 4.32 //return ret; 4.33 return retStream.toString(); 4.34 } 4.35 - 4.36 + 4.37 public void update(String updateString, SailRepositoryConnection con) throws MalformedQueryException 4.38 4.39 { 4.40 @@ -744,12 +752,13 @@ 4.41 con1.add(file, baseURI, format); 4.42 } 4.43 4.44 - public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault 4.45 + public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException 4.46 { 4.47 + System.out.println("generaldb.Strabon.store in repo"); 4.48 storeInRepo(src, null, null, format); 4.49 } 4.50 4.51 - public void storeInRepo(Object src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault 4.52 + public void storeInRepo(Object src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException 4.53 { 4.54 RDFFormat realFormat = null; 4.55 4.56 @@ -808,13 +817,22 @@ 4.57 } 4.58 } 4.59 4.60 - private void storeFile(File file, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 4.61 + private void storeFile(File file, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.62 { 4.63 System.out.println("File : " + file.getName()); 4.64 System.out.println("Base URI : " + ((baseURI == null) ? "null" : baseURI)); 4.65 System.out.println("Context : " + ((context == null) ? "null" : context)); 4.66 System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 4.67 4.68 + RDFParser parser = Rio.createParser(format); 4.69 + GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(); 4.70 + FileReader reader = new FileReader(file); 4.71 + handler.startRDF(); 4.72 + parser.setRDFHandler(handler); 4.73 + parser.parse(reader, ""); 4.74 + System.out.println("These are the extra triples:"+ handler.getTriples().toString()); 4.75 + StringReader georeader= new StringReader(handler.getTriples().toString()); 4.76 + handler.endRDF(); 4.77 if (context == null) { 4.78 System.out.println("[1]"); 4.79 con1.add(file, baseURI, format); 4.80 @@ -822,15 +840,28 @@ 4.81 System.out.println("[2]"); 4.82 con1.add(file, baseURI, format, context); 4.83 } 4.84 + con1.add(georeader, "", RDFFormat.NTRIPLES); 4.85 + 4.86 } 4.87 4.88 - private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 4.89 + private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.90 { 4.91 System.out.println("URL : " + url.toString()); 4.92 System.out.println("Base URI : " + ((baseURI == null) ? "null" : baseURI)); 4.93 System.out.println("Context : " + ((context == null) ? "null" : context)); 4.94 System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 4.95 4.96 + InputStream in = (InputStream) url.openStream(); 4.97 + InputStreamReader reader = new InputStreamReader(in); 4.98 + RDFParser parser = Rio.createParser(format); 4.99 + GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(); 4.100 + handler.startRDF(); 4.101 + parser.setRDFHandler(handler); 4.102 + parser.parse(reader, ""); 4.103 + System.out.println("These are the extra triples:"+ handler.getTriples().toString()); 4.104 + StringReader georeader= new StringReader(handler.getTriples().toString()); 4.105 + handler.endRDF(); 4.106 + 4.107 if (context == null) { 4.108 System.out.println("[3]"); 4.109 con1.add(url, baseURI, format); 4.110 @@ -838,9 +869,10 @@ 4.111 System.out.println("[4]"); 4.112 con1.add(url, baseURI, format, context); 4.113 } 4.114 + con1.add(georeader, "", RDFFormat.NTRIPLES); 4.115 } 4.116 - 4.117 - private void storeString(String text, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException 4.118 + 4.119 + private void storeString(String text, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.120 { 4.121 if (baseURI == null) 4.122 baseURI = ""; 4.123 @@ -851,6 +883,16 @@ 4.124 System.out.println("Format : " + ((format == null) ? "null" : format.toString())); 4.125 4.126 StringReader reader = new StringReader(text); 4.127 + RDFParser parser = Rio.createParser(format); 4.128 + GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(); 4.129 + 4.130 + handler.startRDF(); 4.131 + parser.setRDFHandler(handler); 4.132 + parser.parse(reader, ""); 4.133 + System.out.println("These are the extra triples:"+ handler.getTriples().toString()); 4.134 + StringReader georeader= new StringReader(handler.getTriples().toString()); 4.135 + handler.endRDF(); 4.136 + 4.137 if (context == null) { 4.138 System.out.println("[5]"); 4.139 con1.add(reader, baseURI, format); 4.140 @@ -858,6 +900,7 @@ 4.141 System.out.println("[6]"); 4.142 con1.add(reader, baseURI, format, context); 4.143 } 4.144 + con1.add(georeader, "", RDFFormat.NTRIPLES); 4.145 } 4.146 4.147 public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException
5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java Wed Apr 04 16:12:08 2012 +0300 5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/StoreOp.java Wed Apr 04 19:37:19 2012 +0300 5.3 @@ -38,6 +38,7 @@ 5.4 Strabon strabon = new Strabon(db, user, passwd, port, host, true); 5.5 5.6 File file = new File (src); 5.7 + System.out.println("about to store the file in the repo!"); 5.8 strabon.storeInRepo(file, format); 5.9 // strabon.storeInRepo(file, null, null, fileRDFFormat); 5.10