Class ExternalAPI
java.lang.Object
fr.inria.rules.integraal.api.external.ExternalAPI
- Direct Known Subclasses:
MyAwfulTests, MyAwfulTests2
Defines external access to the internal API services.
The purpose is to enable the use of the internal API services offered
by InteGraal without directly manipulating InteGraal objects. All elements
manipulated by InteGraal will be designated here by names (String).
The proposed functionalities enable the management of fact bases,
rule bases, and queries, performing saturation, rewriting rules, querying
a knowledge base, extracting rules, unfolding rules, transforming rules, and
executing queries with different options.
- Author:
- Jean-François Baget, Carole Beaugeois, Pierre Bisquert, Michel Leclère, Federico Ulliana
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringDefault environment created at class initialization time. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for subclasses and compatibility helpers. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddFactBase(String env, String fbCollection, String fb) Adds a fact base to a fact base collection.static StringAdds a query to a query collection.static StringAdds a rule to a rule base.static StringaddToFactBase(String envKey, String fbName, String dlgpe) Adds data to a fact base.static StringaddToFactBase(String envKey, String fbName, String dlgpe, String jsSubst, boolean freeze) Adds data to a fact base with substitution and freezing options.static StringcompiledRewrite(String env, String query, String compilation) Rewrites a query using a precomputed compilation.static StringcopyFactBase(String envKey, String fbName) Copies a fact base.static StringcopyFactBaseCollection(String env, String name) Copies a fact base collection.static StringCopies a query.static StringcopyQueryCollection(String env, String name) Copies a query collection.static StringCopies a rule.static StringcopyRuleBase(String env, String name) Copies a rule base.static StringCreates a fact base, a rule base, and a query collection from a single input.static StringCreates a fact base, a rule base, and a query collection from a file.static StringDeprecated.static StringcreateAnalyser(String env, String rbn) Creates an analyser for a rule base.static StringcreateCompilation(String env, String rbn, String compilationType) Creates a compilation for a rule base.static StringcreateEnvironment(String envKey) Creates a new environment, storing both the registries required to access InteGraal objects stored by their name, and the IntegraalEnvironment required to load and write those objects.static StringcreateFactBase(String envKey, String fbName, String dlgpe) Creates a new FactBase.static StringcreateFactBaseCollection(String envKey, String fbcName, String dlgpe) Creates a fact base collection.static StringcreateFactBaseFromMerge(String envKey, String fbName, String dlgpe) Creates a new FactBase.static StringcreateFactBaseOld(String env, String name, String dlgp) Deprecated.static StringcreateQuery(String env, String name, String dlgp) Creates a query.static StringcreateQueryCollection(String env, String name, String dlgp) Creates a query collection.static StringcreateQueryCollectionOld(String env, String name, String dlgp) Deprecated.static StringcreateQueryOld(String env, String name, String dlgp) Deprecated.static StringcreateRule(String env, String name, String dlgp) Creates a rule.static StringcreateRuleBase(String env, String name, String dlgp) Creates a rule base.static StringcreateRuleBaseOld(String env, String name, String dlgp) Deprecated.static StringcreateRuleOld(String env, String name, String dlgp) Deprecated.static StringdefaultChase(String env, String fbn, String rbn, String params) Executes the default chase.static voiddeleteEnvironment(String envKey) Deletes an environment.static StringdeleteFactBase(String envKey, String name) Deletes a fact base.static StringdeleteFactBaseCollection(String env, String name) Deletes a fact base collection.static StringdeleteQuery(String env, String name) Deletes a query.static StringdeleteQueryCollection(String env, String name) Deletes a query collection.static StringdeleteRule(String env, String name) Deletes a rule.static StringdeleteRuleBase(String env, String name) Deletes a rule base.static StringEvaluates a query against a fact base.static StringEvaluates a query against a fact base with a preprocessing object.static StringexistFactBase(String envKey, String name) Checks whether a fact base exists.static StringexistFactBaseCollection(String envKey, String name) Checks whether a fact base collection exists.static StringexistInFactBaseCollection(String envKey, String fbName, String fbCollectionName) Checks whether a fact base belongs to a fact base collection.static StringexistInQueryCollection(String envKey, String queryName, String queryCollectionName) Checks whether a query belongs to a query collection.static StringexistInRuleBase(String envKey, String ruleName, String ruleBaseName) Checks whether a rule belongs to a rule base.static StringexistQuery(String envKey, String name) Checks whether a query exists.static StringexistQueryCollection(String envKey, String name) Checks whether a query collection exists.static StringChecks whether a rule exists.static StringexistRuleBase(String envKey, String name) Checks whether a rule base exists.Lists all available environments.static StringLists all fact base collections in an environment.static StringexploreAllFactBases(String envKey) Lists all fact bases in an environment.static StringexploreAllQueries(String env) Lists all queries in an environment.static StringLists all query collections in an environment.static StringLists all rule bases in an environment.static StringexploreAllRules(String env) Lists all rules in an environment.static StringexploreFactBaseCollection(String env, String name) Explores a fact base collection.static StringexploreQueryCollection(String env, String name) Explores a query collection.static StringexploreQueryCollectionOld(String env, String name) Deprecated.static StringexploreRuleBase(String env, String name) Explores a rule base.static StringexportFactBase(String envKey, String fbName) Exports a fact base.static StringexportFactBaseCollection(String env, String name) Exports a fact base collection.static StringexportFactBaseOld(String env, String name) Deprecated.static StringexportQuery(String env, String name) Exports a query.static StringexportQueryCollection(String env, String name) Exports a query collection.static StringexportQueryCollectionOld(String env, String name) Deprecated.static StringexportQueryOld(String env, String name) Deprecated.static StringexportRule(String env, String name) Exports a rule.static StringexportRuleBase(String env, String name) Exports a rule base.static StringexportRuleBaseOld(String env, String name) Deprecated.static StringexportRuleOld(String env, String name) Deprecated.static StringextendQueryOld(String env, String base, String other) Deprecated.static StringisEmptyFactBase(String envKey, String name) Checks whether a fact base is empty.static StringisEmptyFactBaseCollection(String envKey, String name) Checks whether a fact base collection is empty.static StringisEmptyQueryCollection(String envKey, String name) Checks whether a query collection is empty.static StringisEmptyRuleBase(String envKey, String name) Checks whether a rule base is empty.static StringmergeFactBaseCollection(String env, String base, String other) Merges two fact base collections.static StringmergeQueryCollection(String env, String base, String other) Merges two query collections.static StringmergeRuleBase(String env, String base, String other) Merges two rule bases.static StringnextAnswer(String env, String an, String params) Retrieves the next answer from an answer iterator.static StringremoveFactBase(String env, String fbcollection, String fb) Removes a fact base from a fact base collection.static StringremoveFromFactBase(String env, String name, String dlgpe, String jsSubst) Removes data from a fact base.static StringremoveQuery(String env, String qcollection, String query) Removes a query from a query collection.static StringremoveRuleBase(String env, String rulebase, String rule) Removes a rule from a rule base.static StringRewrites a query with a rule base.static StringRewrites a query with a rule base and a compilation type.
-
Field Details
-
DEFAULT_ENV
Default environment created at class initialization time.
-
-
Constructor Details
-
ExternalAPI
protected ExternalAPI()Protected constructor for subclasses and compatibility helpers.
-
-
Method Details
-
createEnvironment
Creates a new environment, storing both the registries required to access InteGraal objects stored by their name, and the IntegraalEnvironment required to load and write those objects. In two distinct environments, a predicate with same name can have different arities, and two distinct rules can have the same name. Note that nothing can be done by the external API without an existing environment. A universal, static DEFAULT_ENV is provided.- Parameters:
envKey- the name given to the environment, used to retrieve all objects created and manipulated in this environment. If the given envKey is the empty String, a new one will be generated. If the given envKey already points to an existing environment, an error will be indicated in the EUA string.- Returns:
- an EUA string (the string representation of a JSON object). In case of success (result field = 1),
the EUA string will be such as
{"result":1,"data":{"envname":"E1"},"message":""}, where data.envname property indicates the name finally associated with the created environment. While in case of failure, the EUA string will be similar to{"result":-2,"data":{},"message":"Duplicate key for distinct objects E1"}
-
deleteEnvironment
Deletes an environment.- Parameters:
envKey- the environment name.
-
exploreAllEnvironments
-
createFactBase
Creates a new FactBase.- Parameters:
envKey- the key to the environment in which the FactBase is created.fbName- the name that will be given to the created FactBase. Note that this name may conflict with the dlgpe naming of the FactBase (generating an error). A safe way is to use the empty string as fbName to let an automatic generation of the fbname which is then read from DLGPE file or obtain from a safe name generation.dlgpe- the dlgpe string representing the FactBase. Note that there must be a single FactBase, whose atoms are separated by commas, and ending with a period. Its name can be indicated in the string, such as in[F] p(a, b), p(b, X)..- Returns:
- an EUA string (the string representation of a JSON object). In case of success (result field = 1),
the EUA string will be such as
{"result":1,"data":{"fbname":"FB:1772562638165_2"},"message":""}, while in case of failure, the EUA string will be similar to{"result":-4,"data":{},"message":"Unwanted item p(c)"}
-
createFactBaseFromMerge
Creates a new FactBase.- Parameters:
envKey- the key to the environment in which the FactBase is created.fbName- the name that will be given to the created FactBase. Here the dlgpe string can encode many FactBases (each FactBase ending with a period) whose dlgpe naming will be lost.dlgpe- the dlgpe string representing 0 or more FactBases. Atoms in each FactBase are separated by commas, and FactBases are ending with a period. Note that variable names are local to each FactBase, and are thus renamed when merging in a single FactBase to avoid conflicts.- Returns:
- an EUA string (the string representation of a JSON object). In case of success (result field = 1),
the EUA string will be such as
{"result":1,"data":{"fbname":"FB:1772562638165_2"},"message":""}, while in case of failure, the EUA string will be similar to{"result":-4,"data":{},"message":"Unwanted item ?(X) :- q(X)"}
-
exportFactBase
-
copyFactBase
-
deleteFactBase
-
exploreAllFactBases
-
existFactBase
-
isEmptyFactBase
-
addToFactBase
-
addToFactBase
public static String addToFactBase(String envKey, String fbName, String dlgpe, String jsSubst, boolean freeze) Adds data to a fact base with substitution and freezing options.- Parameters:
envKey- the environment name.fbName- the fact base name.dlgpe- the DLGPE content to add.jsSubst- the substitution encoded as JSON.freeze- whether to freeze the added data.- Returns:
- an EUA string describing the merge result.
-
removeFromFactBase
Removes data from a fact base.- Parameters:
env- the environment name.name- the fact base name.dlgpe- the DLGPE content to remove.jsSubst- the substitution encoded as JSON.- Returns:
- an EUA string describing the removal result.
-
createFactBaseCollection
-
exportFactBaseCollection
-
deleteFactBaseCollection
-
exploreAllFactBaseCollections
-
existFactBaseCollection
-
isEmptyFactBaseCollection
-
exploreFactBaseCollection
-
existInFactBaseCollection
public static String existInFactBaseCollection(String envKey, String fbName, String fbCollectionName) Checks whether a fact base belongs to a fact base collection.- Parameters:
envKey- the environment name.fbName- the fact base name.fbCollectionName- the collection name.- Returns:
- an EUA string describing whether the fact base belongs to the collection.
-
addFactBase
-
removeFactBase
-
mergeFactBaseCollection
-
copyFactBaseCollection
-
createRule
-
exploreAllRules
-
existRule
-
exportRule
-
copyRule
-
deleteRule
-
createRuleBase
-
exportRuleBase
-
exploreAllRuleBases
-
existRuleBase
-
isEmptyRuleBase
-
exploreRuleBase
-
existInRuleBase
Checks whether a rule belongs to a rule base.- Parameters:
envKey- the environment name.ruleName- the rule name.ruleBaseName- the rule base name.- Returns:
- an EUA string describing whether the rule belongs to the rule base.
-
deleteRuleBase
-
addRule
-
removeRuleBase
-
mergeRuleBase
-
copyRuleBase
-
createQuery
-
exploreAllQueries
-
exportQuery
-
existQuery
-
copyQuery
-
deleteQuery
-
createQueryCollection
-
exportQueryCollection
-
exploreAllQueryCollections
-
existQueryCollection
-
isEmptyQueryCollection
-
exploreQueryCollection
-
existInQueryCollection
public static String existInQueryCollection(String envKey, String queryName, String queryCollectionName) Checks whether a query belongs to a query collection.- Parameters:
envKey- the environment name.queryName- the query name.queryCollectionName- the collection name.- Returns:
- an EUA string describing whether the query belongs to the collection.
-
deleteQueryCollection
-
copyQueryCollection
-
addQuery
-
removeQuery
-
mergeQueryCollection
-
createAll
public static String createAll(String env, String fbname, String rbname, String qcname, String dlgp) Creates a fact base, a rule base, and a query collection from a single input.- Parameters:
env- the environment name.fbname- the fact base name.rbname- the rule base name.qcname- the query collection name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created objects.
-
createAllFromFile
public static String createAllFromFile(String env, String fbname, String rbname, String qcname, String dlgp) Creates a fact base, a rule base, and a query collection from a file.- Parameters:
env- the environment name.fbname- the fact base name.rbname- the rule base name.qcname- the query collection name.dlgp- the input file path or content identifier.- Returns:
- an EUA string describing the created objects.
-
evaluate
Evaluates a query against a fact base.- Parameters:
env- the environment name.fbn- the fact base name.qn- the query name.an- the answer iterator name.params- the reasoning parameters.- Returns:
- an EUA string describing the evaluation result.
-
evaluate
public static String evaluate(String env, String fbn, String qn, String pre, String an, String params) Evaluates a query against a fact base with a preprocessing object.- Parameters:
env- the environment name.fbn- the fact base name.qn- the query name.pre- the preprocessing or compilation name.an- the answer iterator name.params- the reasoning parameters.- Returns:
- an EUA string describing the evaluation result.
-
nextAnswer
-
defaultChase
-
createCompilation
-
compiledRewrite
Rewrites a query using a precomputed compilation.- Parameters:
env- the environment name.query- the query name or query content.compilation- the compilation name.- Returns:
- an EUA string describing the rewriting result.
-
rewrite
-
rewrite
Rewrites a query with a rule base and a compilation type.- Parameters:
env- the environment name.query- the query name or query content.rbn- the rule base name.compilationType- the compilation type.- Returns:
- an EUA string describing the rewriting result.
-
createAnalyser
-
createFactBaseOld
Deprecated.Creates a fact base using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the fact base name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created fact base.
-
exportFactBaseOld
Deprecated.Exports a fact base using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the fact base name.- Returns:
- an EUA string describing the exported fact base.
-
createRuleBaseOld
Deprecated.Creates a rule base using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the rule base name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created rule base.
-
exportRuleBaseOld
Deprecated.Exports a rule base using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the rule base name.- Returns:
- an EUA string describing the exported rule base.
-
createQueryCollectionOld
Deprecated.Creates a query collection using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the collection name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created collection.
-
exportQueryCollectionOld
Deprecated.Exports a query collection using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the collection name.- Returns:
- an EUA string describing the exported collection.
-
exploreQueryCollectionOld
Deprecated.Explores a query collection using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the collection name.- Returns:
- an EUA string describing the collection content.
-
createQueryOld
Deprecated.Creates a query using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the query name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created query.
-
exportQueryOld
Deprecated.Exports a query using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the query name.- Returns:
- an EUA string describing the exported query.
-
extendQueryOld
Deprecated.Merges queries using the deprecated DLGP-based API.- Parameters:
env- the environment name.base- the target query name.other- the source query name.- Returns:
- an EUA string describing the merge result.
-
createRuleOld
Deprecated.Creates a rule using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the rule name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created rule.
-
exportRuleOld
Deprecated.Exports a rule using the deprecated DLGP-based API.- Parameters:
env- the environment name.name- the rule name.- Returns:
- an EUA string describing the exported rule.
-
createAllOld
@Deprecated public static String createAllOld(String env, String fbname, String rbname, String qcname, String dlgp) Deprecated.Creates all main objects using the deprecated DLGP-based API.- Parameters:
env- the environment name.fbname- the fact base name.rbname- the rule base name.qcname- the query collection name.dlgp- the DLGP content.- Returns:
- an EUA string describing the created objects.
-