1
1
package com .formulasearchengine .mathmlquerygenerator ;
2
2
3
3
4
- import com .formulasearchengine .mathmltools .xmlhelper .XMLHelper ;
5
4
import com .formulasearchengine .mathmltools .xmlhelper .NonWhitespaceNodeList ;
5
+ import com .formulasearchengine .mathmltools .xmlhelper .XMLHelper ;
6
6
import com .google .common .collect .Lists ;
7
7
import org .w3c .dom .Document ;
8
8
import org .w3c .dom .Node ;
11
11
12
12
import javax .xml .parsers .ParserConfigurationException ;
13
13
import 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 ;
15
19
import java .util .regex .Pattern ;
16
20
17
- import static com .formulasearchengine .mathmltools .xmlhelper .NonWhitespaceNodeList .getFirstChild ;
18
-
19
21
/**
20
22
* Converts MathML queries into XQueries, given a namespace, a xquery/xpath to the root elements, and a xquery return format.
21
23
* 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) {
117
119
}
118
120
// if that fails try to get content MathML from an annotation tag
119
121
Node node = getContentMathMLNode (xml );
120
- if (node != null ) return node ;
122
+ if (node != null ) {
123
+ return node ;
124
+ }
121
125
// if that fails too interprete content of first semantic element as content MathML
122
126
expr = xml .getElementsByTagNameNS ("*" , "semantics" );
123
127
if (expr .getLength () > 0 ) {
@@ -136,8 +140,8 @@ private static Node getContentMathMLNode(Document xml) {
136
140
NodeList expr ;
137
141
expr = xml .getElementsByTagName ("annotation-xml" );
138
142
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" )) {
141
145
return node ;
142
146
}
143
147
}
@@ -216,7 +220,7 @@ private String getDefaultString() {
216
220
outBuilder .append (qvarMapVariable ).append ("\n " );
217
221
}
218
222
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 ())
220
224
.append ("\n " ).append (exactMatchXQuery );
221
225
if (!lengthConstraint .isEmpty () || !qvarConstraint .isEmpty ()) {
222
226
outBuilder .append ("\n " ).append ("where" ).append ("\n " );
@@ -389,7 +393,8 @@ private String generateSimpleConstraints(Node node, boolean isRoot) {
389
393
//Text nodes are always leaf nodes
390
394
out .append ("./text() = '" ).append (child .getNodeValue ().trim ()).append ("'" );
391
395
}
392
- }//for child : nodelist
396
+ }
397
+ //for child : nodelist
393
398
394
399
if (!isRoot && restrictLength ) {
395
400
if (lengthConstraint .isEmpty ()) {
@@ -414,5 +419,4 @@ public Map<String, ArrayList<String>> getQvar() {
414
419
}
415
420
return qvar ;
416
421
}
417
-
418
422
}
0 commit comments