5 Replies Latest reply on Aug 27, 2012 10:08 AM by alwu-Oracle

    get data using SEM_MATCH


      I try to get index from family example using SEM_MATCH. For example I do
      INSERT INTO family_rdf_data VALUES (3,

      And now I want do somethink like this

      SELECT a.id, ?x, ?y FROM TABLE(SEM_MATCH(
      *'(?x :grandParentOf ?y) (?x rdf:type :Male)',*

      to get: id, subject, object
        • 1. Re: get data using SEM_MATCH

          To do this, you need to join SEM_MATCH results with your application table's triple column in order to retrieve the ID column from the application table.

          But let me take a step back and ask you this question. Why do you need to do this?


          Zhe Wu
          • 2. Re: get data using SEM_MATCH
            It is my curiosity. Could you give some example of this join?
            • 3. Re: get data using SEM_MATCH

              You can use something like this

              select app_tab.id ...
              from (TABLE(SEM_MATCH(
              '(?x :grandParentOf ?y) (?x rdf:type :Male)', SEM_Models('family'),null,SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),null))
              ) g, family_rdf_data app_tab
              where g.x$RDFVID=app_tab.triple.rdf_s_id
              and g.y$RDFVID=app_tab.triple.rdf_c_id

              If you need to add a constraint on the property, you can add another expression to the above SQL as follows.

              and app_tab.triple.rdf_p_id=oracle_orardf_res2vid('http://www.example.org/family/grandParentOf')

              Note that the oracle_orardf_res2vid function is a helper function (automatically created when you
              use Jena Adapter).

              Hope it helps,

              Zhe Wu
              • 4. Re: get data using SEM_MATCH
                Thanks for answear. I' ve got two questions. First: I do

                select app_tab.id
                from (TABLE(SEM_MATCH(
                *'(:John :fatherOf ?y)', SEM_Models('family'),null,SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),null))*
                *) g, family app_tab*
                --g.x$RDFVID=app_tab.triple.rdf_s_id and*
                and I get id = 1,2,3,4 but it should return id=1,2

                and Second: What is rdf_s_id or rdf_c_id ??
                • 5. Re: get data using SEM_MATCH

                  It really depends on what rows you have in your application table.
                  Note that if you insert the same triple multiple times into your application table,
                  you are likely to get "duplicates" when querying the graph together with your application table.

                  In contrast, when querying using SEM_MATCH, the underlying RDFM_<modelName> view
                  maintains a set of triples.

                  As far as your query goes, basically it finds the ID of the RDF resource (which is father of John),
                  you then join it with the application table, locating rows that have the same object ID.

                  Obviously, the object ID itself is not sufficient to uniquely identify a triple.
                  You may want to add predicates using oracle_orardf_res2vid for both :John
                  and :fatherOf.

                  Note that
                  rdf_s_id is the ID for triple subject and
                  rdf_p_id is the ID for triple predicate.

                  Hope it helps,