Can you please show me an example to use negation in user defined rule? I created a rule like below (the rule says if a patient has a fever problem and not have penicillin hypersensitivity, then recommend medication1):
INSERT INTO mdsys.semr_myMedicineRB VALUES('rule1',
'(?p rdf:type :Patient) (?p :present ?c1) (?c1 rdf:type :Fever) (?c2 rdf:type :Penicillin_Hypersensitivity)',
'(NOT_EXISTS(p :present c2))',
'(?p :recommendation :medication1)',
The rule successfully inserted into the rulebase. However, I cannot pass the entailment creation phase and got the errors:
ORA-29532: Java call terminated by uncaught Java exception: java.sql.SQLException: Missing IN or OUT parameter at index:: 1
ORA-06512: at "MDSYS.SDO_SEM_INF_INTERNAL", line 16453
ORA-06512: at "MDSYS.SDO_SEM_INFERENCE", line 302
ORA-06512: at "MDSYS.SDO_SEM_INFERENCE", line 352
ORA-06512: at "MDSYS.RDF_APIS", line 118
ORA-06512: at line 2
29532. 00000 - "Java call terminated by uncaught Java exception: %s"
*Cause: A Java exception or error was signaled and could not be
resolved by the Java code.
*Action: Modify Java code, if this behavior is not intended.
According to the post built-in primitives(noValue,remove) for user defined rules, it seems negation is not supported in user defined rules. Can you please advice how to implement negation in user defined rules? Thanks a lot in advance.
Negation is not supported in the user defined rules. If you need a work around, please follow the suggestion in the post you referenced.
If you are using Oracle Database Release 12c, then user defined inferencing can certainly handle negation.
Hope it helps,
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,