prac comes with an easy-to-use API, which lets you use the modules provided by prac of which each solves an own inference task conveniently in your own applications.
A PRACModule is represented by an instance of the class
prac.core.base.PRACModule
. Each module provides a predicates.mln file
containing the predicate declarations for the MLN of the respective module and
a pracmodule.yaml file specifying module properties such as its name and a
description, as well as dependencies to other PRACModules, the names of the
module’s class and a file (usually predicates.mln) containing the predicate
declarations for the related MLN. It also specifies which project file
contains the default project to be loaded for this module. This file will be
processed during initialization of the PRAC reasoning system.
The PRAC reasoning system is represented by an instance of the class
prac.core.base.PRAC
. This class encapsulates information about
the modules of the PRAC pipeline and the ontology used for the inference.
It also provides a method run
to execute a module of the PRAC
pipeline.
An instance of the class prac.core.inference.PRACInference
represents
an inference chain in PRAC which is initialized with a reference to an
instance of the PRAC reasoning system (prac.core.base.PRAC
) and a
list of natural-language sentences subject to inference.
The method next_module
returns the name of the next module to be
executed according to the predefined PRAC pipeline. An instance of this
module can then be created and executed:
>>> modulename = inference.next_module()
>>> module = prac.module(modulename)
>>> prac.run(inference, module)
PRACInference.
next_module
()¶A PRACInferenceStep instance encapsulates a single inference step in the
PRAC pipeline. It consists of n input databases and m output databases.
Initialize an instance of the class prac.core.inference.PRACInference
with a reference to the PRACInference object, a reference to the PRACModule
performing this inference step and list of databases taken as inputs.
The class prac.core.wordnet.WordNet
is a wrapper class for
Wordnet, which may be initialized with
some WordNet concepts spanning an initial, collapsed concept taxonomy.
The methods synsets
and synset
allow creating WordNet synsets
from strings and perform a number of preprocessing steps to generate temporary
WordnetConcepts for numbers that are not contained in the WordNet ontology.
The method similarity
will calculate the WUP- or path-similarity
provided by WordNet after preprocessing the synsets. In particular, if at least
one of the synsets is an adjective, this preprocessing includes looking up
the synset in predefined similarity tables for colors, shapes and sizes and
numbers not contained in the original ontology. Otherwise the derivationally
related noun form of the adjective is retrieved from WordNet and used for the
similarity calculation.
WordNet.
synsets
(*args, **kw)¶WordNet.
synset
(*args, **kw)¶WordNet.
similarity
(*args, **kw)¶Once a PRAC- and a PRACInference instance have been initialized, we can run the PRAC pipeline.
>>> prac = PRAC()
>>> inference = PRACInference(prac, sentences)
>>> while inference.next_module() != None and not is_inference_process_aborted:
>>> modulename = inference.next_module()
>>> module = prac.module(modulename)
>>> prac.run(inference, module)
>>> prac = PRAC()
>>> inference = PRACInference(prac, sentences)
>>> while inference.next_module() != None and not is_inference_process_aborted:
>>> modulename = inference.next_module()
>>> module = prac.module(modulename)
>>> prac.run(inference, module)
>>> prac = PRAC()
>>> inference = PRACInference(prac, sentences)
>>> while inference.next_module() != None and not is_inference_process_aborted:
>>> modulename = inference.next_module()
>>> module = prac.module(modulename)
>>> prac.run(inference, module)
prac.core.base.
PRAC
(configfile=’pracconf’)¶The PRAC reasoning system.
construct_global_mln
()¶Reads all predicte declaration MLNs of all modules and returns an MLN with all predicates declared.
module
(modulename)¶Returns a loaded and initialized module given by the module name.
modules
()¶Returns a generator iterating over all module manifests.
query
(instr, stopat=None)¶Performs a query on PRAC using the natural-language instruction(s) instr
.
Parameters: |
|
---|
tell
(howto, steps)¶This method tells PRAC how complex high-level tasks are being achieved by executing multiple instruction steps.
This method triggers a (partial) PRAC inference pipeline and stores the result in the PRAC MongoDB.
Parameters: |
|
---|
training_dbs
(actioncore_name=None)¶Returns the list of training database file names associated to the given action core. Returns all training databases if actioncore_name is None.
prac.core.base.
PRACModule
(prac)¶Base class for all PRAC reasoning modules. Provides some basic functionality for serializing, deserializing and running PRAC modules. Every PRAC module must subclass this.
from_manifest
(manifest, prac)¶Loads a Module from a given manifest. :param manifest: a PRACModuleManifest instance :param prac: a PRAC instance :return: an instance of PRACModule
initialize
()¶Called after the PRAC module has been loaded. Every PRAC module can do some initialization stuff in here. The default implementation does nothing.
mlnquery
(config=None, verbose=None, **params)¶Wrapper for MLNQuery to replace the resultdb of the inference object with an MLN Database casted to a PRACDatabase
Parameters: |
|
---|---|
Returns: | the inference object |
shutdown
()¶Called when the PRAC reasoning system is to be shut down. Here modules can do some cleaning up. The default does nothing.
prac.core.wordnet.
WordNet
(*args, **kw)¶Wrapper class for WordNet, which may be initialized with some WordNet concepts spanning an initial, collapsed concept taxonomy.
Also provides a set of customized similarity measures for colors, shapes and sizes as introduced in Mareike’s thesis.
nltkpos
(penntreepos)¶Converts a Penn Treebank part-of-speech tag into an NLTK POS tag.
prac.core.inference.
PRACInference
(prac, instr)¶Represents an inference chain in PRAC
prac.core.inference.
PRACInferenceStep
(node, module)¶Wrapper class encapsulating a single inference step in the PRAC pipeline. It consists of n input databases and m output databases.