Any idea about CYK algorithm XSLT please have a look on the link below:
There are two input xml like below I have to pass sentance.xml in the xslt and then based on the words in each sentance I have to read the values at runtime from the Rule.xml file and then produce the new XML given below.
Only using XSLT, XPath and XML no any other language or keywords.
http://en.wikipedia.org/wiki/CYK_algorithm
1) sentance.xml
<?xml version="1.0" encoding="UTF-8"?>
<sentances>
<s>dog bark</s>
<s>cat drink milk</s>
</sentances>
1) sentance.xml
<?xml version="1.0" encoding="UTF-8"?>
<allrules>
<rules>
<rule cat="s">
<rulechild cat="np"/>
<rulechild cat="vp"/>
</rule>
<rule cat="vp">
<rulechild cat="vt"/>
<rulechild cat="np"/>
</rule>
<rule cat="vp">
<rulechild cat="vi"/>
</rule>
</rules>
<words>
<word cat="vi">bark</word>
<word cat="vt">drink</word>
<word cat="pn">dog</word>
<word cat="pn">cat</word>
<word cat="pn">milk</word>
</words>
</allrules>
OutPut XML should be like below:
<trees>
<tree>
<sentace>dog bark</sentace>
<node cat="s">
<node cat="np">
<word cat="pn">dog</word>
</node>
<node cat="vp">
<word cat="vi">bark</word>
</node>
</node>
</tree>
<tree>
<sentace>cat drink milk</sentace>
<node cat="s">
<node cat="np">
<word cat="pn">cat</word>
</node>
<node cat="vp">
<word cat="vt">drink</word>
<node cat="np">
<word cat="pn">milk</word>
</node>
</node>
</node>
</tree>
Could it be possible to implement the CYK algorithm and produce the above out using XSLT Someone please help on that...
Here is a solution should be close to what you have asked for. You did not specify the XSLT version. I have embedded the rules and symbols in the stylesheet, but you could easily adjust to make them an external document.
If XSLT 3.0 is not available to you, you could replace the fold-left() with tail-end recursion.
This input document ...
... when fed to this XSLT 3.0 stylesheet ...
... will yield this output ...
Caveat Emptor
I have not tested this.
Alternative
If you are not interested in all permutations, and just want any (the first) permutation, then we can add a few more templates and strip out all the permutations but one.
Alternative output
The output should then be tidier, and look something like this ...