4 Replies Latest reply on Sep 5, 2008 1:22 PM by JorgeB-Oracle

    A SparQL question

    609674
      Hi,

      I have a question need anyone to help.
      for example, there is a class student(hasName,hasDesc)
      now, in my data table, these are two instances of student.

      <uri://www.test.org:studentId:1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <uri://www.test.org#Student>
      <uri://www.test.org:studentId:1> <uri://www.test.org#hasName> "John"
      <uri://www.test.org:studentId:1> <uri://www.test.org#hasDesc> "John is a good student"
      <uri://www.test.org:studentId:2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <uri://www.test.org#Student>
      <uri://www.test.org:studentId:2> <uri://www.test.org#hasName> "Tom"

      please note, the student 2 has not the hasDesc data. Now, I ran the following statement, the result didn't include the student 2, it is not the result that I expected. I want to get the student 2 at the same time, and desc should be a null value. any good ideas for this? I don't want to join two tables.Oracle should have a way for this,I think. anyone can help me?

      select student ,desc
      from TABLE(SEM_MATCH('(?student rdf:type :Student) (?student :hasDesc ?desc)',
      SEM_Models('test'),
      null,
      SEM_Aliases(SEM_Alias('', 'uri://www.test.org#')),
      null))
        • 1. Re: A SparQL question
          Mannamal-Oracle
          Hi,

          What you are looking for is support for the OPTIONAL construct in SPARQL. Support for this is in the plan and expected very soon.

          Meanwhile a workaround is to do an outer join. For example:

          select t2.student, t1.desc
          from TABLE(SEM_MATCH('(?student rdf:type :Student) (?student :hasDesc ?desc)',
          SEM_Models('test'),
          null,
          SEM_Aliases(SEM_Alias('', 'uri://www.test.org#')),
          null)) t1
          RIGHT OUTER JOIN
          ABLE(SEM_MATCH('(?student rdf:type :Student)',
          SEM_Models('test'),
          null,
          SEM_Aliases(SEM_Alias('', 'uri://www.test.org#')),
          null)) t2 on t1.x = t2.x;

          We will post on this forum as soon as support for OPTIONAL becomes available.

          Melli
          • 2. Re: A SparQL question
            603214
            So it would be included in new release or in new patch?
            • 3. Re: A SparQL question
              Mannamal-Oracle
              Yes. It will not be in the upcoming Oracle database patch but in a future one (soon).

              Melli
              • 4. Re: A SparQL question
                JorgeB-Oracle
                Adding to the previously posted workaround we can also insert another triple with a null value. This alternative has to modify the data, see example in note:

                Note 602217.1 Sem_match Returns Nothing If Attribute Selected Not Populated (OPTIONAL support)

                In that note I have added the OUTER JOIN workaround as well in the example.

                In case you do not have access to the note, taking your example it basically does this insert:


                INSERT INTO demo_rdf_data VALUES (1001,
                SDO_RDF_TRIPLE_S ('demo_model', '<uri://www.test.org:studentId:2>',
                '<uri://www.test.org#hasDesc>',
                '""^^<http://www.w3.org/2001/XMLSchema#string>'));
                commit;

                Then you can use the same query to extract both rows:

                select student ,desc
                from TABLE(SEM_MATCH('(?student rdf:type :Student) (?student :hasDesc ?desc)',
                SEM_Models('test'),
                null,
                SEM_Aliases(SEM_Alias('', 'uri://www.test.org#')),
                null))

                Regards!
                Jorge