We have worked with XML being asserted as Jess using this basic technique.
Build a collection of Java bean objects, one per XML element. The XML
structure needs to be explicitly in the Java object. That is in your
example, there would be something like:
public TechnicalRequirements{
/* Attributes */
// No Attributes here.
/* Elements */
Area myArea;
/*
* Bean getters and setters...
*/
}
public Area {
/* Attributes */
int MaxTemp;
int MinTemp;
boolean Aggressive;
boolean Humid;
boolean Vibrating;
boolean Explosive;
/* Elements */
Supervision mySuper;
/*
* Bean getters and setters...
*/
}
In the rules use the OBJECT field to follow the structure, like:
(defrule checkHumidArea
(Request
(TechReqmnts ?treq_oid)
)
(TechnicalRequirements
(OBJECT ?treq_oid)
(Area ?area_oid)
)
(Area
(OBJECT ?area_oid)
(Humid true)
)
=>
...
This is not very generalized, but it works well if the XML structure is
known before hand and is fairly stable. There is a little more information
about this at our web site
http://grcinet.grci.com/maria/www/asasite/asa.html.
Alternatively, consider looking at the Resource Description Framework (RDF),
see http://www.w3.org/RDF/, which uses XML syntax but adds some object
flavor. By just adding a header and RDF tags, your XML can be treated as
RDF. There are RDF parsers which turn the XML into (subject, predicate,
object) triples, which can be the basic facts for your rules. Some of the
triples from your example (which I saved as jess-test.xml) are:
triple("file:jess-test.xml#genid5", "SupplyVoltage", literal("0"))
triple("file:jess-test.xml#genid13",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"file:jess-test.xml#Printer")
triple("file:jess-test.xml#genid3", "Aggressive", literal("false"))
triple("file:jess-test.xml#genid20",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"file:jess-test.xml#Cable")
triple("file:jess-test.xml#genid20", "CableType", literal(""))
This however can make the rules very complicated, since you will need to
collect all the little pieces of each object, but this is very general and
can represent any XML structure.
Hope this helps.
- Lewis
___________________________________________
Lewis L Hart
GRC International [EMAIL PROTECTED]
1900 Gallows Rd. Voice (703)506-5938
Vienna, Va 22182 Fax (703)556-4261
-----Original Message-----
From: Peter Frederick [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 28, 2001 9:17 AM
To: Jess-Users@Sandia. Gov
Subject: JESS: Building facts from XML files
Dear all,
I am trying to put together a rule-based reasoner with the facts coming
from an XML file. From what I've been able to read about fact construction,
facts are not designed to hold the heavily nested tree structure in an XML
file. However, I need to know which branches components belong to. Has
anyone else had to do anything like this and, if so, what tips could you
give for constructing the facts? I've attached a template file similar to
the one I'll need to work with.
Yours,
Pete Frederick
Mr Peter Frederick,
Research Scientist,
British Maritime Technology,
Orlando House,
1, Waldegrave Rd,
Teddington,
TW11 8LZ
Tel: 0044 (0) 208 943 5544 extn 217
Email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------