Computes the probability of the tag OF being at the end of the table given
that the previous tag sequence in table is GIVEN. given is at the beginning,
of is at the end.

@return the probability of the tag OF being at the end of the table
517064
public double conditionalLogProbGivenPrevious(int[] given, int of) {
    if (given.length != windowSize - 1) {
      throw new IllegalArgumentException("conditionalLogProbGivenPrevious requires given one less than clique size (" +
              windowSize + ") but was " + Arrays.toString(given));
    }
    // Note: other similar methods could be optimized like this one, but this is the one the CRF uses....
    /*
    int startIndex = indicesFront(given);
    int numCellsToSum = SloppyMath.intPow(numClasses, windowSize - given.length);
    double z = ArrayMath.logSum(table, startIndex, startIndex + numCellsToSum);
    int i = indexOf(given, of);
    System.err.printf("startIndex is %d, numCellsToSum is %d, i is %d (of is %d)%n", startIndex, numCellsToSum, i, of);
    */
    int startIndex = indicesFront(given);
    double z = ArrayMath.logSum(table, startIndex, startIndex + numClasses);
    int i = startIndex + of;
    // System.err.printf("startIndex is %d, numCellsToSum is %d, i is %d (of is %d)%n", startIndex, numClasses, i, of);

    return table[i] - z;
  }
983627
public int getMaxTagSize()
	{
		int retval = -1;

		if ((maxTagSize >= 0) && (maxTagSize < MAX_TAG_SIZE_TABLE.length))
		{
			retval = MAX_TAG_SIZE_TABLE[maxTagSize];
		}

		return retval;
	}
1072147
public int numOfTableColumns() {
        Element rows = tableRows();
        if (rows == null) {
            return -1;
        }
        Element thCells = rows.findChild(app.newElement(Locator.TAGNAME, "th"));
        Element tdCells = rows.findChild(app.newElement(Locator.TAGNAME, "td"));
        return thCells.get().matchCount() + tdCells.get().matchCount();
    }
406613
public Rule Table() {
        Var<TableNode> node = new Var<TableNode>();
        return NodeSequence(
                push(node.setAndGet(new TableNode())),
                Optional(
                        NodeSequence(
                                TableRow(), push(1, new TableHeaderNode()) && addAsChild(),
                                ZeroOrMore(TableRow(), addAsChild())
                        ),
                        addAsChild() // add the TableHeaderNode to the TableNode
                ),
                TableDivider(node),
                Optional(
                        NodeSequence(
                                TableRow(), push(1, new TableBodyNode()) && addAsChild(),
                                ZeroOrMore(TableRow(), addAsChild())
                        ),
                        addAsChild() // add the TableHeaderNode to the TableNode
                ),
                // only accept as table if we have at least one header or at least one body
                Optional(TableCaption(), addAsChild()),
                !node.get().getChildren().isEmpty()

        );
    }
153487
public int last()
    {
        for (int ii=array.length-1;ii>=0;ii--)
        {
            if (array[ii] != 0)
            {
                for (int jj=Math.min(bits,(ii+1)*8)-1;jj>=0;jj--)
                {
                    if (isSet(jj))
                    {
                        return jj;
                    }
                }
            }
        }
        return -1;
    }
