7 Replies Latest reply: Aug 15, 2012 11:34 PM by alwu-Oracle RSS

    sparql query using variable paths

    366556
      Hi,

      I have a following graph in Oracle that I like to query using Jena 2.6.4 and OracleJenaAdaptor 11.2.0.3

      ind:123 :hasA ind:124
      ind:124 :hasB ind:125
      ind:125 :hasC ind:126
      ind:123 :hasD ind:127

      Is there a way to construct a sparql query to return all ind: without "hard-conding" the full property name? Something in these lines (note, this query doesn't really work).

      select *
      where { ind:123 (:has*)+ ?x }

      Thanks.
        • 1. Re: sparql query using variable paths
          alwu-Oracle
          Hi,

          Can you use something like this?

          select *
          where { ind:123  (:hasA|:hasB|:hasC|:hasD)+ ?x }

          If you really don't know all those property names/URIs before hand, then
          you can define a super property :hasRelation of all those :has* properties, run
          inference, and execute the following query

          select *
          where { ind:123  (:hasRelation)+ ?x }

          Here I assume you defined:
          :hasA rdfs:subPropertyOf :hasRelation .
          :hasB rdfs:subPropertyOf :hasRelation .
          ...

          Hope it helps,

          Zhe Wu
          • 2. Re: sparql query using variable paths
            366556
            I've made hasRelation a superproperty of my other properties and used OWLPRIME inferencing with the following settings: SNOMED,INTERSECTSCOH,INTERSECT,CHAIN

            However, running this query didn't return any results

            select *
            where { ind:123 (:hasRelation)+ ?x }



            If I try the following query I'm only getting the immediate results links to ind:123 (i.e. ind:124, ind:127) but not indirect links

            select *
            where { ind:123 :hasRelation ?x }


            Am I missing any other settings?
            • 3. Re: sparql query using variable paths
              alwu-Oracle
              Please cut & paste your TBox (the sub property definitions) and the code snippet you used to run SPARQL queries against the asserted model as well as the inferred graph.

              Thanks,

              Zhe
              • 4. Re: sparql query using variable paths
                366556
                :hasA rdf:type owl:ObjectProperty ;

                rdfs:subPropertyOf :hasRelation .
                :hasB rdf:type owl:ObjectProperty ;

                rdfs:subPropertyOf :hasRelation .
                :hasC rdf:type owl:ObjectProperty ;

                rdfs:subPropertyOf :hasRelation .
                :hasD rdf:type owl:ObjectProperty ;

                rdfs:subPropertyOf :hasRelation .


                String q1 = "SELECT ?x, ?y
                where {?x (:hasRelation)+ ?y} ";

                Stirng q2 = "SELECT ?x, ?y
                where {?x :hasRelation ?y} ";

                Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);
                               
                Attachment attachment = Attachment.createInstance(new String[]{"my_asset","my_model"},
                new String[]{"OWLPRIME"}, InferenceMaintenanceMode.UPDATE_WHEN_COMMIT, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP);

                GraphOracleSem graph = new GraphOracleSem(oracle, "vm_model", attachment);

                ModelOracleSem inferencedModel = new ModelOracleSem(graph);
                          
                Query query = QueryFactory.create(q1);

                Edited by: a1239090 on Aug 15, 2012 4:54 PM
                • 5. Re: sparql query using variable paths
                  alwu-Oracle
                  Hi,

                  Did you have a graph.performInference() somewhere in your code?

                  Thanks,

                  Zhe
                  • 6. Re: sparql query using variable paths
                    366556
                    I've created a virtual model before that.
                    • 7. Re: sparql query using variable paths
                      alwu-Oracle
                      Hi,

                      If you have created a virtual model before, then the following will do. Note that I am assuming that the virtual model is created based on two models "my_asset","my_model" and the rulebase OWLPRIME.

                      Attachment attachment = Attachment.createInstance(new String[]{"my_model"},
                      new String[]{"OWLPRIME"}, InferenceMaintenanceMode.UPDATE_WHEN_COMMIT, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP);

                      GraphOracleSem graph = new GraphOracleSem(oracle, "my_asset", attachment, true);
                      graph.performInference();

                      Thanks,

                      Zhe