-
Notifications
You must be signed in to change notification settings - Fork 0
Querying DFL with a DL reasoner
You must first follow the procedure in Prepare DFL for use in order to be able to reason with DFL.
Assuming you have already done so, open a terminal and go to the src folder of your clone of this repository. Open a python instance and run this code:
import dfl.dlquery as dl
dl.buildCache()
The buildCache function will store all queries related to the presence of a "disposition" in an object. It should take 20 to 30 seconds to complete, but it is worth it as it makes most of the other queries blazingly fast.
A disposition is understood here as a quality allowing an object to participate in some event or task in a particular role. The convention is that the disposition's name is a combination of the event/task name and the role name. So for example, cut.v.wn.contact.Instrument is the disposition of an object that allows it to be a cutting instrument, whereas cut.v.wn.contact.Patient is the disposition of an object that allows it to be cuttable.
You can now try out various queries, for example:
# query for superclasses of a concept
print(" ", dl.whatSuperclasses("dfl:aircraft.n.wn.artifact"))
# query for subclasses of a concept
print(" ", dl.whatSubclasses("dfl:aircraft.n.wn.artifact"))
# query for the dispositions that an object has; loosely speaking, "what can you do with it?"
print(" ", dl.whatDispositionsDoesObjectHave("dfl:aircraft.n.wn.artifact"))
# query for which objects provably have a given disposition; loosely speaking, "what can do a particular task?"
print(" ", dl.whatHasDisposition("dfl:fly.v.wn.motion..assisted.Instrument"))
# query whether a particular object has a particular disposition
# NOTE: this query is slow because inference for absence of dispositions is not cached yet
print(" ", dl.doesObjectHaveDisposition("dfl:aircraft.n.wn.artifact", "dfl:fly.v.wn.motion..assisted.Instrument"))
print(" ", dl.doesObjectHaveDisposition("dfl:aircraft.n.wn.artifact", "dfl:cut.v.wn.contact..separate.Instrument"))
print(" ", dl.whatHasDisposition("dfl:cut.v.wn.contact..separate.Instrument"))
print(" ", dl.whatDispositionsDoesObjectHave("dfl:knife.n.wn.artifact..tool"))
print(" ", dl.whatDispositionsDoesObjectHave("dfl:apple.n.wn.food"))
# query what tools can be used to perform a particular task on a particular object
print(" ", dl.whatToolsCanPerformTaskOnObject('dfl:cut.v.wn.contact..separate', 'dfl:apple.n.wn.food'))
# query what objects can a particular task be performed on while using a particular tool
print(" ", dl.whatObjectsCanToolPerformTaskOn('dfl:cut.v.wn.contact..separate', 'dfl:table_knife.n.wn.artifact'))
The inputs/outputs of the above mentioned functions are described below.
Input: none
Output: none; needs about 30 seconds, builds an internal cache of inference results
Input: name of an object concept from dfl; the name must include either the "dfl:" prefix or be specified as a full IRI
Output: True (object provably has disposition) / False (object provably does not have disposition) / None (cannot prove either way)
Input: name of an object concept from dfl; the name must include either the "dfl:" prefix or be specified as a full IRI
Output: set of names of dispositions that the object provably has
Input: name of a disposition concept from dfl; the name must include either the "dfl:" prefix or be specified as a full IRI
Output: set of names of objects that provably have the disposition
Input: name of a task concept, name of an object concept that is the instrument of the task; names must include either the "dfl:", "soma:", "dul:" prefixes or be specified as full IRIs
Output: set of names of concepts for objects that can be patients of the given task, when performed with the given instrument
Input: name of a concept; the name must include a prefix from among "dfl:", "dul:", "owl:", "soma:" or be specified as a full IRI
Output: set of names of subconcepts
Input: name of a concept; the name must include a prefix from among "dfl:", "dul:", "owl:", "soma:" or be specified as a full IRI
Output: set of names of superconcepts
Input: name of a task concept, name of an object concept that is the patient of the task; names must include either the "dfl:", "soma:", "dul:" prefixes or be specified as full IRIs
Output: set of names of concepts for objects that can act as instruments in the given task, performed on the given patient