Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

call a Sparql command in a rule, is it possible?

$
0
0
Is it possible call a Sparql command in a rule? Can we do that with a custom
built-in function?

An example:

let's consider that I have the classes Student, Course and Lesson. Lesson is
related with Course. I have an ObjectProperty wasFailedBy that defines that
a given student fails to a given lesson (I list my schema and my data
example below). I want to define an ObjectProperty isDiligent that defines
that a given student is diligent to a given course. I consider that a given
student is diligent to a given course if he didn't fails more than a given
number of lessons (let's consider 1). I can't get this information with OWL
or OWL2 inference, I only can get with a Sparql command.

I'm thinking to define my rule in this way:

(?Student ex:isDiligent ?Course) <-
(?Student rdf:type ex:Student),
(?Course rdf:type ex:Course),
execSparql('
prefix exa: <http://www.example.org/example#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT (COUNT(1) AS ?nCount)
WHERE {
?V1_Student ex:failsTo ?Lesson .
?Lesson exa:isLessonOf ?V2_Course .
}', ?Student, ?Course, ?NCount),
le(?NCount, 1).

In my idea, the custom built-in function execSparql receives as parameters a
string with a Sparql command, a list of instanced variables to be replaced
inside the function and will return the result in the last variable passed
as parameter. I didn't implemented yet because I have doubts if this is the
better approach. My main doubts is:
Can I execute a Sparql command inside a custom built-in function using de
RuleContext?
Can I use a custom built-in function only to be an external access from the
rule and call the Sparql command, for instance via Web Service, to my
inference engine? Any better ideas?

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY exa "http://www.example.org/example#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>

<rdf:RDF xmlns="http://www.example.org/example#"
xml:base="http://www.example.org/example#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:exa="http://www.example.org/example#">

<!--

////////////////////////////////////////////////////////////////////////////
///////////
//
// Object Properties
//

////////////////////////////////////////////////////////////////////////////
///////////

<owl:ObjectProperty rdf:about="笖;isLessonOf">
<rdfs:label>wasFailedBy</rdfs:label>
<rdfs:domain rdf:resource="笖;Lesson"/>
<rdfs:range rdf:resource="笖;Course"/>
</owl:ObjectProperty>

<owl:ObjectProperty rdf:about="笖;wasFailedBy">
<rdfs:label>wasFailedBy</rdfs:label>
<rdfs:domain rdf:resource="笖;Lesson"/>
<rdfs:range rdf:resource="笖;Student"/>
</owl:ObjectProperty>

<owl:ObjectProperty rdf:about="笖;failsTo">
<rdfs:label>failsTo</rdfs:label>
<owl:inverseOf rdf:resource="笖;wasFailedBy"/>
</owl:ObjectProperty>

<!--

////////////////////////////////////////////////////////////////////////////
///////////
//
// Classes
//

////////////////////////////////////////////////////////////////////////////
///////////

<owl:Class rdf:about="笖;Student">
<rdfs:label>Student</rdfs:label>
</owl:Class>

<owl:Class rdf:about="笖;Course">
<rdfs:label>Course</rdfs:label>
</owl:Class>

<owl:Class rdf:about="笖;Lesson">
<rdfs:label>Lesson</rdfs:label>
</owl:Class>

<!--

////////////////////////////////////////////////////////////////////////////
///////////
//
// Individuals
//

////////////////////////////////////////////////////////////////////////////
///////////

<owl:Thing rdf:about="笖;Databases">
<rdfs:label>Databases</rdfs:label>
<rdf:type rdf:resource="笖;Course"/>
</owl:Thing>

<owl:Thing rdf:about="笖;ComputerProgramming">
<rdfs:label>Computer Programming</rdfs:label>
<rdf:type rdf:resource="笖;Course"/>
</owl:Thing>

<owl:Thing rdf:about="笖;Michael">
<rdfs:label>Michael</rdfs:label>
<rdf:type rdf:resource="笖;Student"/>
</owl:Thing>

<owl:Thing rdf:about="笖;Richard">
<rdfs:label>Richard</rdfs:label>
<rdf:type rdf:resource="笖;Student"/>
</owl:Thing>

<owl:Thing rdf:about="笖;LessonDB1">
<rdf:type rdf:resource="笖;Lesson"/>
<isLessonOf rdf:resource="笖;Databases"/>
<wasFailedBy rdf:resource="笖;Michael"/>
</owl:Thing>

<owl:Thing rdf:about="笖;LessonDB2">
<rdf:type rdf:resource="笖;Lesson"/>
<isLessonOf rdf:resource="笖;Databases"/>
<wasFailedBy rdf:resource="笖;Michael"/>
<wasFailedBy rdf:resource="笖;Richard"/>
</owl:Thing>

<owl:Thing rdf:about="笖;LessonCP1">
<rdf:type rdf:resource="笖;Lesson"/>
<isLessonOf rdf:resource="笖;ComputerProgramming"/>
<wasFailedBy rdf:resource="笖;Richard"/>
</owl:Thing>

<owl:Thing rdf:about="笖;LessonCP2">
<rdf:type rdf:resource="笖;Lesson"/>
<isLessonOf rdf:resource="笖;ComputerProgramming"/>
<wasFailedBy rdf:resource="笖;Michael"/>
<wasFailedBy rdf:resource="笖;Richard"/>
</owl:Thing>

</rdf:RDF>

Viewing all articles
Browse latest Browse all 5648

Latest Images

Trending Articles



Latest Images