Implementation

Although the core of our application is written with (fuzzy) MALP rules, we have reused/adapted several modules of our previous Prolog-based implementation of (crisp) XPath described in [ALM09], which make use of the SWI-Prolog library for loading XML files in order to store each XML document by means of a Prolog term representing a tree. The clever idea is that each tag is represented as a data-term of the form

element(Tag,Attributes,Subelements)

where Tag is the name of the XML tag, Attributes is a list containing the attributes, and Subelements is a list containing the subelements (i.e. subtrees) of the tag. For instance, let us consider the XML document of Figure 1,

Figure 1: Input XML document collecting Hotel's information

represented in SWI-Prolog like in Figure 2. Moreover, for loading XML documents in our prototype we can use the predicate load_xml(+File,-Term) defined as follows:

load_xml(File,Term):-load_structure(File,Term,[dialect(sgml)])

where load_structure(+File,-Term,+Options) is the SWI-Prolog predicate of the XML library for loading XML documents. Similarly, we have implemented a predicate called write_xml(+File,+Term) for writing data-terms representing a XML document into a file. And, of course, the parser of our application has been extended to recognize the new keywords deep, down, avg, etc... with their proper arguments.

Fig. 2: A data-term representing an XML document

Fig. 3: Example of a tv structure

Now, we are going to present how the new «fuzzyXPath» predicate admits an elegant definition by means of fuzzy MALP rules which, after being compiled into clauses using FLOPER, can be safely executed in any standard Prolog platform. Each rule defining predicate

fuzzyXPath(ListXP ath,Tree,Deep,Down)

receives four arguments: (1) ListXPath is the Prolog representation of an XPath expression, (2) Tree is the term representing an input XML document and (3) Deep/Down which have the obvious meaning -their default values are tv(1,[])-. A call to this predicate, returns after being executed a truth-value (i.e., a tv tree) like the one depicted in Figure 3.

For instance, the query «[DEEP=0.9,DOWN=0.8]/Path » on a given XML term, would generate a call of the form

fuzzyXPath(Path,XM L,tv(0.9,[]),tv(0.8,[]))

whose further execution will return the resulting tv tree.

Basically, the fuzzyXPath predicate traverses the Prolog tree representing a XML document and extracts in the returned tv tree the subtrees occurring in the given path, also annotating into the nested tv trees the corresponding deep/down values according the movements performed (in the horizontal and vertical axis, respectively) when navigating on the XML tree.

The definition of such predicate includes several rules for distinguishing cases in the form of the input document and the XPath expression. As an example, we can see the rule of Figure 9, whose translation to Prolog is shown in Figure 5.

Fig. 4: MALP rule for traversing element structures representing XML documents

Let us remark that the parameters Deep and Down are tv trees of the form tv(r1,[]) and tv(r2,[]) whenever the XPath expression is of the form [DEEP = r1,DOWN = r2]∕path.... They are passed as arguments in order to be used for penalizing nesting and order.

Fig. 5: Prolog clause obtained by FLOPER after compiling a MALP rule

Let us explain in detail the fuzzy code of Figure 9. After performing a recursive call to compute the solutions associated to the Children of a given node (i.e., fuzzyXPath(LabelRest, Children, Deep,Down)), we use connective &prod to muffle the resulting tv tree according to Deep, which is represented by sentence &prod(Deep,fuzzyXPath(LabelRest,Children,Deep,Down)). A similar operation is next performed on the siblings of the node, whose result is penalized now according Down, that is, &prod(Down, fuzzyXPath([Label|LabelRest], Siblings, Deep, Down)). Finally, both tv trees are combined (fused) with the content of the current node.

On the other hand, when considering queries containing expressions with conditions, the fuzzyXPath predicate evolves as shown in the MALP rule listed in Figure 6. Here it is remarkable the direct use of connective avg when defining the recursive execute_fcond predicate.

Fig. 6: Schema of MALP rules for evaluating conditions (with avg)

Finally, we have defined a predicate tv_to_elem to show the result in a pretty way (see Figures 3 and 4), which transforms the returned tv tree to a XML tree.

izmir escort- cratosslot baymavi vdcasino asyabahis tipobet