Inferencing in embedded triples of Marklogic

142 views Asked by At

I have the following 2 documents. 1 document has this data:

<Content>
  <sem:triples xmlns:sem="http://marklogic.com/semantics">
    <sem:triple>
      <sem:subject>http://sector#Basic_Materials</sem:subject>
      <sem:predicate>http://relationship#isTRBCEconomicSectorOf</sem:predicate>
      <sem:object>http://company#CST_Mining_Group_Limited</sem:object>
    </sem:triple>
  </sem:triples>
  <AnalystName>Henrik Christiansson</AnalystName>
  <DocumentFormat>pdf</DocumentFormat>
</Content>

And another document that has the following data:

<Content>
  <sem:triples xmlns:sem="http://marklogic.com/semantics">
    <sem:triple>
      <sem:triple>
        <sem:subject>http://sector#Energy_-_Fossil_Fuels</sem:subject>
        <sem:predicate>http://relationship#isTRBCEconomicSectorOf</sem:predicate>
        <sem:object>http://company#Bodycote_PLC</sem:object>
      </sem:triple>
    </sem:triple>
  </sem:triples>
  <AnalystName>Pawel Dziedzic</AnalystName>
  <DocumentFormat>pdf</DocumentFormat>
</Content>

I have made a relationship between these two embedded triples as

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

INSERT DATA
{

  <http://company#CST_Mining_Group_Limited> rdfs:subClassOf <http://company#Bodycote_PLC> .

}

When I query to get all the results that are economicSector of Bodycote Plc, I get both of the triples, which is correct, but when I use a combined query it does not give me the required results.

For example, when the query has an economic sector of BodyCote and also the Analyst Name is Henrik Christiansson, I want it to return the first triple but it does not.

I used the following query:

xquery version "1.0-ml";

import module namespace sem = "http://marklogic.com/semantics" 
  at "/MarkLogic/semantics.xqy";

sem:sparql(
  'SELECT ?subject
   WHERE {
     ?subject <http://relationship#isTRBCEconomicSectorOf> <http://company#Bodycote_PLC>
   }',
  (),
  (),
  cts:and-query( (
    cts:element-value-query( xs:QName("AnalystName"), "Henrik Christiansson" )
  ) )
)

I wanted to know if there is a way through which i can apply inferencing in combined queries also.

1

There are 1 answers

0
grtjn On

The problem with your approach is that the cts:query only selects the relevant documents, not the managed triple that specifies the subclass. You are not using real Inferencing here, but are actually externalizing inference rules by literally adding triples. Use rulesets instead, that is more flexible, and will work better as well. See Semantics guide for details.

Once you have your ruleset file in place, you need to wrap the query in sem:store, and then apply the ruleset with a sem:ruleset-store:

sem:sparql(
  '
    SELECT ?subject
    WHERE {
      ?subject <http://relationship#isTRBCEconomicSectorOf <http://company#Bodycote_PLC>
    }
  ',
  (),
  (),
  sem:ruleset-store(
    "myrules",
    sem:store(
      (),
      cts:and-query((
       cts:element-value-query( xs:QName("AnalystName"), "Henrik Christiansson" )
      ))
    )
  )
)

HTH!