12 Replies Latest reply on Sep 12, 2014 5:30 PM by joguerra

    GeoSPARQL query

    joguerra

      Hi,

      I've just to start to make queries in the database using the GeoSPARQL vocabulary and I am wondering whether there is something missing/wrong in this query:

       

      PREFIX dc:<http://purl.org/dc/elements/1.1/>

      PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

      PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

      PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>

      PREFIX owl:   <http://www.w3.org/2002/07/owl#>

      PREFIX fn:<http://www.w3.org/2005/xpath-functions#>

      PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>

      PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>

      PREFIX astro: <http://www.tng.iac.es/ontologies/2014/6/starguidecatalog#>

      PREFIX geo:   <http://www.opengis.net/ont/geosparql#>

      PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

       

      PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#timeout=100,qid=123>

       

      SELECT ?name ?fWKT

      WHERE { ?name astro:hasAstronomicalPoint ?point .

      ?point geo:asWKT ?fWKT .

      FILTER (geof:sfWithin(?fWKT, "Polygon (0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1)"^^geo:wktLiteral))

      }

      LIMIT 10

       

      The query is based on the ontology described on this thread (Oracle semantic tech inference + Protege plugin). Basically, it's a simple thing. I just want to pull out the names within a box defined by the Polygon. Can anybody point out whether it is correct? I got an internal error from Joseki server (HTTP Status 500 - Unknown error)

       

      Thanks & Cheers

        • 1. Re: GeoSPARQL query
          Matperry-Oracle

          Hi,

           

          Have you created a spatial index for the network?

           

          An index is required for GeoSPARQL query support. You can create one as follows (for the default WGS84 Long Lat spatial reference system):

          EXECUTE sem_apis.add_datatype_index('http://www.opengis.net/ont/geosparql#wktLiteral', options=>'TOLERANCE=1 SRID=8307 DIMENSIONS=((LONGITUDE,-180,180) (LATITUDE,-90,90))');

           

          Thanks,

          Matt

          • 2. Re: GeoSPARQL query
            joguerra

            Hi,

             

            Thank you for your reply.

             

            Unfortunately it doesn't work. I recreated the index again, I got not luck though. Same error "HTTP Status 500 - Unknown error".

            The thing is that with any other query works. I mean, it seems the error is due to spatial stuff. Also is that It doesn't squawk any other error on the tomcat logs either.

             

            I have no clues at all

            Cheers

            • 3. Re: GeoSPARQL query
              Matperry-Oracle

              Please try a sem_match version of this query on the database directly. That will help rule out any server configuration errors.

               

              select name

              from table(sem_match(

              'PREFIX dc:    <http://purl.org/dc/elements/1.1/>

                PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

                PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

                PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>

                PREFIX owl:   <http://www.w3.org/2002/07/owl#>

                PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>

                PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>

                PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>

                PREFIX astro: <http://www.tng.iac.es/ontologies/2014/6/starguidecatalog#>

                PREFIX geo:   <http://www.opengis.net/ont/geosparql#>

                PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

                SELECT ?name ?fWKT

                WHERE {

                  ?name astro:hasAstronomicalPoint ?point .

                  ?point geo:asWKT ?fWKT .

                  FILTER (geof:sfWithin(?fWKT, "Polygon (0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1)"^^geo:wktLiteral))

                }

                LIMIT 10'

              ,sem_models('your_model_here')

              ,null,null,null,null

              ,' '));

               

              Thanks,
              Matt

              • 4. Re: GeoSPARQL query
                Matperry-Oracle

                By the way, I just noticed that you need an extra set of parenthesis in your WKT string. It should be "Polygon ((0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1))"

                • 5. Re: Re: GeoSPARQL query
                  joguerra

                  Thank you Mat,

                   

                  I ran the query from sqlplus and it seems a problem with the spatial/geosparql functions:

                   

                  select name
                  from table(sem_match(
                  'PREFIX dc:    <http://purl.org/dc/elements/1.1/>
                   PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                   PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
                   PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
                   PREFIX owl:   <http://www.w3.org/2002/07/owl#>
                   PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>
                   PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
                   PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>
                   PREFIX astro: <http://www.tng.iac.es/ontologies/2014/8/starguidecatalog#>
                   PREFIX geo:   <http://www.opengis.net/ont/geosparql#>
                   PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
                  SELECT ?name ?fWKT
                    WHERE {
                      ?name astro:hasAstronomicalPoint ?point .
                      ?point geo:asWKT ?fWKT .
                      FILTER (geof:sfWithin(?fWKT, "Polygon ((0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1))"^^geo:wktLiteral))
                    }
                    LIMIT 10'
                  ,sem_models('TEST')
                  ,null,null,null,null
                  ,' '));
                  
                  

                   

                  select name
                  *
                  ERROR at line 1:
                  ORA-29532: Java call terminated by uncaught Java exception:
                  oracle.spatial.rdf.server.RDFException: Unsupported Function:
                  http://www.opengis.net/def/function/geosparql/sfWithin
                  ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 184
                  ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 1157
                  ORA-06512: at "MDSYS.RDF_MATCH_IMPL_T", line 387
                  ORA-06512: at line 1
                  
                  

                   

                   

                  Is there anything else to run in order to have support for them?

                   

                  Cheers

                  • 6. Re: Re: GeoSPARQL query
                    Matperry-Oracle

                    Thanks for trying the SEM_MATCH query. What version of Oracle are you using? Please post the results of the following query as SYSDBA.

                     

                    SELECT * FROM MDSYS.RDF_PARAMETER;

                     

                    Thanks,
                    Matt

                    • 7. Re: Re: GeoSPARQL query
                      joguerra

                      Hi Mat,

                       

                      SQL> SELECT * FROM MDSYS.RDF_PARAMETER;

                       

                      NAMESPACE               ATTRIBUTE              VALUE                                   DESCRIPTION

                      ------------------------------ ------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------

                      COMPONENT               RDFCTX                  INSTALLED                                Semantic (Text) Search component

                      COMPONENT               RDFOLS                  INSTALLED                                RDF Optional component for OLS support

                      COMPONENT               RDFVPD                  INSTALLED                                RDF Optional component for VPD support

                      MDSYS                   SEM_VERSION              11203                                   VALID

                       

                      SQL>

                       

                      Thank you for your replies

                      • 8. Re: Re: GeoSPARQL query
                        Matperry-Oracle

                        Hi,

                         

                        The problem is that you are using version 11.2.0.3.0 of RDF Semantic Graph. This version predates the GeoSPARQL spec, so GeoSPARQL syntax is not supported. However, an Oracle-specific syntax that is functionally equivalent to GeoSPARQL is supported in version 11.2 and later.

                         

                        The main differences are that (1) you need to use orageo:WKTLiteral instead of ogc:wktLiteral as the datatype of your geometry literals and (2) you need to use different query functions. The content of the literal is exactly the same for orageo:WKTLiteral and ogc:wktLiteral, so you only need to change the type tag of the geometry literals in your dataset.

                         

                        "Polygon ((0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1))"^^<http://xmlns.oracle.com/rdf/geo/WKTLiteral>

                         

                        The spatial functions in 11.2 are documented here: http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sdo_rdf_concepts.htm#RDFRM194

                         

                        Your query would change to:

                         

                        select name

                        from table(sem_match(

                        'PREFIX dc:    <http://purl.org/dc/elements/1.1/>

                          PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

                          PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

                          PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>

                          PREFIX owl:   <http://www.w3.org/2002/07/owl#>

                          PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>

                          PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>

                          PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>

                          PREFIX astro: <http://www.tng.iac.es/ontologies/2014/6/starguidecatalog#>

                          PREFIX geo:   <http://www.opengis.net/ont/geosparql#>

                          PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

                          SELECT ?name ?fWKT

                          WHERE {

                            ?name astro:hasAstronomicalPoint ?point .

                            ?point geo:asWKT ?fWKT .

                            FILTER (orageo:relate(?fWKT, "Polygon ((0.0 0.0, 10.0 0.0, 10.0 0.1, 0.0 0.1))"^^orageo:WKTLiteral, "mask=coveredby+inside"))

                          }

                          LIMIT 10'

                        ,sem_models('TEST')

                        ,null,null,null,null

                        ,' '));

                         

                        You should also re-create the spatial index after changing your data.

                         

                        EXECUTE sem_apis.drop_datatype_index('http://xmlns.oracle.com/rdf/geo/WKTLiteral');

                        EXECUTE sem_apis.add_datatype_index('http://xmlns.oracle.com/rdf/geo/WKTLiteral', options=>'TOLERANCE=1 SRID=8307 DIMENSIONS=((LONGITUDE,-180,180) (LATITUDE,-90,90))');

                         

                        Thanks,
                        Matt

                        • 9. Re: GeoSPARQL query
                          joguerra

                          Thank you very much indeed Matt.

                           

                          We are harnessing tests on 11g database but the final production database will be a RAC 12c, I know it sounds a bit woolly but we didn't realize about this, we may have to step back to rebuild the test environment. I've just logged in into the database (12c) and I ran the query you told me before and the semantic version is 12.1.0.2. So the question is immediately, is the GeoSPARQL spec supported here or we have to stick with the Oracle Geo specs?

                           

                          SQL> SELECT * FROM MDSYS.RDF_PARAMETER;

                           

                          NAMESPACE               ATTRIBUTE              VALUE                                                                               DESCRIPTION

                          ------------------------------ ------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------

                          COMPONENT               RDFCTX                  INSTALLED                                                                            Semantic (Text) Search component

                          COMPONENT               RDFOLS                  INSTALLED                                                                            RDF Optional component for OLS support

                          COMPONENT               RDFVPD                  INSTALLED                                                                            RDF Optional component for VPD support

                          MDSYS                   SEM_VERSION              12.1.0.2.0                                                                           VALID

                           

                          SQL>

                           

                          Cheers

                          • 10. Re: GeoSPARQL query
                            joguerra

                            I was checking the 12c docs and it seems the ogc literals are supported (ogc:wktLiteral) but I am not sure about the ogc functions!. We might have to stick with the Oracle ones.

                            http://docs.oracle.com/database/121/RDFRM/sdo_rdf_concepts.htm#RDFRM187

                             

                            Another question is related to the URL to orageo ontology. Where can I get a link to it?

                            Cheers

                            • 11. Re: GeoSPARQL query
                              Matperry-Oracle

                              Hi,

                               

                              The OGC query should work in 12.1.0.2.0. Both OGC and Oracle-specific functions are supported in 12c. The Oracle-specific functions provide some additional capabilities beyond GeoSPARQL. For example, there is no nearestNeighbor function in GeoSPARQL.

                               

                              There is not really an orageo ontology. It's just a namespace used for the spatial query functions. The list of all supported functions in 12c is below.

                               

                              Cheers,

                              Matt

                               

                              GeoSPARQL functions:

                              Oracle-specific functions:

                              • 12. Re: GeoSPARQL query
                                joguerra

                                Hi Matt,

                                 

                                Thank you for your clues!!. On Oracle 12c, the query worked as expected.

                                1 person found this helpful