Thank you very much for the helpful reply. I can simulate the negation in sparql construct query; but, I don't have a clue to write negation in user defined inferencing function in oracle 12c. Can you please give me a simple example to demonstrate negation in user defined inferencing? Thanks a lot in advance.
Let's look at this similar but simplified problem:
if (?p rdf:type :Patient) and (NOT_EXISTS(?p :present :c2)) ==> (?p :recommendation :medication1)
You can use something like this in the user defined inferencing:
-- First get the numeric IDs for the relevant URIs
recomID := sdo_sem_inference.oracle_orardf_add_res('http://..../recommendation');
medID := sdo_sem_inference.oracle_orardf_add_res('http://..../medication1')
rdfTypeID := sdo_sem_inference.oracle_orardf_res2vid('... full URI for rdf:type');
patientID := ...
presentID := ...
c2ID := ...
-- Now this query will find out ?p that satisfy (?p rdf:type :Patient) but not
-- (?p :present :c2)
sqlStmt := '
select ids1.sid sub
from ' || src_tab_view || ' ids1
where ids1.pid= ' || to_char(rdfTypeID,'TM9') || '
and not exists (
from ' || src_tab_view || '
where sid = ids1.sid
and pid = ' || to_char(presentID, 'TM9') || '
and oid = '|| to_char(c2ID,'TM9') || '
insertStmt := '
insert /*+ parallel append */
into ' || output_tab || '(sid, pid, oid)
select sub, '||to_char(recomID,'TM9') || ',' || to_char(medID,'TM9') || '
from (' || sqlStmt || ')'
More details can be found in
Hope it helps,
This example gives me a very good guide to write the user defined negation inference. But, my case would be a little bit different because the predicate 'recommendation' is not defined in the ontology. It is rather defined in the user defined rules. In this case, is it still possible to insert the triple (?p :recommendation medication1) into the model using this function? Thank you very much for help.
Yes. Note that I used sdo_sem_inference.oracle_orardf_add_res for URIs :recommendation and medication1. They will be added to MDSYS.RDF_VALUE$ if absent.
BTW, negation in general is tricky. What do you plan to do if (p :present c2) is inferred through some other rules after (p :recommendation :medication1) has been generated.
Sorry for the late reply. W.r.t the conflict rules, my rulebases are based on a medical document and don't contain such rules so far and I'll try to avoid rules which are potentially conflict. If a conflict is inferred, one of the reasons might be the medical document on which the ontology is based may not be consistent. BTW, does oracle have a mechanism to deal with conflict rules? Thank you very much for clarifying the issues confused me.
Out of performance considerations, the native inference engine in Oracle does not check conflict in the process of forward chaining. You can, however, issue a SPARQL ASK query to see if the following conjunctive patterns hold. To have an early detection, you can run inference on a per round basis.
(?p rdf:type :patient)
(?p :present ?c1)
(?c1 rdf:type :Fever)
(?c2 rdf:type :penicillin_Hypersensitivity)
(?p :present ?c2)
(?p :recommendation :medication1)
Hope it helps,