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

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
physikerwelt committed Mar 18, 2017
1 parent 6a0e825 commit 93006d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.formulasearchengine.mathmlquerygenerator;

import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
import com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList;
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList.getFirstChild;

/**
* Created by Moritz on 08.11.2014.
* <p/>
Expand Down Expand Up @@ -98,8 +99,8 @@ public final List<NtcirPattern> extractPatterns() throws XPathExpressionExceptio
xFormula.evaluate(node, XPathConstants.NODESET));
for (final Node formula : formulae) {
final String id = formula.getAttributes().getNamedItem("id").getTextContent();
final Node mathMLNode = getFirstChild(formula);
queryGenerator.setMainElement(getFirstChild(mathMLNode));
final Node mathMLNode = NonWhitespaceNodeList.getFirstChild(formula);
queryGenerator.setMainElement(NonWhitespaceNodeList.getFirstChild(mathMLNode));
patterns.add(new NtcirPattern(num, id, queryGenerator.toString(), mathMLNode));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.formulasearchengine.mathmlquerygenerator;


import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
import com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList;
import com.formulasearchengine.mathmltools.xmlhelper.XMLHelper;
import com.google.common.collect.Lists;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand All @@ -11,11 +11,13 @@

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;

import static com.formulasearchengine.mathmltools.xmlhelper.NonWhitespaceNodeList.getFirstChild;

/**
* Converts MathML queries into XQueries, given a namespace, a xquery/xpath to the root elements, and a xquery return format.
* The variable $x always represents a hit, so you can refer to $x in the return format as the result node.
Expand Down Expand Up @@ -117,7 +119,9 @@ public static Node getMainElement(Document xml) {
}
// if that fails try to get content MathML from an annotation tag
Node node = getContentMathMLNode(xml);
if (node != null) return node;
if (node != null) {
return node;
}
// if that fails too interprete content of first semantic element as content MathML
expr = xml.getElementsByTagNameNS("*", "semantics");
if (expr.getLength() > 0) {
Expand All @@ -136,8 +140,8 @@ private static Node getContentMathMLNode(Document xml) {
NodeList expr;
expr = xml.getElementsByTagName("annotation-xml");
for (Node node : new NonWhitespaceNodeList(expr)) {
if (node.hasAttributes() &&
node.getAttributes().getNamedItem("encoding").getNodeValue().equals("MathML-Content")) {
if (node.hasAttributes()
&& node.getAttributes().getNamedItem("encoding").getNodeValue().equals("MathML-Content")) {
return node;
}
}
Expand Down Expand Up @@ -216,7 +220,7 @@ private String getDefaultString() {
outBuilder.append(qvarMapVariable).append("\n");
}
outBuilder.append("for $m in ").append(pathToRoot).append(" return\n")
.append("for $x in $m//*:").append(getFirstChild(mainElement).getLocalName())
.append("for $x in $m//*:").append(NonWhitespaceNodeList.getFirstChild(mainElement).getLocalName())
.append("\n").append(exactMatchXQuery);
if (!lengthConstraint.isEmpty() || !qvarConstraint.isEmpty()) {
outBuilder.append("\n").append("where").append("\n");
Expand Down Expand Up @@ -389,7 +393,8 @@ private String generateSimpleConstraints(Node node, boolean isRoot) {
//Text nodes are always leaf nodes
out.append("./text() = '").append(child.getNodeValue().trim()).append("'");
}
}//for child : nodelist
}
//for child : nodelist

if (!isRoot && restrictLength) {
if (lengthConstraint.isEmpty()) {
Expand All @@ -414,5 +419,4 @@ public Map<String, ArrayList<String>> getQvar() {
}
return qvar;
}

}

0 comments on commit 93006d4

Please sign in to comment.