import org.xerial.core.XerialException;\r
import org.xerial.lens.relation.Node;\r
import org.xerial.lens.relation.Tuple;\r
+import org.xerial.lens.relation.lang.RelationExpr;\r
import org.xerial.lens.relation.query.QuerySet;\r
import org.xerial.lens.relation.query.RelationExtractor;\r
import org.xerial.lens.relation.query.RelationHandler;\r
-import org.xerial.lens.relation.query.lang.RelationExpr;\r
import org.xerial.lens.relation.schema.Schema;\r
import org.xerial.util.log.Logger;\r
import org.xerial.util.tree.TreeParser;\r
* \r
* @param visitor\r
*/\r
- void accept(TupleElementVisitor<NodeType> visitor);\r
+ void accept(TupleVisitor<NodeType> visitor);\r
\r
}\r
}\r
\r
@SuppressWarnings("unchecked")\r
- public void accept(TupleElementVisitor<NodeType> visitor) {\r
+ public void accept(TupleVisitor<NodeType> visitor) {\r
visitor.visitNode((NodeType) this);\r
}\r
\r
}\r
}\r
\r
- public void accept(TupleElementVisitor<Element> visitor) {\r
+ public void accept(TupleVisitor<Element> visitor) {\r
visitor.visitTuple(this);\r
}\r
\r
public int size();\r
\r
/**\r
- * Get the cell at the specified index\r
+ * Get the tuple element at the specified index\r
* \r
* @param index\r
* @return\r
* \r
* @param visitor\r
*/\r
- void accept(TupleElementVisitor<Element> visitor);\r
+ void accept(TupleVisitor<Element> visitor);\r
\r
}\r
* @author leo\r
* \r
*/\r
-public interface TupleElementVisitor<NodeType>\r
-{\r
+public interface TupleVisitor<NodeType> {\r
public void visitNode(NodeType node);\r
\r
public void visitTuple(Tuple<NodeType> tuple);\r
// $URL$\r
// $Author$\r
//--------------------------------------\r
-package org.xerial.lens.relation.query.lang;\r
+package org.xerial.lens.relation.lang;\r
\r
import org.xerial.lens.relation.NodeBase;\r
\r
// $URL$\r
// $Author$\r
//--------------------------------------\r
-package org.xerial.lens.relation.query.lang;\r
+package org.xerial.lens.relation.lang;\r
\r
import org.antlr.runtime.ANTLRStringStream;\r
import org.antlr.runtime.CommonTokenStream;\r
\r
SchemaBuilder parent = new SchemaBuilder();\r
parent.add(name);\r
+\r
for (TupleElement<RelationAttribute> each : this) {\r
\r
if (each.isTuple()) {\r
RelationExpr re = RelationExpr.class.cast(each);\r
- for (Schema s : re.buildQuerySet().getTargetQuerySet()) {\r
+ for (Schema s : re.buildQuerySet().getTargetQuerySet())\r
b.addQueryTarget(s);\r
- }\r
}\r
else {\r
RelationAttribute ra = RelationAttribute.class.cast(each);\r
// $URL$\r
// $Author$\r
//--------------------------------------\r
-package org.xerial.lens.relation.query.lang;\r
+package org.xerial.lens.relation.lang;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
import java.util.List;
import org.xerial.lens.relation.TupleElement;
-import org.xerial.lens.relation.TupleElementVisitor;
+import org.xerial.lens.relation.TupleVisitor;
import org.xerial.lens.relation.Node;
import org.xerial.lens.relation.Tuple;
import org.xerial.lens.relation.TupleIndex;
return new Tuple<Node>(nodeList);
}
- class CompletenessTester implements TupleElementVisitor<Node> {
+ class CompletenessTester implements TupleVisitor<Node> {
boolean hasNull = false;
public boolean isComplete() {
--- /dev/null
+/*--------------------------------------------------------------------------\r
+ * Copyright 2009 Taro L. Saito\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *--------------------------------------------------------------------------*/\r
+//--------------------------------------\r
+// XerialJ\r
+//\r
+// DSNumber.java\r
+// Since: 2009/05/13 9:29:15\r
+//\r
+// $URL$\r
+// $Author$\r
+//--------------------------------------\r
+package org.xerial.util;\r
+\r
+import org.xerial.core.XerialError;\r
+import org.xerial.core.XerialErrorCode;\r
+\r
+/**\r
+ * DSNumber (Dot-separated number) for specifying a position in a nested node\r
+ * tuple, e.g., 1, 1.1, 1.2, ...etc.\r
+ * \r
+ * @author leo\r
+ * \r
+ */\r
+public class DSNumber implements Comparable<DSNumber> {\r
+ private int[] index;\r
+\r
+ /**\r
+ * Create an index with a single level, e.g., 1, 2, 3, ...\r
+ * \r
+ * @param baseIndex\r
+ */\r
+ public DSNumber(int baseIndex) {\r
+ this.index = new int[1];\r
+ this.index[0] = baseIndex;\r
+ }\r
+\r
+ /**\r
+ * Create an index based on a parent index, e.g, 1.1, 1.2, 1.1.1, 1.1.2,\r
+ * ..etc.\r
+ * \r
+ * @param parent\r
+ * @param childIndex\r
+ */\r
+ public DSNumber(DSNumber parent, int childIndex) {\r
+ if (parent == null) {\r
+ this.index = new int[1];\r
+ this.index[0] = childIndex;\r
+ }\r
+ else {\r
+ this.index = new int[parent.size() + 1];\r
+ for (int i = 0; i < parent.size(); ++i)\r
+ index[i] = parent.get(i);\r
+ index[parent.size()] = childIndex;\r
+ }\r
+ }\r
+\r
+ public static DSNumber root() {\r
+ return new DSNumber(0);\r
+ }\r
+\r
+ public static DSNumber parse(String indexStr) {\r
+ if (indexStr == null)\r
+ throw new NullPointerException("indexStr");\r
+\r
+ String[] component = indexStr.split("\\.");\r
+ if (component == null)\r
+ throw new XerialError(XerialErrorCode.INVALID_INPUT, "invalid format:" + indexStr);\r
+\r
+ int[] index = new int[component.length];\r
+ for (int i = 0; i < component.length; ++i)\r
+ index[i] = Integer.parseInt(component[i]);\r
+ return new DSNumber(index);\r
+ }\r
+\r
+ private DSNumber(int[] index) {\r
+ this.index = index;\r
+ }\r
+\r
+ public DSNumber parent() {\r
+ if (index.length <= 1)\r
+ return null;\r
+\r
+ int[] newIndex = new int[index.length - 1];\r
+ for (int i = 0; i < index.length - 1; ++i)\r
+ newIndex[i] = index[i];\r
+ return new DSNumber(newIndex);\r
+ }\r
+\r
+ public DSNumber tail() {\r
+ if (index.length < 2)\r
+ return null;\r
+\r
+ int[] newIndex = new int[index.length - 1];\r
+ for (int i = 1; i < index.length; ++i)\r
+ newIndex[i - 1] = index[i];\r
+ return new DSNumber(newIndex);\r
+ }\r
+\r
+ public DSNumber sibling() {\r
+ int[] newIndex = new int[index.length];\r
+ for (int i = 0; i < index.length; ++i)\r
+ newIndex[i] = index[i];\r
+ newIndex[index.length - 1]++;\r
+ return new DSNumber(newIndex);\r
+ }\r
+\r
+ /**\r
+ * nested level\r
+ * \r
+ * @return nested level\r
+ */\r
+ public int size() {\r
+ return index.length;\r
+ }\r
+\r
+ public boolean hasParent() {\r
+ return index.length > 1;\r
+ }\r
+\r
+ public boolean hasTail() {\r
+ return index.length > 1;\r
+ }\r
+\r
+ /**\r
+ * Get the index on the specified level\r
+ * \r
+ * @param level\r
+ * @return\r
+ */\r
+ public int get(int level) {\r
+ return index[level];\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ StringBuilder buf = new StringBuilder();\r
+ for (int i = 0; i < index.length; i++) {\r
+ if (i != 0)\r
+ buf.append(".");\r
+ buf.append(index[i]);\r
+ }\r
+ return buf.toString();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ DSNumber other = DSNumber.class.cast(obj);\r
+ if (this.index.length != other.index.length)\r
+ return false;\r
+\r
+ for (int i = 0; i < this.index.length; ++i) {\r
+ if (this.index[i] != other.index[i])\r
+ return false;\r
+ }\r
+ return true;\r
+\r
+ }\r
+\r
+ public int compareTo(DSNumber other) {\r
+ int i1 = 0;\r
+ int i2 = 0;\r
+ int cmp = 0;\r
+ while (i1 < this.index.length && i2 < other.index.length) {\r
+ int e1 = this.index[i1];\r
+ int e2 = other.index[i2];\r
+ cmp = e1 - e2;\r
+ if (cmp != 0)\r
+ return cmp;\r
+\r
+ i1++;\r
+ i2++;\r
+ }\r
+ if (i1 < this.index.length)\r
+ return 1;\r
+ else {\r
+ if (i2 < other.index.length)\r
+ return -1;\r
+ else\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ int hash = 3;\r
+ for (int i = 0; i < index.length; ++i)\r
+ hash += 137 * index[i];\r
+ return hash / 1987;\r
+ }\r
+\r
+}\r
OCCURRENCE;
CONTENTSPEC;
ENTITY;
+ENTITY_REF;
VALUE;
}
entityDecl
: '<!ENTITY' Name String '>' -> ^(ENTITY NAME[$Name.text] VALUE[$String.text])
- | '<!ENTITY' '%' Name String '>' -> ^(ENTITY NAME[$Name.text] VALUE[$String.text])
+ | '<!ENTITY' '%' Name String '>' -> ^(ENTITY_REF NAME[$Name.text] VALUE[$String.text])
;
\ No newline at end of file
// $URL$\r
// $Author$\r
//--------------------------------------\r
-package org.xerial.lens.relation.query.lang;\r
+package org.xerial.lens.relation.lang;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.xerial.lens.Lens;\r
+import org.xerial.lens.relation.lang.RelationExpr;\r
import org.xerial.util.log.Logger;\r
\r
public class RelationExprTest {\r
// $URL$\r
// $Author$\r
//--------------------------------------\r
-package org.xerial.lens.relation.query.lang;\r
+package org.xerial.lens.relation.lang;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.xerial.core.XerialException;\r
import org.xerial.lens.Lens;\r
+import org.xerial.lens.relation.lang.XPathExpr;\r
import org.xerial.util.log.Logger;\r
\r
public class XPathExprTest {\r
phdthesis|mastersthesis|www)*>
<!ENTITY % field "author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter">
-<!ELEMENT article (%field;)*>
+<!ELEMENT article (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST article
key CDATA #REQUIRED
reviewid CDATA #IMPLIED
rating CDATA #IMPLIED
>
-<!ELEMENT inproceedings (%field;)*>
+<!ELEMENT inproceedings (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST inproceedings key CDATA #REQUIRED>
-<!ELEMENT proceedings (%field;)*>
+<!ELEMENT proceedings (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST proceedings key CDATA #REQUIRED>
-<!ELEMENT book (%field;)*>
+<!ELEMENT book (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST book key CDATA #REQUIRED>
-<!ELEMENT incollection (%field;)*>
+<!ELEMENT incollection (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST incollection key CDATA #REQUIRED>
-<!ELEMENT phdthesis (%field;)*>
+<!ELEMENT phdthesis (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST phdthesis key CDATA #REQUIRED>
-<!ELEMENT mastersthesis (%field;)*>
+<!ELEMENT mastersthesis (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST mastersthesis key CDATA #REQUIRED>
-<!ELEMENT www (%field;)*>
+<!ELEMENT www (author|editor|title|booktitle|pages|year|address|journal|volume|number|month|url|ee|cdrom|cite|publisher|note|crossref|isbn|series|school|chapter)*>
<!ATTLIST www key CDATA #REQUIRED>
<!ELEMENT author (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ENTITY % titlecontents "#PCDATA|sub|sup|i|tt|ref">
-<!ELEMENT title (%titlecontents;)*>
+<!ELEMENT title (#PCDATA|sub|sup|i|tt|ref)*>
<!ELEMENT booktitle (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT ref (#PCDATA)>
<!ATTLIST ref href CDATA #REQUIRED>
-<!ELEMENT sup (%titlecontents;)*>
-<!ELEMENT sub (%titlecontents;)*>
-<!ELEMENT i (%titlecontents;)*>
-<!ELEMENT tt (%titlecontents;)*>
+<!ELEMENT sup (#PCDATA|sub|sup|i|tt|ref)*>
+<!ELEMENT sub (#PCDATA|sub|sup|i|tt|ref)*>
+<!ELEMENT i (#PCDATA|sub|sup|i|tt|ref)*>
+<!ELEMENT tt (#PCDATA|sub|sup|i|tt|ref)*>
<!ENTITY reg "®">
<!ENTITY micro "µ">