11package com .formulasearchengine .mathmlquerygenerator ;
22
33
4- import com .formulasearchengine .mathmltools .xmlhelper .XMLHelper ;
54import com .formulasearchengine .mathmltools .xmlhelper .NonWhitespaceNodeList ;
5+ import com .formulasearchengine .mathmltools .xmlhelper .XMLHelper ;
66import com .google .common .collect .Lists ;
77import org .w3c .dom .Document ;
88import org .w3c .dom .Node ;
1111
1212import javax .xml .parsers .ParserConfigurationException ;
1313import java .io .IOException ;
14- import java .util .*;
14+ import java .util .ArrayList ;
15+ import java .util .HashMap ;
16+ import java .util .Iterator ;
17+ import java .util .LinkedHashMap ;
18+ import java .util .Map ;
1519import java .util .regex .Pattern ;
1620
17- import static com .formulasearchengine .mathmltools .xmlhelper .NonWhitespaceNodeList .getFirstChild ;
18-
1921/**
2022 * Converts MathML queries into XQueries, given a namespace, a xquery/xpath to the root elements, and a xquery return format.
2123 * The variable $x always represents a hit, so you can refer to $x in the return format as the result node.
@@ -117,7 +119,9 @@ public static Node getMainElement(Document xml) {
117119 }
118120 // if that fails try to get content MathML from an annotation tag
119121 Node node = getContentMathMLNode (xml );
120- if (node != null ) return node ;
122+ if (node != null ) {
123+ return node ;
124+ }
121125 // if that fails too interprete content of first semantic element as content MathML
122126 expr = xml .getElementsByTagNameNS ("*" , "semantics" );
123127 if (expr .getLength () > 0 ) {
@@ -136,8 +140,8 @@ private static Node getContentMathMLNode(Document xml) {
136140 NodeList expr ;
137141 expr = xml .getElementsByTagName ("annotation-xml" );
138142 for (Node node : new NonWhitespaceNodeList (expr )) {
139- if (node .hasAttributes () &&
140- node .getAttributes ().getNamedItem ("encoding" ).getNodeValue ().equals ("MathML-Content" )) {
143+ if (node .hasAttributes ()
144+ && node .getAttributes ().getNamedItem ("encoding" ).getNodeValue ().equals ("MathML-Content" )) {
141145 return node ;
142146 }
143147 }
@@ -216,7 +220,7 @@ private String getDefaultString() {
216220 outBuilder .append (qvarMapVariable ).append ("\n " );
217221 }
218222 outBuilder .append ("for $m in " ).append (pathToRoot ).append (" return\n " )
219- .append ("for $x in $m//*:" ).append (getFirstChild (mainElement ).getLocalName ())
223+ .append ("for $x in $m//*:" ).append (NonWhitespaceNodeList . getFirstChild (mainElement ).getLocalName ())
220224 .append ("\n " ).append (exactMatchXQuery );
221225 if (!lengthConstraint .isEmpty () || !qvarConstraint .isEmpty ()) {
222226 outBuilder .append ("\n " ).append ("where" ).append ("\n " );
@@ -389,7 +393,8 @@ private String generateSimpleConstraints(Node node, boolean isRoot) {
389393 //Text nodes are always leaf nodes
390394 out .append ("./text() = '" ).append (child .getNodeValue ().trim ()).append ("'" );
391395 }
392- }//for child : nodelist
396+ }
397+ //for child : nodelist
393398
394399 if (!isRoot && restrictLength ) {
395400 if (lengthConstraint .isEmpty ()) {
@@ -414,5 +419,4 @@ public Map<String, ArrayList<String>> getQvar() {
414419 }
415420 return qvar ;
416421 }
417-
418422}
0 commit comments