_build
*.native
*.byte
+tests/*.results/*
+
+++ /dev/null
-#!/bin/sh
-
-cd src
-echo `pwd`
-for dir in *
-do
- if [ -d "$dir" ]
- then
- echo "$dir"
- rm -f "$dir".mlpack
- cd "$dir"
- for i in *.ml *.mly *.mll
- do
- if [ ! -f "$i" ]
- then
- continue
- fi
- echo "$i"
- f=`echo "$i" | cut -b1`
- l=`basename "$i" .mll`
- l=`basename "$l" .mly`
- l=`basename "$l" .ml | cut -b2-`
- o=`echo "$f" | tr a-z A-Z`
- echo "$dir"/"$o""$l" >> ../"$dir".mlpack
- done
- cd ..
- fi
-done
-cd ..
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><A id="n1" pre="1" post="26" xml:lang="en"><B id="n2" pre="2" post="3"><C id="n3" pre="3" post="1">clergywoman</C><D id="n4" pre="4" post="2">decadent</D></B><E id="n5" pre="5" post="22"><F id="n6" pre="6" post="6"><G id="n7" pre="7" post="4">gentility</G><H id="n8" pre="8" post="5" idrefs="n17 n26">happy-go-lucky man</H></F><I id="n9" pre="9" post="9"><J id="n10" pre="10" post="7">jigsaw</J><K id="n11" pre="11" post="8">kerchief</K></I><L id="n12" pre="12" post="15"><!--L is the twelve-th letter of the English alphabet-->The letter L is followed by the letter:<M id="n13" pre="13" post="10"/>which is followed by the letter:<N id="n14" pre="14" post="13"><O id="n15" pre="15" post="11">ovenware</O><P id="n16" pre="16" post="12">plentiful</P></N><?myPI value="XPath is nice"?><Q id="n17" pre="17" post="14" idrefs="n8 n26">quarrelsome</Q></L><R id="n18" pre="18" post="18"><S id="n19" pre="19" post="16">sage</S><T id="n20" pre="20" post="17">tattered</T></R><U id="n21" pre="21" post="21"><V id="n22" pre="22" post="19">voluptuary</V><W id="n23" pre="23" post="20">wriggle</W></U></E><X id="n24" pre="24" post="25"><Y id="n25" pre="25" post="23">yawn</Y><Z id="n26" pre="26" post="24" idrefs="n8 n17" xml:lang="it">zuzzurellone</Z></X></A>
--- /dev/null
+A1 //L/*
+A2 //L/parent::*
+A3 //L/descendant::*
+A4 //L/descendant-or-self::*
+A5 //L/ancestor::*
+A6 //L/ancestor-or-self::*
+A7 //L/following-sibling::*
+A8 //L/preceding-sibling::*
+A9 //L/following::*
+A10 //L/preceding::*
+A11 //L/self::*
+A12 //L/@id/parent::*
+P1 //*[L]
+P2 //*[parent::L]
+P3 //*[descendant::L]
+P4 //*[descendant-or-self::L]
+P5 //*[ancestor::L]
+P6 //*[ancestor-or-self::L]
+P7 //*[following-sibling::L]
+P8 //*[preceding-sibling::L]
+P9 //*[following::L]
+P10 //*[preceding::L]
+P11 //*[self::L]
+P12 //*[@id]
+T1 //L/text()
+T2 //L/comment()
+# T3 //L/processing-instruction()
+# T4 //L/processing-instruction("myPI")
+T5 //L/node()
+T6 //L/N
+T7 //L/*
+O1 //*[child::* and preceding::Q]
+O2 //*[not(child::*) and preceding::Q]
+O3 //*[preceding::L or following::L]
+O4 //L/ancestor::* | //L/descendant::*
+# O5 //*[.="happy-go-lucky man"]
+# O6 //*[@pre > 12 and @post < 15]
+# O7 //*[@pre != @post]
+# O8 //*[((@post * @post + @pre * @pre) div (@post + @pre)) > ((@post - @pre) * (@post - @pre))]
+# O9 //*[@pre mod 2 = 0]
+# F1 //*[contains(.,"plentiful")]
+# F2 //*[starts-with(.,"plentiful")]
+# F3 //*[substring(.,1,9) = "plentiful"]
+# F4 //*[substring-after(.,"oven") = "ware"]
+# F5 //*[substring-before(.,"ful") = "plenti"]
+# F6 //*[string-length(translate(normalize-space(.)," ","")) > 100]
+# F7 //*[concat(.,..) = ..]
+# F8 //*[ceiling(@pre div @post) = 1]
+# F9 //*[floor(@pre div @post) = 0]
+# F10 //*[round(@pre div @post) = 0]
+# F11 //*[name(.) = "X"]
+# F12 //*[lang("it")]
+# F13 //L/child::*[last()]
+# F14 //L/descendant::*[4]
+# F15 //L/ancestor::*[2]
+# F16 //L/following-sibling::*[1]
+# F17 //L/preceding-sibling::*[1]
+# F18 //L/following::*[7]
+# F19 //L/preceding::*[7]
+# F20 //*[count(ancestor::*) > 3]
+# F21 //*[sum(ancestor::*/@pre) < sum(descendant::*/@pre)]
+# F22 id("n1 n26")
+# F23 id(id(//*[.="happy-go-lucky man"]/@idrefs)/@idrefs)
+# F24 //*[number(@pre) < number(@post)]
+# F25 //*[string(@pre - 1) = "0"]
+# F26 //*[boolean(@id) = true() and boolean(@idrefs) = false()]
--- /dev/null
+all: XPathEval.class xml_diff
+
+
+xml_diff: xml_diff.ml
+ ocamlfind ocamlopt -o xml_diff -package expat -linkpkg xml_diff.ml
+
+XPathEval.class: XPathEval.java
+ javac XPathEval.java
+
+
+clean:
+ rm -f XPathEval.class xml_diff *.o *.cm*
--- /dev/null
+import javax.xml.xpath.*;
+import org.xml.sax.*;
+import org.w3c.dom.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+
+public class XPathEval {
+
+
+ public static void main(String args[]) {
+ try {
+
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ String expression = args[1];
+ InputSource inputSource = new InputSource(args[0]);
+ NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
+ Transformer serializer = TransformerFactory.newInstance().newTransformer();
+ serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ StreamResult o = new StreamResult(System.out);
+ System.out.println("<xml_result>");
+ for(int i = 0; i < nodes.getLength(); i++){
+ serializer.transform(new DOMSource(nodes.item(i)), o);
+ System.out.println("");
+ };
+ System.out.println("</xml_result>");
+ } catch (XPathException e) {
+ System.out.println (e.getCause());
+ } catch (Exception e) {
+ System.out.println(e);
+ };
+
+
+ }
+}
--- /dev/null
+#!/bin/sh
+
+cd src
+echo `pwd`
+for dir in *
+do
+ if [ -d "$dir" ]
+ then
+ echo "$dir"
+ rm -f "$dir".mlpack
+ cd "$dir"
+ for i in *.ml *.mly *.mll
+ do
+ if [ ! -f "$i" ]
+ then
+ continue
+ fi
+ echo "$i"
+ f=`echo "$i" | cut -b1`
+ l=`basename "$i" .mll`
+ l=`basename "$l" .mly`
+ l=`basename "$l" .ml | cut -b2-`
+ o=`echo "$f" | tr a-z A-Z`
+ echo "$dir"/"$o""$l" >> ../"$dir".mlpack
+ done
+ cd ..
+ fi
+done
+cd ..
\ No newline at end of file
--- /dev/null
+#!/bin/sh
+
+usage() {
+ echo "error: missing input, query file or XPathEval class"
+ echo "usage: $0 file.xml"
+}
+
+FILE="$1"
+RESULTS="$FILE".results
+QUERIES="$FILE".queries
+
+if test ! -f "$FILE" -o ! -f "$QUERIES" -o ! -f XPathEval.class
+then
+ usage;
+ exit 1
+fi
+
+
+mkdir -p "$RESULTS"
+
+cat "$QUERIES" | grep -v '^#' | while read qname q
+do
+ echo "Computing $q"
+ java XPathEval "$FILE" "$q" > "$RESULTS"/"$qname".xml
+done
--- /dev/null
+type event = Open of string * (string * string) list | Close of string | Text of string
+
+let eq_event e1 e2 =
+ match e1, e2 with
+ | Open(t1, l1), Open(t2, l2) -> t1 = t2 &&
+ let sl1 = List.sort compare l1
+ and sl2 = List.sort compare l2 in sl1 = sl2
+ | Close t1, Close t2 -> t1 = t2
+ | Text s1 , Text s2 -> s1 = s2
+ | _ -> false
+
+
+type position = {
+ byte_index : int;
+ column_num : int;
+ line_num : int;
+ byte_count : int;
+}
+
+type ctx = {
+ text_buffer : Buffer.t;
+ events : (event*position) Queue.t;
+}
+let get_position p =
+ { byte_index = Expat.get_current_byte_index p;
+ column_num = Expat.get_current_column_number p;
+ line_num = Expat.get_current_line_number p;
+ byte_count = Expat.get_current_byte_count p;
+ }
+
+
+let rec start_element_handler parser_ ctx tag attr_list =
+ do_text parser_ ctx;
+ Queue.add (Open(tag, attr_list), get_position parser_) ctx.events
+
+and end_element_handler parser_ ctx tag =
+ do_text parser_ ctx;
+ Queue.add (Close(tag), get_position parser_) ctx.events
+
+and do_text parser_ ctx =
+ if Buffer.length ctx.text_buffer != 0 then
+ let s = Buffer.contents ctx.text_buffer in
+ Buffer.clear ctx.text_buffer;
+ Queue.add (Text s, get_position parser_) ctx.events
+
+let character_data_handler parser_ ctx text =
+ Buffer.add_string ctx.text_buffer text
+
+let create_parser () =
+ let ctx1 = { text_buffer = Buffer.create 512; events = Queue.create (); } in
+ let parser1 = Expat.parser_create ~encoding:None in
+ Expat.set_start_element_handler parser1 (start_element_handler parser1 ctx1);
+ Expat.set_end_element_handler parser1 (end_element_handler parser1 ctx1);
+ Expat.set_character_data_handler
+ parser1 (character_data_handler parser1 ctx1);
+ parser1, ctx1
+
+exception Diff of position
+
+let diffs fd1 fd2 =
+ let buffer1 = String.create 4096 in
+ let buffer2 = String.create 4096 in
+ let parser1,ctx1 = create_parser () in
+ let parser2,ctx2 = create_parser () in
+ let rec loop () =
+ let read1 = input fd1 buffer1 0 4096 in
+ let read2 = input fd2 buffer2 0 4096 in
+ if read1 == 0 && read2 == 0 then () else
+ let () = Expat.parse_sub parser1 buffer1 0 read1 in
+ let () = Expat.parse_sub parser2 buffer2 0 read2 in
+ for i = 1 to min (Queue.length ctx1.events) (Queue.length ctx2.events) do
+ let e1,p1 = Queue.pop ctx1.events in
+ let e2,_ = Queue.pop ctx2.events in
+ if not (eq_event e1 e2) then
+ raise (Diff p1)
+ done;
+ loop ()
+ in
+ loop ()
+
+let main () =
+ if Array.length Sys.argv != 3 then
+ Printf.eprintf "usage: %s file1.xml file2.xml\n%!" Sys.argv.(0)
+ else
+ let fn1 = Sys.argv.(1) in
+ let fn2 = Sys.argv.(2) in
+ try
+ let fd1 = open_in fn1 in
+ let fd2 = open_in fn2 in
+ let () =
+ try
+ diffs fd1 fd2
+ with
+ Diff p -> Printf.printf "File %s and %s differ at line %i, column %i\n%!"
+ fn1 fn2 p.line_num p.column_num
+ in close_in fd1; close_in fd2
+ with
+ _ -> Printf.eprintf "Error\n%!"
+let () = main ()
+