604916
@Override
	public boolean isEmptyElementTag() {
		if (type != START_TAG) {
			throw new KriptonRuntimeException(ILLEGAL_TYPE, true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
		}
		return degenerated;
	}
488048
public int getLast()
  {
    if (isEmpty()) {
      return -1;
    }

    int last = 0;
    for (int i = 0; i <= lastWordIndex; i++) {
      int w = words.get(i);
      if (ConciseSetUtils.isLiteral(w)) {
        last += ConciseSetUtils.MAX_LITERAL_LENGTH;
      } else {
        last += ConciseSetUtils.maxLiteralLengthMultiplication(ConciseSetUtils.getSequenceCount(w) + 1);
      }
    }

    int w = words.get(lastWordIndex);
    if (ConciseSetUtils.isLiteral(w)) {
      last -= Integer.numberOfLeadingZeros(ConciseSetUtils.getLiteralBits(w));
    } else {
      last--;
    }
    return last;
  }
569996
private String getNext() {
    StringBuilder result = new StringBuilder();
    try {
      XMLUtils.XMLTag tag;
      do {
        // String text =
        XMLUtils.readUntilTag(inputReader);
        // there may or may not be text before the next tag, but we discard it
        //        System.out.println("outside text: " + text );
        tag = XMLUtils.readAndParseTag(inputReader);
        //        System.out.println("outside tag: " + tag);
        if (tag == null) {
          return null; // couldn't find any more tags, so no more elements
        }
      } while (!tagNamePattern.matcher(tag.name).matches() ||
               tag.isEndTag || tag.isSingleTag);
      if (keepDelimitingTags) {
        result.append(tag.toString());
      }
      int depth = 1;
      while (true) {
        String text = XMLUtils.readUntilTag(inputReader);
        if (text != null) {
          // if the text isn't null, we append it
          //        System.out.println("inside text: " + text );
          result.append(text);
        }
        String tagString = XMLUtils.readTag(inputReader);
        tag = XMLUtils.parseTag(tagString);
        if (tag == null) {
          return null; // unexpected end of this element, so no more elements
        }
        if (tagNamePattern.matcher(tag.name).matches() && tag.isEndTag) {
          if ((countDepth && depth == 1) || !countDepth) {
            if (keepDelimitingTags) {
              result.append(tagString);
            }
            // this is our end tag so we stop
            break;
          } else {
            --depth;
            if (keepInternalTags) {
              result.append(tagString);
            }
          }
        } else if (tagNamePattern.matcher(tag.name).matches() && !tag.isEndTag &&
                   !tag.isSingleTag && countDepth) {
          ++depth;
          if (keepInternalTags) {
            result.append(tagString);
          }
        } else {
          // not our end tag, so we optionally append it and keep going
          if (keepInternalTags) {
            result.append(tagString);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return result.toString();
  }
909997
public int readTag() throws IOException
    {
        if (!buffer.hasRemaining())
        {
            lastTag = 0;
            return 0;
        }

        final int tag = readRawVarint32();
        if (tag >>> TAG_TYPE_BITS == 0)
        {
            // If we actually read zero, that's not a valid tag.
            throw ProtobufException.invalidTag();
        }
        lastTag = tag;
        return tag;
    }
693578
@Override
  public int endPosition() {
    if (assumeSinglePosition) {
      return super.endPosition();
    } else {
      int status = super.endPosition();
      if (status >= 0) {
        try {
          processEncodedPayload();
          return (status != NO_MORE_POSITIONS) ? (mtasPosition.getEnd() + 1)
              : NO_MORE_POSITIONS;
        } catch (IOException e) {
          log.debug(e);
          return NO_MORE_POSITIONS;
        }
      } else {
        return status;
      }
    }
  }
1059671
public int end() {
    Preconditions.checkState(match != null, "Have not called find()");
    if (match.getEndLocation() >= 0) {
      return tokens.get(match.getEndLocation() - 1).end();
    }
    return -1;
  }
116983
public static boolean hasSisterTagAfter(Tag tag, String nameToFind) {
	Body body = (Body) tag.getParent();
	List<Statement> stats = body.getStatements();
	Iterator<Statement> it = stats.iterator();
	Statement other;

	boolean isAfter = false;
	while (it.hasNext()) {
	    other = it.next();

	    if (other instanceof Tag) {
		if (isAfter) {
		    if (((Tag) other).getTagLibTag().getName().equals(nameToFind)) return true;
		}
		else if (other == tag) isAfter = true;
	    }
	}
	return false;
    }
347451
public int readTag() throws IOException
    {
        if (offset == limit)
        {
            lastTag = 0;
            return 0;
        }

        final int tag = readRawVarint32();
        if (tag >>> WireFormat.TAG_TYPE_BITS == 0)
        {
            // If we actually read zero, that's not a valid tag.
            throw ProtobufException.invalidTag();
        }
        lastTag = tag;
        return tag;
    }
635710
public int computeNextStatementStartKeywordCount() {
        int result = 0;

        if (isNextKeyWord()) {
            for (String[] nextStmtStart : registeredStatementStartPhrases) {
                if (this.matches(nextStmtStart)) {
                    return nextStmtStart.length;
                }
            }
        }

        return result;
    }
1059540
public int getSnippetEnd() {
    if (Cooccurrence_Type.featOkTst && ((Cooccurrence_Type)jcasType).casFeat_snippetEnd == null)
      jcasType.jcas.throwFeatMissing("snippetEnd", "ch.epfl.bbp.uima.types.Cooccurrence");
    return jcasType.ll_cas.ll_getIntValue(addr, ((Cooccurrence_Type)jcasType).casFeatCode_snippetEnd);}
428965
public int getNextCode() {
        // Attempt to get the next code. The exception is caught to make
        // this robust to cases wherein the EndOfInformation code has been
        // omitted from a strip. Examples of such cases have been observed
        // in practice.
        try {
            nextData = (nextData << 8) | (data[bytePointer++] & 0xff);
            nextBits += 8;
            
            if (nextBits < bitsToGet) {
                nextData = (nextData << 8) | (data[bytePointer++] & 0xff);
                nextBits += 8;
            }
            
            int code =
            (nextData >> (nextBits - bitsToGet)) & andTable[bitsToGet-9];
            nextBits -= bitsToGet;
            
            return code;
        } catch(ArrayIndexOutOfBoundsException e) {
            // Strip not terminated as expected: return EndOfInformation code.
            return 257;
        }
    }
94096
public long completeSegmentByteCount() {
    long result = size;
    if (result == 0) return 0;

    // Omit the tail if it's still writable.
    Segment tail = head.prev;
    if (tail.limit < Segment.SIZE && tail.owner) {
      result -= tail.limit - tail.pos;
    }

    return result;
  }