Skip to content

Querying DFL with a DL reasoner

mpomarlan edited this page Feb 21, 2022 · 6 revisions

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.Theme"))

# 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.Theme"))

print("    ", dl.doesObjectHaveDisposition("dfl:aircraft.n.wn.artifact", "dfl:cut.v.wn.contact.Instrument"))
print("    ", dl.whatHasDisposition("dfl:cut.v.wn.contact.Instrument"))
print("    ", dl.whatDispositionsDoesObjectHave("dfl:knife.n.wn.artifact"))
print("    ", dl.whatDispositionsDoesObjectHave("dfl:apple.n.wn.food"))

The inputs/outputs of the above mentioned functions are described below.

buildCache

Input: none
Output: none; needs about 30 seconds, builds an internal cache of inference results

doesObjectHaveDisposition

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)

whatDispositionsDoesObjectHave

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

whatHasDisposition

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

whatSubclasses

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

whatSuperclasses

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

Clone this wiki locally