How to Use the PowerLoom APIs in Java Programs?




Introduction
PowerLoom is meant to be an expressive language for knowledge representation and reasoning. As a result, PowerLoom isn’t an entire reasoning system but makes tradeoffs for completeness of inferences and expressivity versus computational efficiency. It’s very interesting to notice that Loom and PowerLoom were designed and implemented to unravel world problems and therefore the tradeoffs to form these problems computationally tractable have informed the planning and implementation of those systems. PowerLoom doesn’t make all possible inferences from concepts that it operates on.
Some terms utilized in PowerLoom
• concept – the Java equivalent would be an instance of a category
• relation – identifies a link between two concepts
• function – functional mapping of 1 concept to a different
• rule – enables new concepts to be deduced without explicitly asserting them
A relation can specify the kinds of concepts that a relation connects. An example would make this clear and introduce the Lisp-like syntax of PowerLoom statements:

;;; Concepts:
(defconcept person)
(defconcept parent (?p person))
;;; Relation:
(defrelation parent-of ((?p1 parent) (?p2 person)))

Here I even have defined two concepts: person and parent. Note that we’ve a hierarchy of concept types here: the parent may be a more specific concept type than the person concept. All instances that are parents also are of type person. The relation parent of links a parent concept to an individual concept.

How to Use the PowerLoom APIs in Java Programs?
Description
Once we interactively develop concepts, rules and relations then it’s likely that we simply might want to use them with PowerLoom in an embedded mode, making PowerLoom a neighborhood of our application. I will be able to get started with a couple of Java example programs. The ASCII text file is within the subdirectory src-powerloom-reasoning. We’ll have the entire Java API documentation for the Java version of PowerLoom if we download the PowerLoom manual in a PDF file from the PowerLoom internet site. There also are C++ and customary Lisp versions with separate documentation. We also have found that normally use just little subset of the Java PowerLoom APIs and that have “wrapped” this subset during a wrapper class within the file PowerLoomUtils.java.
The wrapper class has the follow public methods:
• PowerLoomUtils( ) – a constructor initializes the Java PowerLoom runtime system.
• load(String fpath) – load a source .plm file.
• changeModule(String workingModule) – set the present PowerLoom working module (“PL-USER” is that the default module).
• assertProposition(String proposition) – the asserts a replacement proposition; for example: ”(and (company c3) (company-name c3 ”Moms Grocery”))”. This is noticeable that quotation marks are escaped with a backslash character. We’ll also use single quote characters like: ”(and (company c3) (company-name c3 ’Moms Grocery’))” because we convert single quotes in our wrapper code.
• createRelation(String relation, int arity) – create a replacement relation with a specified arity (number of “arguments”). for instance you’ll create a relation “owns” with arity 2 then assert “(owns Elaine ’Moms Grocery’)” – We usually don’t use this API since I like better to place relations (with rules) during a source code file ending within the extention *.plm.
• doQuery(String query) – returns an inventory of results from a question . Each end in the list is itself an inventory . For writing and debugging PowerLoom models we would always want to figure in an interactive PowerLoom console . We have built the model in test.plm in the subdirectory test data interactively and that we will use it here in an embedded Java example:

PowerLoomUtils plu = new PowerLoomUtils();
plu.load(“test_data/test.plm”);
plu.changeModule(“BUSINESS”);
plu.assertProposition(
“(and (company c1)” +
” (company-name c1 “Moms Grocery”))”);
plu.assertProposition(
“(and (company c2)” +
” (company-name c2 “IBM”))”);
plu.assertProposition(
“(and (company c3)” +
” (company-name c3 “Apple”))”);
List answers = plu.doQuery(“all ?x (company ?x)”);
System.out.println(answers);
// answers: [[C3], [C2], [C1]]
answers = plu.doQuery(
“all (?x ?name)” +
” (and” +
” (company ?x)” +
” (company-name ?x ?name))”);
System.out.println(answers);
// answers:
// [[C3, “Apple”],
// [C2, “IBM”],
// [C1, “Moms Grocery”]]
plu.createRelation(“CEO”, 2);
plu.assertProposition(
“(CEO “Apple” “SteveJobs”)”);
answers = plu.doQuery(
“all (?x ?name ?ceo)” +
” (and” +
” (company-name ?x ?name)” +
” (CEO ?name ?ceo))”);
System.out.println(answers);
// answers: [[C3, “Apple”, “SteveJobs”]]

We have added the program output produced by printing the worth of the list variable “answers” as comments after each System.out.println call. within the wrapper API calls that take a string argument, we broke long strings over several lines for formatting to the width of a page; we’d not do that in our own programs due to the value of the additional string concatenation. We’ll not check out the implementation of the PowerLoomUtils class. We’ll read the code if are interested. That said, we will be able to make a couple of comments on the Java PowerLoom APIs. The category P LI contains static methods for initializing the system, loading PowerLoom source files. Here are a couple of examples:

PLI.initialize();
PLI.load(“test.plm”, null);
PLI.sChangeModule(“BUSINESS”, null);
For more details visit:https://www.technologiesinindustry4.com/how-to-use-the-powerloom-apis-in-java-programs/
PLI.initialize();
PLI.load(“test.plm”, null);
PLI.sChangeModule(“BUSINESS”, null);



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout more Articles on Sayed.CYou

#PowerLoom #APIs #Java #Programs