Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 93006d4

Browse files
committed
Improve code style
1 parent 6a0e825 commit 93006d4

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/main/java/com/formulasearchengine/mathmlquerygenerator/NtcirTopicReader.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package com.formulasearchengine.mathmlquerygenerator;
22

3-
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
43
import com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList;
4+
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
55
import org.w3c.dom.Document;
66
import org.w3c.dom.Node;
77
import org.w3c.dom.NodeList;
88
import org.xml.sax.SAXException;
99

1010
import javax.xml.parsers.DocumentBuilder;
1111
import javax.xml.parsers.ParserConfigurationException;
12-
import javax.xml.xpath.*;
12+
import javax.xml.xpath.XPath;
13+
import javax.xml.xpath.XPathConstants;
14+
import javax.xml.xpath.XPathExpression;
15+
import javax.xml.xpath.XPathExpressionException;
1316
import java.io.File;
1417
import java.io.IOException;
1518
import java.util.ArrayList;
1619
import java.util.List;
1720

18-
import static com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList.getFirstChild;
19-
2021
/**
2122
* Created by Moritz on 08.11.2014.
2223
* <p/>
@@ -98,8 +99,8 @@ public final List<NtcirPattern> extractPatterns() throws XPathExpressionExceptio
9899
xFormula.evaluate(node, XPathConstants.NODESET));
99100
for (final Node formula : formulae) {
100101
final String id = formula.getAttributes().getNamedItem("id").getTextContent();
101-
final Node mathMLNode = getFirstChild(formula);
102-
queryGenerator.setMainElement(getFirstChild(mathMLNode));
102+
final Node mathMLNode = NonWhitespaceNodeList.getFirstChild(formula);
103+
queryGenerator.setMainElement(NonWhitespaceNodeList.getFirstChild(mathMLNode));
103104
patterns.add(new NtcirPattern(num, id, queryGenerator.toString(), mathMLNode));
104105
}
105106
}

src/main/java/com/formulasearchengine/mathmlquerygenerator/XQueryGenerator.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.formulasearchengine.mathmlquerygenerator;
22

33

4-
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
54
import com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList;
5+
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
66
import com.google.common.collect.Lists;
77
import org.w3c.dom.Document;
88
import org.w3c.dom.Node;
@@ -11,11 +11,13 @@
1111

1212
import javax.xml.parsers.ParserConfigurationException;
1313
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;
1519
import 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

Comments
 (0)