[MarkLogic Dev General] How to include inference rules

Geert Josten Geert.Josten at marklogic.com
Sun Jul 5 11:32:31 PDT 2015


Hi Prateek,

It would help if you provide more detail. If you run this query from Qconsole, against which database are you running it then (the dropdown at the top of QConsole)? And does this database contain triple data? You can discover that using the Explore button which should reveal XML triple files, or using count(cts:triples()) in a new Qconsole query against the same database.

Note that your ruleset needs to be stored in the schemas database that is connected to the documents database that you are using..

Cheers,
Geert

From: "prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>" <prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Sunday, July 5, 2015 at 8:20 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] How to include inference rules


Hi Geert,

 I am running this script now. It runs w/o error but doesnt return ant results. I am not sure if, I am missing something here. Also, I am not sure how to pass my data in query like, I want to get all banks in uk.


let $my-store := sem:ruleset-store("/rules/bankAt.rules", sem:store() )
return
 (: use the store you just created - pass it in to sem:sparql() :)
 sem:sparql('
PREFIX ex: <http://example.com/>
PREFIX gn: <http://www.geonames.org/ontology/>

SELECT ?bank ?placeName
FROM <http://marklogic.com/semantics/sb/banks/inf-1>
WHERE
 {
 ?bank ex:bankAt ?place .
 ?place gn:name ?placeName
 }
 ORDER BY ?bank
', (), (),
 $my-store
 )

Prateek Jain

Cell : +91-9958646136

--------------------------------------------------------------
EXPECTATION : Causes all troubles......
--------------------------------------------------------------

On Sun, Jul 5, 2015 at 11:37 PM, Geert Josten <Geert.Josten at marklogic.com<mailto:Geert.Josten at marklogic.com>> wrote:
Hi Prateek,

Which error do you get?

Cheers,
Geert

From: "prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>" <prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Sunday, July 5, 2015 at 8:05 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] How to include inference rules


Thanks Geert,

 I have already created rule for inferencing by:

xquery version "1.0-ml";
xdmp:document-insert(
'/rules/bankAt.rules',
text{
'
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema/>
PREFIX ex: <http://example.com/>
PREFIX gn: <http://www.geonames.org/ontology/>

rule "bankAt" CONSTRUCT {
  ?bank ex:bankAt ?place2
} {
  ?bank ex:bankAt ?place1 .
  ?place1 gn:parentFeature ?place2
}
'
}
)

And this is running w/o error. My issue is I am trying to use it in my query like


let $my-store := sem:ruleset-store("/rules/bankAt.rules", sem:store() )
return
 (: use the store you just created - pass it in to sem:sparql() :)
 sem:sparql('
PREFIX ex: <http://example.com/>

SELECT ?bank ?placeName
FROM <http://marklogic.com/semantics/sb/banks/inf-1>
WHERE
 {
 ?bank ex:bankAt ?place .
 ?place gn:name ?placeName
 }
 ORDER BY ?bank
', (), (),
 $my-store
 )


This is giving me error. I am confused on how to use custom rule (syntatically)

Prateek Jain

Cell : +91-9958646136

--------------------------------------------------------------
EXPECTATION : Causes all troubles......
--------------------------------------------------------------

On Sun, Jul 5, 2015 at 11:24 PM, Geert Josten <Geert.Josten at marklogic.com<mailto:Geert.Josten at marklogic.com>> wrote:
Hi Prateek,

I see two options:

  1.  Specify ruleset programmatically using a sem:ruleset-store (see http://docs.marklogic.com/guide/semantics/inferencing#id_pgfId-920824)
  2.  Use default rulesets, which is a config setting for databases (see http://docs.marklogic.com/guide/semantics/inferencing#id_pgfId-919120)

Cheers,
Geert

From: "prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>" <prateekjainaa at gmail.com<mailto:prateekjainaa at gmail.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Sunday, July 5, 2015 at 7:06 PM
To: "general at developer.marklogic.com<mailto:general at developer.marklogic.com>" <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] How to include inference rules

Hi,

 I am facing issue while using custom inference rules in marklogic 8.0. Here is the scenario:

1. create data

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX place: <http://example.com/places/>
PREFIX ex: <http://example.com/>
PREFIX bank: <http://example.com/banks/>

INSERT DATA
{
  GRAPH <http://marklogic.com/semantics/sb/banks/inf-1>
  {
    bank:1001 rdf:type ex:bank ;
              ex:name "rbs" ;
 ex:service "loan" , "asset management" , "fx" ;
 place:name "london" .
    bank:1002 rdf:type ex:bank ;
              ex:name "rbi" ;
 ex:service "loan" , "retail banking" , "guide lines" ;
 place:name "delhi" .
  }
}

#------------- Define some places and their relationships-------------

DROP SILENT GRAPH <http://marklogic.com/semantics/sb/places/inf-1> ;

CREATE GRAPH <http://marklogic.com/semantics/sb/places/inf-1> ;


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX place: <http://example.com/places/>
PREFIX ex: <http://example.com/>

INSERT DATA
{
  GRAPH <http://marklogic.com/semantics/sb/places/inf-1>
  {
    place:1001 rdf:type ex:country ;
              ex:name "uk" ;
 ex:isin "Europe" .

place:1002 rdf:type ex:city ;
              ex:name "london" ;
 ex:isin "uk" .

  }
}

2. Query w/o inference

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ex: <http://example.com/>
PREFIX bank: <http://example.com/banks/>
PREFIX place: <http://example.com/places/>

SELECT ?b
FROM <http://marklogic.com/semantics/sb/banks/inf-1>
WHERE
  {
    ?b rdf:type ex:bank ;
place:name "london"
  }

3. I know how to use inference via creating ontology data:

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

INSERT DATA
{
  GRAPH <http://marklogic.com/semantics/sb/banks/inf-1>
  {
    ex:city rdfs:subClassOf ex:country .
  }
}


-------------------------
4. Now, what I am trying to do is; achieve this via creating custom rules file. I have created "bankAt.rules" file under schemas database. Here is the code:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema/>
PREFIX ex: <http://example.com/>
PREFIX gn: <http://www.geonames.org/ontology/>

rule "bankAt" CONSTRUCT {
  ?bank ex:bankAt ?place2
} {
  ?bank ex:bankAt ?place1 .
  ?place1 gn:parentFeature ?place2
}

I dont know how to use this rules file in my sparql query. I would be really helpful if someone can just list down the steps on "how to use this rule in sparql query".

Regards,

Prateek Jain

--------------------------------------------------------------
EXPECTATION : Causes all troubles......
--------------------------------------------------------------

_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general



_______________________________________________
General mailing list
General at developer.marklogic.com<mailto:General at developer.marklogic.com>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20150705/01498fb3/attachment-0001.html 


More information about the General mailing list