/** * Creates an automaton that corresponds to the set of all possible operations * on the given document under the given schema constraints. */ public NindoAutomaton(DocumentSchema schemaConstraints, IndexedDocument<N, E, T> doc) { this.schemaConstraints = schemaConstraints; this.doc = doc; this.resultingLength = doc.size(); }
private boolean canSkip(int distance) { assert distance >= 0; assert doc.size() <= MAX_DOC_LENGTH; return distance <= maxSkipDistance(); }
private DocSymbol effectiveDocSymbol() { if (effectivePos >= doc.size()) { return DocSymbol.END; } { E e = elementStartingHere(); if (e != null) { return DocSymbol.OPEN; } } { E e = elementEndingNext(); if (e != null) { return DocSymbol.CLOSE; } } return DocSymbol.CHARACTER; }
if (effectivePos == 0 || effectivePos >= doc.size()) { return null;
private static <N, E extends N, T extends N> int remainingCharactersInElement( IndexedDocument<N, E, T> doc, int pos) { if (pos >= doc.size()) { return 0; } Point<N> deletionPoint = doc.locate(pos); if (!deletionPoint.isInTextNode()) { return 0; } int offsetWithinNode = deletionPoint.getTextOffset(); N container = deletionPoint.getContainer(); assert doc.getNodeType(container) == NodeType.TEXT_NODE; int nodeLength = DocHelper.getItemSize(doc, container); int remainingChars = nodeLength - offsetWithinNode; assert remainingChars >= 0; while (true) { N next = doc.getNextSibling(container); if (next == null || doc.getNodeType(next) != NodeType.TEXT_NODE) { break; } remainingChars += DocHelper.getItemSize(doc, next); container = next; } return remainingChars; }
public void testNoRedundantSkips() throws OperationException { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("abcdefghijkl"); Nindo.Builder b; b = new Nindo.Builder(); b.skip(1); b.startAnnotation("a", "1"); b.skip(1); b.startAnnotation("b", "1"); b.skip(1); b.endAnnotation("a"); b.skip(1); b.startAnnotation("c", "1"); b.skip(1); b.endAnnotation("c"); b.skip(1); b.endAnnotation("b"); b.skip(1); b.startAnnotation("c", "1"); b.skip(1); b.endAnnotation("c"); checkApply(doc, b.build()); b = new Nindo.Builder(); b.startAnnotation("z", "1"); b.skip(doc.size()); b.endAnnotation("z"); DocOp docOp = doc.consumeAndReturnInvertible(b.build()); assertEquals(3, docOp.size()); }
public void testNoRedundantSkips() throws OperationException { IndexedDocument<Node, Element, Text> doc = DocProviders.POJO.parse("abcdefghijkl"); Nindo.Builder b; b = new Nindo.Builder(); b.skip(1); b.startAnnotation("a", "1"); b.skip(1); b.startAnnotation("b", "1"); b.skip(1); b.endAnnotation("a"); b.skip(1); b.startAnnotation("c", "1"); b.skip(1); b.endAnnotation("c"); b.skip(1); b.endAnnotation("b"); b.skip(1); b.startAnnotation("c", "1"); b.skip(1); b.endAnnotation("c"); checkApply(doc, b.build()); b = new Nindo.Builder(); b.startAnnotation("z", "1"); b.skip(doc.size()); b.endAnnotation("z"); DocOp docOp = doc.consumeAndReturnInvertible(b.build()); assertEquals(3, docOp.size()); }