|
24 | 24 | * http://ntcir-math.nii.ac.jp/wp-content/blogs.dir/13/files/2014/05/NTCIR11-Math-topics.pdf |
25 | 25 | */ |
26 | 26 | public class NtcirTopicReader { |
27 | | - public static final String NS_NII = "http://ntcir-math.nii.ac.jp/"; |
28 | | - private final Document topics; |
29 | | - private final List<NtcirPattern> patterns = new ArrayList<>(); |
30 | | - private final XQueryGenerator queryGenerator; |
| 27 | + public static final String NS_NII = "http://ntcir-math.nii.ac.jp/"; |
| 28 | + private final Document topics; |
| 29 | + private final List<NtcirPattern> patterns = new ArrayList<>(); |
| 30 | + private final XQueryGenerator queryGenerator; |
31 | 31 |
|
32 | | - public NtcirTopicReader( Document topics ) { |
33 | | - this.topics = topics; |
34 | | - queryGenerator = new XQueryGenerator( topics ); |
35 | | - } |
| 32 | + public NtcirTopicReader(Document topics) { |
| 33 | + this.topics = topics; |
| 34 | + queryGenerator = new XQueryGenerator(topics); |
| 35 | + } |
36 | 36 |
|
37 | | - public NtcirTopicReader( File topicFile ) throws ParserConfigurationException, IOException, SAXException { |
38 | | - DocumentBuilder documentBuilder = XMLHelper.getDocumentBuilder( true ); |
39 | | - topics = documentBuilder.parse( topicFile ); |
| 37 | + public NtcirTopicReader(File topicFile) throws ParserConfigurationException, IOException, SAXException { |
| 38 | + DocumentBuilder documentBuilder = XMLHelper.getDocumentBuilder(true); |
| 39 | + topics = documentBuilder.parse(topicFile); |
40 | 40 |
|
41 | | - //TODO: Find out how this code duplication can be avoided in Java. |
42 | | - queryGenerator = new XQueryGenerator( topics ); |
43 | | - } |
| 41 | + //TODO: Find out how this code duplication can be avoided in Java. |
| 42 | + queryGenerator = new XQueryGenerator(topics); |
| 43 | + } |
44 | 44 |
|
45 | | - public NtcirTopicReader( Document topics, String namespace, String pathToRoot, String returnFormat, boolean restrictLength ) { |
46 | | - queryGenerator = new XQueryGenerator( topics ); |
47 | | - this.topics = topics; |
48 | | - this.setNamespace(namespace).setReturnFormat(returnFormat).setPathToRoot(pathToRoot).setRestrictLength(restrictLength); |
49 | | - } |
| 45 | + public NtcirTopicReader(Document topics, String namespace, String pathToRoot, String returnFormat, boolean restrictLength) { |
| 46 | + queryGenerator = new XQueryGenerator(topics); |
| 47 | + this.topics = topics; |
| 48 | + this.setNamespace(namespace).setReturnFormat(returnFormat).setPathToRoot(pathToRoot).setRestrictLength(restrictLength); |
| 49 | + } |
50 | 50 |
|
51 | | - public final NtcirTopicReader setReturnFormat(String returnFormat) { |
52 | | - queryGenerator.setReturnFormat(returnFormat); |
53 | | - return this; |
54 | | - } |
| 51 | + public final NtcirTopicReader setReturnFormat(String returnFormat) { |
| 52 | + queryGenerator.setReturnFormat(returnFormat); |
| 53 | + return this; |
| 54 | + } |
55 | 55 |
|
56 | | - public final NtcirTopicReader setNamespace(String namespace) { |
57 | | - queryGenerator.setNamespace(namespace); |
58 | | - return this; |
59 | | - } |
| 56 | + public final NtcirTopicReader setNamespace(String namespace) { |
| 57 | + queryGenerator.setNamespace(namespace); |
| 58 | + return this; |
| 59 | + } |
60 | 60 |
|
61 | | - public final NtcirTopicReader setPathToRoot(String pathToRoot) { |
62 | | - queryGenerator.setPathToRoot(pathToRoot); |
63 | | - return this; |
64 | | - } |
| 61 | + public final NtcirTopicReader setPathToRoot(String pathToRoot) { |
| 62 | + queryGenerator.setPathToRoot(pathToRoot); |
| 63 | + return this; |
| 64 | + } |
65 | 65 |
|
66 | | - public final NtcirTopicReader setFindRootApply(boolean findRootApply) { |
67 | | - queryGenerator.setFindRootApply(findRootApply); |
68 | | - return this; |
69 | | - } |
| 66 | + public final NtcirTopicReader setFindRootApply(boolean findRootApply) { |
| 67 | + queryGenerator.setFindRootApply(findRootApply); |
| 68 | + return this; |
| 69 | + } |
70 | 70 |
|
71 | | - public final NtcirTopicReader setRestrictLength( boolean restrictLength ) { |
72 | | - queryGenerator.setRestrictLength( restrictLength ); |
73 | | - return this; |
74 | | - } |
| 71 | + public final NtcirTopicReader setRestrictLength(boolean restrictLength) { |
| 72 | + queryGenerator.setRestrictLength(restrictLength); |
| 73 | + return this; |
| 74 | + } |
75 | 75 |
|
76 | | - public final NtcirTopicReader setAddQvarMap( boolean addQvarMap ) { |
77 | | - queryGenerator.setAddQvarMap( addQvarMap ); |
78 | | - return this; |
79 | | - } |
| 76 | + public final NtcirTopicReader setAddQvarMap(boolean addQvarMap) { |
| 77 | + queryGenerator.setAddQvarMap(addQvarMap); |
| 78 | + return this; |
| 79 | + } |
80 | 80 |
|
81 | | - /** |
82 | | - * Splits the given NTCIR query file into individual queries, converts each query into an XQuery using |
83 | | - * XQueryGenerator, and returns the result as a list of NtcirPatterns for each individual query. |
84 | | - * @return List of NtcirPatterns for each query |
85 | | - * @throws XPathExpressionException Thrown if xpaths fail to compile or fail to evaluate |
86 | | - + */ |
87 | | - public final List<NtcirPattern> extractPatterns() throws XPathExpressionException { |
88 | | - final XPath xpath = XMLHelper.namespaceAwareXpath( "t", NS_NII ); |
89 | | - final XPathExpression xNum = xpath.compile( "./t:num" ); |
90 | | - final XPathExpression xFormula = xpath.compile( "./t:query/t:formula" ); |
91 | | - final NonWhitespaceNodeList topicList = new NonWhitespaceNodeList( |
92 | | - topics.getElementsByTagNameNS( NS_NII, "topic" ) ); |
93 | | - for ( final Node node : topicList ) { |
94 | | - final String num = xNum.evaluate( node ); |
95 | | - final NonWhitespaceNodeList formulae = new NonWhitespaceNodeList( (NodeList) |
96 | | - xFormula.evaluate( node, XPathConstants.NODESET ) ); |
97 | | - for ( final Node formula : formulae ) { |
98 | | - final String id = formula.getAttributes().getNamedItem( "id" ).getTextContent(); |
99 | | - final Node mathMLNode = getFirstChild( formula ); |
100 | | - queryGenerator.setMainElement( getFirstChild( mathMLNode ) ); |
101 | | - patterns.add( new NtcirPattern( num, id, queryGenerator.toString(), mathMLNode ) ); |
102 | | - } |
103 | | - } |
104 | | - return patterns; |
105 | | - } |
| 81 | + /** |
| 82 | + * Splits the given NTCIR query file into individual queries, converts each query into an XQuery using |
| 83 | + * XQueryGenerator, and returns the result as a list of NtcirPatterns for each individual query. |
| 84 | + * |
| 85 | + * @return List of NtcirPatterns for each query |
| 86 | + * @throws XPathExpressionException Thrown if xpaths fail to compile or fail to evaluate |
| 87 | + * + |
| 88 | + */ |
| 89 | + public final List<NtcirPattern> extractPatterns() throws XPathExpressionException { |
| 90 | + final XPath xpath = XMLHelper.namespaceAwareXpath("t", NS_NII); |
| 91 | + final XPathExpression xNum = xpath.compile("./t:num"); |
| 92 | + final XPathExpression xFormula = xpath.compile("./t:query/t:formula"); |
| 93 | + final NonWhitespaceNodeList topicList = new NonWhitespaceNodeList( |
| 94 | + topics.getElementsByTagNameNS(NS_NII, "topic")); |
| 95 | + for (final Node node : topicList) { |
| 96 | + final String num = xNum.evaluate(node); |
| 97 | + final NonWhitespaceNodeList formulae = new NonWhitespaceNodeList((NodeList) |
| 98 | + xFormula.evaluate(node, XPathConstants.NODESET)); |
| 99 | + for (final Node formula : formulae) { |
| 100 | + final String id = formula.getAttributes().getNamedItem("id").getTextContent(); |
| 101 | + final Node mathMLNode = getFirstChild(formula); |
| 102 | + queryGenerator.setMainElement(getFirstChild(mathMLNode)); |
| 103 | + patterns.add(new NtcirPattern(num, id, queryGenerator.toString(), mathMLNode)); |
| 104 | + } |
| 105 | + } |
| 106 | + return patterns; |
| 107 | + } |
106 | 108 | } |
0 commit comments